-
-
Notifications
You must be signed in to change notification settings - Fork 29.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Factorize code to convert int/float to time_t, timeval or timespec #58388
Comments
There are various ways to convert a Python int/float to a C time_t, timeval or timespec structure. Attached patch factorize code by adding functions to convert a Python object to a C type (time_t, timeval or timespec). My patch changes how datetime rounds microsecond: round towards zero instead of rounding to nearest with ties going away from zero. I chose this rounding method because it is the method used by int(float) and int(time.time()) is a common in programs (more than round(time.time()). Rounding towards zero avoids also producing timestamps in the future. On overflow, an OverflowError is now raises instead of a ValueError. I prefer OverflowError over ValueError because it is an implementation detail. For example, time_t is 32 bits on Linux 32 bits, 64 bits on Linux 64 bits or on Windows (32 or 64 bits). PyTime_ObjectToXXX() functions are part of Python and so can be used by the posix, time, datetime and select modules. The patch removes _time.c, _time.h and timefunc.h because these files were only used for one function (_PyTime_DoubleToTime_t) which is no more used and it required to link a module to _time.c to get this function. -- If it is a problem to replace ValueError with OverflowError for backward compatibility, it is easy to adapt the patch to raise ValueError instead. timedelta*float and timedelta/float rounding method may also be changed. |
Alexander: No complain if I remove _time.c? |
New changeset 1e9cc1a03365 by Victor Stinner in branch 'default': |
New changeset ed73006bac42 by Victor Stinner in branch 'default': |
New changeset 1eaf6e899f02 by Victor Stinner in branch 'default': |
New changeset cb1c877a27f2 by Victor Stinner in branch 'default': |
New changeset 760cf150bb99 by Victor Stinner in branch 'default': |
New changeset 9d69a2418d80 by Victor Stinner in branch 'default': |
New changeset 5d6a5c5a4ebe by Victor Stinner in branch 'default': New changeset 706689b2d678 by Victor Stinner in branch 'default': New changeset a0d101220f96 by Victor Stinner in branch 'default': |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: