[Python-bugs-list] [ python-Bugs-661086 ] datetime.today() truncates microseconds

noreply@sourceforge.net noreply@sourceforge.net
Thu, 02 Jan 2003 06:23:25 -0800


Bugs item #661086, was opened at 2003-01-02 15:23
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=661086&group_id=5470

Category: Python Library
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Amaury Forgeot d'Arc (amauryf)
Assigned to: Nobody/Anonymous (nobody)
Summary: datetime.today() truncates microseconds

Initial Comment:
While exploring the new datetime module, I got results 
like:
>>> datetime.datetime.today()
datetime.datetime(2003, 1, 2, 15, 14, 51, 480999)

Shouldn't the microseconds be 637000 ?
While not very important, this can lead you to believe 
that the timestamp is accurate to 1e-6 seconds, 
whereas only milliseconds are relevant (on W2K).

since today() is equivalent to fromtimestamp(time.time()),
I explored the results of time.time():

>>> time.time(),datetime.datetime.today()
returns:
(1041516891.4809999, 
datetime.datetime(2003, 1, 2, 15, 14, 51, 480999))

It seems that the float returned by time.time is truncated 
to 1e-6. I suggest that it should be rounded instead, so 
that the last digit (which is significant) is taken into 
account.

Looking into the code, I think that the code to change is 
in datetimemodule.c: the function 
datetime_from_timestamp could add 5e-7 to the "us" 
variable before casting it to int.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=661086&group_id=5470