Skip to content

Commit de0a954

Browse files
committed
Remove _utcfromtimestamp function
1 parent 0dbc58a commit de0a954

File tree

1 file changed

+3
-24
lines changed

1 file changed

+3
-24
lines changed

Lib/test/datetimetester.py

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import decimal
88
import io
99
import itertools
10-
import math
1110
import os
1211
import pickle
1312
import random
@@ -49,6 +48,8 @@
4948
for proto in range(pickle.HIGHEST_PROTOCOL + 1)]
5049
assert len(pickle_choices) == pickle.HIGHEST_PROTOCOL + 1
5150

51+
EPOCH_NAIVE = datetime(1970, 1, 1, 0, 0) # For calculating transitions
52+
5253
# An arbitrary collection of objects of non-datetime types, for testing
5354
# mixed-type comparisons.
5455
OTHERSTUFF = (10, 34.5, "abc", {}, [], ())
@@ -58,28 +59,6 @@
5859
NAN = float("nan")
5960

6061

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-
8362
#############################################################################
8463
# module tests
8564

@@ -6125,7 +6104,7 @@ def stats(cls, start_year=1):
61256104
def transitions(self):
61266105
for (_, prev_ti), (t, ti) in pairs(zip(self.ut, self.ti)):
61276106
shift = ti[0] - prev_ti[0]
6128-
yield _utcfromtimestamp(datetime, t), shift
6107+
yield (EPOCH_NAIVE + timedelta(seconds=t)), shift
61296108

61306109
def nondst_folds(self):
61316110
"""Find all folds with the same value of isdst on both sides of the transition."""

0 commit comments

Comments
 (0)