Skip to content

Commit 1b500e6

Browse files
committed
don't divide
1 parent 37e77d8 commit 1b500e6

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

Lib/datetime.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,9 +1761,8 @@ def _fromtimestamp(cls, t, utc, tz):
17611761
A timezone info object may be passed in as well.
17621762
"""
17631763

1764-
t, dp = str(t).split('.')
1765-
us, sus = dp[:6], f'{dp[6:9]:0<3}'
1766-
t, us, sus = int(t), int(us), int(sus)
1764+
t = str(t)
1765+
t, us, sus = map(int, [t[:-9], t[-9:-3], t[-3:]])
17671766
converter = _time.gmtime if utc else _time.localtime
17681767
y, m, d, hh, mm, ss, weekday, jday, dst = converter(t)
17691768
ss = min(ss, 59) # clamp out leap seconds if the platform has them
@@ -1811,13 +1810,13 @@ def utcfromtimestamp(cls, t):
18111810
@classmethod
18121811
def now(cls, tz=None):
18131812
"Construct a datetime from time.time() and optional time zone info."
1814-
t = _time.time_ns() / 1e9
1813+
t = _time.time_ns()
18151814
return cls.fromtimestamp(t, tz)
18161815

18171816
@classmethod
18181817
def utcnow(cls):
18191818
"Construct a UTC datetime from time.time()."
1820-
t = _time.time_ns() / 1e9
1819+
t = _time.time_ns()
18211820
return cls.utcfromtimestamp(t)
18221821

18231822
@classmethod

0 commit comments

Comments
 (0)