This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Floating point second in date/time tuple
Type: enhancement Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: brett.cannon, rhettinger, timcera
Priority: low Keywords:

Created on 2001-04-05 17:33 by timcera, last changed 2022-04-10 16:03 by admin. This issue is now closed.

Messages (3)
msg53123 - (view) Author: Tim Cera (timcera) Date: 2001-04-05 17:33
Would like to have this:

>>> time.localtime(1057035600.6)
(2003, 7, 1, 1, 0.6, 0, 1, 182, 1)

Instead of:

>>> time.localtime(1057035600.6)
(2003, 7, 1, 1, 0, 0, 1, 182, 1)


At a minimum the fractional seconds should be rounded
instead of truncated.

thanks
tim cera
msg53124 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2003-05-12 22:55
Logged In: YES 
user_id=357491

The problem is that the C library's localtime is used to do the conversion and 
that takes in a time_t argument.  On almost all platforms this is a long int.  
Forcing the number to an integer prevent any unexpected warning about 
casting if the platform does support floats for some odd reason.

The reason the argument is truncated is because the argument to 
PyArg_ParseTuple is 'd', which is integer.  Python basically does what C 
would do which is truncate.  You could round it up by taking the number as 
a Python object, 
calling Python's round function, and then extract the integer after the 
rounding.  Trouble is that now your value accounts for time that you didn't 
even have.  The plus side to truncating is your are not adding on time that 
did not occur; you are just losing some extra time you had.  =).

If you want to create a patch to rectify the situation you might get people to 
support the idea, but I don't view this as critical, especially when you can call 
round yourself before passing the value to localtime.
msg53125 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2003-08-09 08:06
Logged In: YES 
user_id=80475

Agree with Brett. 
Closing this one.
History
Date User Action Args
2022-04-10 16:03:55adminsetgithub: 34286
2001-04-05 17:33:17timceracreate