# HG changeset patch # User Mads Kiilerich # Date 2023-06-29 18:02:27 # Node ID 0b05b4d85889c253697356ff76b0da45efde508d # Parent b5efb7a7d2a5aea84be13c29b5a1fc070f32a8fd utils: test coverage of makedate Explore the scenario from ae04af1ce78d to avoid future regressions. This was intended to give some coverage of the change in faccec1edc2c. diff --git a/mercurial/utils/dateutil.py b/mercurial/utils/dateutil.py --- a/mercurial/utils/dateutil.py +++ b/mercurial/utils/dateutil.py @@ -83,7 +83,37 @@ extendeddateformats = defaultdateformats def makedate(timestamp: Optional[float] = None) -> hgdate: """Return a unix timestamp (or the current time) as a (unixtime, - offset) tuple based off the local timezone.""" + offset) tuple based off the local timezone. + + >>> import os, time + >>> os.environ['TZ'] = 'Asia/Novokuznetsk' + >>> time.tzset() + + >>> def dtu(*a): + ... return datetime.datetime(*a, tzinfo=datetime.timezone.utc) + + # Old winter timezone, +7 + >>> makedate(dtu(2010, 1, 1, 5, 0, 0).timestamp()) + (1262322000.0, -25200) + + # Same timezone in summer, +7, so no DST + >>> makedate(dtu(2010, 7, 1, 5, 0, 0).timestamp()) + (1277960400.0, -25200) + + # Changing to new winter timezone, from +7 to +6 (ae04af1ce78d testcase) + >>> makedate(dtu(2010, 10, 30, 20, 0, 0).timestamp() - 1) + (1288468799.0, -25200) + >>> makedate(dtu(2010, 10, 30, 20, 0, 0).timestamp()) + (1288468800.0, -21600) + >>> makedate(dtu(2011, 1, 1, 5, 0, 0).timestamp()) + (1293858000.0, -21600) + + # Introducing DST, changing +6 to +7 + >>> makedate(dtu(2011, 3, 26, 20, 0, 0).timestamp() - 1) + (1301169599.0, -21600) + >>> makedate(dtu(2011, 3, 26, 20, 0, 0).timestamp()) + (1301169600.0, -25200) + """ if timestamp is None: timestamp = time.time() if timestamp < 0: