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.

Author vstinner
Recipients belopolsky, p-ganssle, vstinner
Date 2019-04-08.12:54:17
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1554728057.82.0.282756231506.issue36558@roundup.psfhosted.org>
In-reply-to
Content
time.mktime() returns a floating point number:

>>> type(time.mktime(time.localtime()))
<class 'float'>

The documentation says:

"It returns a floating point number, for compatibility with :func:`.time`."

time.time() returns a float because it has sub-second resolution, but mktime() returns an integer number of seconds.

Would it make sense to change mktime() return type from float to int?

I would like to change mktime() return type to make the function more consistent: inputs are integers, it sounds wrong to me to return float. The result should be integer as well.

How much code would it break? I guess that the main impact are unit tests relying on repr(time.mktime(t)) exact value. But it's easy to fix the tests: use int(time.mktime(t)) or "%.0f" % time.mktime(t) to never get ".0", or use float(time.mktime(t))) to explicitly cast for a float (that which be a bad but quick fix).

Note: I wrote and implemented the PEP 564 to avoid any precision loss. mktime() will not start loosing precision before year 285,422,891 (which is quite far in the future ;-)).
History
Date User Action Args
2019-04-08 12:54:17vstinnersetrecipients: + vstinner, belopolsky, p-ganssle
2019-04-08 12:54:17vstinnersetmessageid: <1554728057.82.0.282756231506.issue36558@roundup.psfhosted.org>
2019-04-08 12:54:17vstinnerlinkissue36558 messages
2019-04-08 12:54:17vstinnercreate