comparison hgext/convert/common.py @ 51684:20e2a20674dc

convert: drop a duplicate implementation of `dateutil.makedate()` I noticed this because the signature generated by pytype recently changed to be less specific. When the method was introduced back in 337d728e644f, `util.makedate()` didn't take an optional timestamp arg. But now it does, and the methods are the same (except the `dateutil` version validates that the timestamp isn't a negative value). I left the old method in place in case anyone has custom convert code that monkey patches it.
author Matt Harbison <matt_harbison@yahoo.com>
date Thu, 11 Jul 2024 14:46:00 -0400
parents faccec1edc2c
children 0eb515c7bec8
comparison
equal deleted inserted replaced
51683:5f37c36f36b9 51684:20e2a20674dc
4 # 4 #
5 # This software may be used and distributed according to the terms of the 5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version. 6 # GNU General Public License version 2 or any later version.
7 7
8 import base64 8 import base64
9 import datetime
10 import os 9 import os
11 import pickle 10 import pickle
12 import re 11 import re
13 import shlex 12 import shlex
14 import subprocess 13 import subprocess
20 error, 19 error,
21 phases, 20 phases,
22 pycompat, 21 pycompat,
23 util, 22 util,
24 ) 23 )
25 from mercurial.utils import procutil 24 from mercurial.utils import (
25 dateutil,
26 procutil,
27 )
26 28
27 propertycache = util.propertycache 29 propertycache = util.propertycache
28 30
29 31
30 def _encodeornone(d): 32 def _encodeornone(d):
563 if self.fp: 565 if self.fp:
564 self.fp.close() 566 self.fp.close()
565 self.fp = None 567 self.fp = None
566 568
567 569
568 def makedatetimestamp(t): 570 def makedatetimestamp(t: float) -> dateutil.hgdate:
569 """Like dateutil.makedate() but for time t instead of current time""" 571 return dateutil.makedate(t)
570 tz = round(
571 t
572 - datetime.datetime.fromtimestamp(t)
573 .replace(tzinfo=datetime.timezone.utc)
574 .timestamp()
575 )
576 return t, tz