Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/utils/dateutil.py @ 51801:55677d115045
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.
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Thu, 29 Jun 2023 20:02:27 +0200 |
parents | f15cb5111a1e |
children | f4733654f144 |
comparison
equal
deleted
inserted
replaced
51800:b619ba39d10a | 51801:55677d115045 |
---|---|
81 ) | 81 ) |
82 | 82 |
83 | 83 |
84 def makedate(timestamp: Optional[float] = None) -> hgdate: | 84 def makedate(timestamp: Optional[float] = None) -> hgdate: |
85 """Return a unix timestamp (or the current time) as a (unixtime, | 85 """Return a unix timestamp (or the current time) as a (unixtime, |
86 offset) tuple based off the local timezone.""" | 86 offset) tuple based off the local timezone. |
87 | |
88 >>> import os, time | |
89 >>> os.environ['TZ'] = 'Asia/Novokuznetsk' | |
90 >>> time.tzset() | |
91 | |
92 >>> def dtu(*a): | |
93 ... return datetime.datetime(*a, tzinfo=datetime.timezone.utc) | |
94 | |
95 # Old winter timezone, +7 | |
96 >>> makedate(dtu(2010, 1, 1, 5, 0, 0).timestamp()) | |
97 (1262322000.0, -25200) | |
98 | |
99 # Same timezone in summer, +7, so no DST | |
100 >>> makedate(dtu(2010, 7, 1, 5, 0, 0).timestamp()) | |
101 (1277960400.0, -25200) | |
102 | |
103 # Changing to new winter timezone, from +7 to +6 (ae04af1ce78d testcase) | |
104 >>> makedate(dtu(2010, 10, 30, 20, 0, 0).timestamp() - 1) | |
105 (1288468799.0, -25200) | |
106 >>> makedate(dtu(2010, 10, 30, 20, 0, 0).timestamp()) | |
107 (1288468800.0, -21600) | |
108 >>> makedate(dtu(2011, 1, 1, 5, 0, 0).timestamp()) | |
109 (1293858000.0, -21600) | |
110 | |
111 # Introducing DST, changing +6 to +7 | |
112 >>> makedate(dtu(2011, 3, 26, 20, 0, 0).timestamp() - 1) | |
113 (1301169599.0, -21600) | |
114 >>> makedate(dtu(2011, 3, 26, 20, 0, 0).timestamp()) | |
115 (1301169600.0, -25200) | |
116 """ | |
87 if timestamp is None: | 117 if timestamp is None: |
88 timestamp = time.time() | 118 timestamp = time.time() |
89 if timestamp < 0: | 119 if timestamp < 0: |
90 hint = _(b"check your clock") | 120 hint = _(b"check your clock") |
91 raise error.InputError( | 121 raise error.InputError( |