[Python-checkins] python/nondist/sandbox/datetime datetime.py,1.143,1.144
tim_one@users.sourceforge.net
tim_one@users.sourceforge.net
Sat, 04 Jan 2003 10:25:26 -0800
Update of /cvsroot/python/python/nondist/sandbox/datetime
In directory sc8-pr-cvs1:/tmp/cvs-serv16038
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.
Index: datetime.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/datetime.py,v
retrieving revision 1.143
retrieving revision 1.144
diff -C2 -d -r1.143 -r1.144
*** datetime.py 4 Jan 2003 14:02:55 -0000 1.143
--- datetime.py 4 Jan 2003 18:25:23 -0000 1.144
***************
*** 1285,1288 ****
--- 1285,1289 ----
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)
***************
*** 1303,1306 ****
--- 1304,1308 ----
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)
***************
*** 1552,1555 ****
--- 1554,1558 ----
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)