[Zope] nasty datetime bug: _nearsec() sometimes says '60' (!)

Anthony Baxter anthony@ekorp.com
Wed, 26 May 1999 20:35:31 +1000


Inside the DateTime object, it uses the attr '_nearsec()' for
printing times which are rounded to the nearest second. 

This is:
        self._nearsec=round(sc)

This is all well and good, except when it's 59.7 seconds past the
minute, in which case you get times like '07:34:60'. Then SQL Server
and Oracle both get sad at me, and foul things up.

My quick fix:

--- /opt/zope/inst/lib/python/DateTime/DateTime.py      Mon Feb 22 22:10:48 1999
+++ DateTime/DateTime.py        Wed May 26 10:33:49 1999
@@ -91,6 +91,7 @@
 from string import strip,split,upper,lower,atoi,atof,find,join
 from time import time,gmtime,localtime,asctime,tzname,strftime,mktime
 from types import InstanceType,IntType,FloatType,StringType
+import math
 
 
 
@@ -580,7 +581,7 @@
             self._months[mo],self._months_a[mo],self._months_p[mo]
         self._fday,self._aday,self._pday= \
             self._days[dx],self._days_a[dx],self._days_p[dx]
-        self._nearsec=round(sc)
+        self._nearsec=math.floor(sc)
         self._year,self._month,self._day     =yr,mo,dy
         self._hour,self._minute,self._second =hr,mn,sc
         self.time,self._d,self._t,self._tz   =s,d,t,tz


(so always truncate the seconds)

(yes, it's posted to Collector, but in case anyone else hits this...)

Anthony