Show More
@@ -83,7 +83,37 extendeddateformats = defaultdateformats | |||||
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: |
General Comments 0
You need to be logged in to leave comments.
Login now