File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -266,7 +266,10 @@ def local_offset(cls):
266
266
267
267
:raises OverflowError:
268
268
"""
269
- return ClockTime (- int (mktime (gmtime (0 ))))
269
+ # Adding and subtracting two days to avoid passing a pre-epoch time to
270
+ # `mktime`, which can cause a `OverflowError` on some platforms (e.g.,
271
+ # Windows).
272
+ return ClockTime (- int (mktime (gmtime (172800 ))) + 172800 )
270
273
271
274
def local_time (self ):
272
275
""" Read and return the current local time from this clock, measured relative to the Unix Epoch.
Original file line number Diff line number Diff line change @@ -53,3 +53,19 @@ def test_local_offset(self):
53
53
clock = object .__new__ (Clock )
54
54
offset = clock .local_offset ()
55
55
self .assertIsInstance (offset , ClockTime )
56
+
57
+ def test_local_time (self ):
58
+ _ = Clock ()
59
+ for impl in Clock ._Clock__implementations :
60
+ self .assert_ (issubclass (impl , Clock ))
61
+ clock = object .__new__ (impl )
62
+ time = clock .local_time ()
63
+ self .assertIsInstance (time , ClockTime )
64
+
65
+ def test_utc_time (self ):
66
+ _ = Clock ()
67
+ for impl in Clock ._Clock__implementations :
68
+ self .assert_ (issubclass (impl , Clock ))
69
+ clock = object .__new__ (impl )
70
+ time = clock .utc_time ()
71
+ self .assertIsInstance (time , ClockTime )
You can’t perform that action at this time.
0 commit comments