[Zope3-checkins] CVS: Zope3/src/datetime - _datetime.py:1.20
Tim Peters
tim.one@comcast.net
Sat, 4 Jan 2003 13:27:23 -0500
Update of /cvs-repository/Zope3/src/datetime
In directory cvs.zope.org:/tmp/cvs-serv5593/src/datetime
Modified Files:
_datetime.py
Log Message:
Clamp out leap seconds on non-POSIX platforms. datetimes can't
represent them, and fromtimestamp() could raise a baffling ValueError
if the platform localtime()/gmtime() returned one. Note that this means
it's possible, on a non-POSIX platform, to have timestamps that differ by
a second, yet map to identical datetime objects.
=== Zope3/src/datetime/_datetime.py 1.19 => 1.20 ===
--- Zope3/src/datetime/_datetime.py:1.19 Fri Jan 3 23:52:47 2003
+++ Zope3/src/datetime/_datetime.py Sat Jan 4 13:27:21 2003
@@ -1275,6 +1275,7 @@
"Construct a datetime from a POSIX timestamp (like time.time())."
y, m, d, hh, mm, ss, weekday, jday, dst = _time.localtime(t)
us = int(round((t % 1.0) * 1000000))
+ ss = min(ss, 59) # clamp out leap seconds if the platform has them
return cls(y, m, d, hh, mm, ss, us)
fromtimestamp = classmethod(fromtimestamp)
@@ -1293,6 +1294,7 @@
"Construct a UTC datetime from a POSIX timestamp (like time.time())."
y, m, d, hh, mm, ss, weekday, jday, dst = _time.gmtime(t)
us = int((t % 1.0) * 1000000)
+ ss = min(ss, 59) # clamp out leap seconds if the platform has them
return cls(y, m, d, hh, mm, ss, us)
utcfromtimestamp = classmethod(utcfromtimestamp)
@@ -1542,6 +1544,7 @@
"""
y, m, d, hh, mm, ss, weekday, jday, dst = _time.localtime(t)
us = int((t % 1.0) * 1000000)
+ ss = min(ss, 59) # clamp out leap seconds if the platform has them
return cls(y, m, d, hh, mm, ss, us, tzinfo)
fromtimestamp = classmethod(fromtimestamp)