[Zope-dev] [Bug+Patch] Microseconds in DateTime
Nicola Larosa
nico@tekNico.net
Tue, 23 Oct 2001 15:34:13 +0200
[Sent to main list, ignored. Retrying here...]
The __str__ function in DateTime.DateTime cuts off two precision digits
from the time returned by time.time(), falling off to tenths of
milliseconds instead of keeping the microseconds.
If it feels unrighteous to put the hard work of gettimeofday() to waste,
apply the patch below to lib/python/DateTime/DateTime.py, and get back
that microsecond precision.
Yes, on some hardware/software platforms those microseconds are
significant, and yes, they can be useful in many situations.
Here is the patch.
--- DateTime.py Thu Jul 05 17:55:29 2001
+++ DateTime.py.NEW Mon Oct 22 16:00:36 2001
@@ -1558,11 +1558,11 @@
y,m,d =self._year,self._month,self._day
h,mn,s,t=self._hour,self._minute,self._second,self._tz
if(h+mn+s):
- if (s-int(s))> 0.0001:
+ if (s-int(s)) >= 0.000001:
try:
# For the seconds, print two digits
# before the decimal point.
- subsec = split('%g' % s, '.')[1]
+ subsec = split('%f' % s, '.')[1]
return '%4.4d/%2.2d/%2.2d %2.2d:%2.2d:%2.2d.%s %s' % (
y,m,d,h,mn,s,subsec,t)
except:
--
Nicola Larosa - nico@tekNico.net