Skip to content
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

Closed
vstinner opened this issue Mar 3, 2012 · 9 comments
Closed

Factorize code to convert int/float to time_t, timeval or timespec #58388

vstinner opened this issue Mar 3, 2012 · 9 comments
Labels
stdlib Python modules in the Lib dir

Comments

@vstinner
Copy link
Member

vstinner commented Mar 3, 2012

BPO 14180
Nosy @birkenfeld, @gpshead, @abalkin, @vstinner
Files
  • pytime.patch
  • 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:

    assignee = None
    closed_at = <Date 2012-03-13.12:38:43.420>
    created_at = <Date 2012-03-03.00:10:21.634>
    labels = ['library']
    title = 'Factorize code to convert int/float to time_t, timeval or timespec'
    updated_at = <Date 2012-03-13.23:20:38.655>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2012-03-13.23:20:38.655>
    actor = 'python-dev'
    assignee = 'none'
    closed = True
    closed_date = <Date 2012-03-13.12:38:43.420>
    closer = 'python-dev'
    components = ['Library (Lib)']
    creation = <Date 2012-03-03.00:10:21.634>
    creator = 'vstinner'
    dependencies = []
    files = ['24716']
    hgrepos = []
    issue_num = 14180
    keywords = ['patch']
    message_count = 9.0
    messages = ['154811', '154984', '155600', '155601', '155616', '155625', '155631', '155639', '155689']
    nosy_count = 5.0
    nosy_names = ['georg.brandl', 'gregory.p.smith', 'belopolsky', 'vstinner', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue14180'
    versions = ['Python 3.3']

    @vstinner
    Copy link
    Member Author

    vstinner commented Mar 3, 2012

    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.

    @vstinner vstinner added the stdlib Python modules in the Lib dir label Mar 3, 2012
    @vstinner
    Copy link
    Member Author

    vstinner commented Mar 5, 2012

    Alexander: No complain if I remove _time.c?

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Mar 13, 2012

    New changeset 1e9cc1a03365 by Victor Stinner in branch 'default':
    Close bpo-14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
    http://hg.python.org/cpython/rev/1e9cc1a03365

    @python-dev python-dev mannequin closed this as completed Mar 13, 2012
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Mar 13, 2012

    New changeset ed73006bac42 by Victor Stinner in branch 'default':
    Issue bpo-14180: Remove commented code
    http://hg.python.org/cpython/rev/ed73006bac42

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Mar 13, 2012

    New changeset 1eaf6e899f02 by Victor Stinner in branch 'default':
    Issue bpo-14180: Fix select.select() compilation on BSD and a typo in kqueue_queue_control()
    http://hg.python.org/cpython/rev/1eaf6e899f02

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Mar 13, 2012

    New changeset cb1c877a27f2 by Victor Stinner in branch 'default':
    Issue bpo-14180: Fix another typo in kqueue_queue_control()
    http://hg.python.org/cpython/rev/cb1c877a27f2

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Mar 13, 2012

    New changeset 760cf150bb99 by Victor Stinner in branch 'default':
    Issue bpo-14180: Fix pythoncore.vcproj, Modules/_time.[ch] have been removed
    http://hg.python.org/cpython/rev/760cf150bb99

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Mar 13, 2012

    New changeset 9d69a2418d80 by Victor Stinner in branch 'default':
    Issue bpo-14180: Fix an invalid rounding when compiler optimization are enabled
    http://hg.python.org/cpython/rev/9d69a2418d80

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Mar 13, 2012

    New changeset 5d6a5c5a4ebe by Victor Stinner in branch 'default':
    Issue bpo-14180: datetime.date.fromtimestamp(), datetime.datetime.fromtimestamp()
    http://hg.python.org/cpython/rev/5d6a5c5a4ebe

    New changeset 706689b2d678 by Victor Stinner in branch 'default':
    Issue bpo-14180: TestDateTime.test_microsecond_rounding() handles localtime() and
    http://hg.python.org/cpython/rev/706689b2d678

    New changeset a0d101220f96 by Victor Stinner in branch 'default':
    Issue bpo-14180: Fix the select module to handle correctly the Windows timeval
    http://hg.python.org/cpython/rev/a0d101220f96

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant