|
7 | 7 | import decimal
|
8 | 8 | import io
|
9 | 9 | import itertools
|
10 |
| -import math |
11 | 10 | import os
|
12 | 11 | import pickle
|
13 | 12 | import random
|
|
49 | 48 | for proto in range(pickle.HIGHEST_PROTOCOL + 1)]
|
50 | 49 | assert len(pickle_choices) == pickle.HIGHEST_PROTOCOL + 1
|
51 | 50 |
|
| 51 | +EPOCH_NAIVE = datetime(1970, 1, 1, 0, 0) # For calculating transitions |
| 52 | + |
52 | 53 | # An arbitrary collection of objects of non-datetime types, for testing
|
53 | 54 | # mixed-type comparisons.
|
54 | 55 | OTHERSTUFF = (10, 34.5, "abc", {}, [], ())
|
|
58 | 59 | NAN = float("nan")
|
59 | 60 |
|
60 | 61 |
|
61 |
| -def _utcfromtimestamp(klass, ts): |
62 |
| - """Simple re-implementation of datetime.utcfromtimestamp. |
63 |
| -
|
64 |
| - utcfromtimestamp is deprecated because it returns a naïve datetime object |
65 |
| - despite being aware that it is UTC. This sort of deliberately wrong object |
66 |
| - happens to be useful when calculating transition times from a TZif file, |
67 |
| - so this is a re-implementation of that. |
68 |
| - """ |
69 |
| - frac, ts = math.modf(ts) |
70 |
| - |
71 |
| - us = round(frac * 1e6) |
72 |
| - if us >= 1000000: |
73 |
| - ts += 1 |
74 |
| - us -= 1000000 |
75 |
| - elif us < 0: |
76 |
| - ts -= 1 |
77 |
| - us += 1000000 |
78 |
| - |
79 |
| - y, m, d, hh, mm, ss, *_ = _time.gmtime(ts) |
80 |
| - |
81 |
| - return klass(y, m, d, hh, mm, ss, us) |
82 |
| - |
83 | 62 | #############################################################################
|
84 | 63 | # module tests
|
85 | 64 |
|
@@ -6125,7 +6104,7 @@ def stats(cls, start_year=1):
|
6125 | 6104 | def transitions(self):
|
6126 | 6105 | for (_, prev_ti), (t, ti) in pairs(zip(self.ut, self.ti)):
|
6127 | 6106 | shift = ti[0] - prev_ti[0]
|
6128 |
| - yield _utcfromtimestamp(datetime, t), shift |
| 6107 | + yield (EPOCH_NAIVE + timedelta(seconds=t)), shift |
6129 | 6108 |
|
6130 | 6109 | def nondst_folds(self):
|
6131 | 6110 | """Find all folds with the same value of isdst on both sides of the transition."""
|
|
0 commit comments