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

mktime adding an hour in April (naive struct)? #54311

Closed
barnburnr mannequin opened this issue Oct 14, 2010 · 3 comments
Closed

mktime adding an hour in April (naive struct)? #54311

barnburnr mannequin opened this issue Oct 14, 2010 · 3 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@barnburnr
Copy link
Mannequin

barnburnr mannequin commented Oct 14, 2010

BPO 10102
Nosy @abalkin
Files
  • mktimeissue.py: Test script
  • 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 2010-10-14.15:37:31.380>
    created_at = <Date 2010-10-14.14:08:02.865>
    labels = ['type-bug', 'invalid']
    title = 'mktime adding an hour in April (naive struct)?'
    updated_at = <Date 2010-10-14.16:54:05.536>
    user = 'https://bugs.python.org/barnburnr'

    bugs.python.org fields:

    activity = <Date 2010-10-14.16:54:05.536>
    actor = 'barnburnr'
    assignee = 'none'
    closed = True
    closed_date = <Date 2010-10-14.15:37:31.380>
    closer = 'belopolsky'
    components = []
    creation = <Date 2010-10-14.14:08:02.865>
    creator = 'barnburnr'
    dependencies = []
    files = ['19232']
    hgrepos = []
    issue_num = 10102
    keywords = []
    message_count = 3.0
    messages = ['118662', '118673', '118690']
    nosy_count = 2.0
    nosy_names = ['belopolsky', 'barnburnr']
    pr_nums = []
    priority = 'normal'
    resolution = 'not a bug'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue10102'
    versions = []

    @barnburnr
    Copy link
    Mannequin Author

    barnburnr mannequin commented Oct 14, 2010

    Just starting to dabble in the world of time and datetime objects. I was converting an array of datetime objects to an array of floats via mktime to do some data analysis. I have ran into an issue where mktime seems to be adding an hour on April 6, 2003. Attached is an example script which I used to create the below output:

    Python version: (2, 6, 5, 'final', 0)
    Epoch: time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=3, tm_yday=1, tm_isdst=0)
    First datetime: 2003-04-06 02:58:17
    Second datetime: 2003-04-06 03:13:17
    Is first datetime prior to second?: True
    First datetime, time struct: time.struct_time(tm_year=2003, tm_mon=4, tm_mday=6, tm_hour=2, tm_min=58, tm_sec=17, tm_wday=6, tm_yday=96, tm_isdst=-1)
    Second datetime, time struct: time.struct_time(tm_year=2003, tm_mon=4, tm_mday=6, tm_hour=3, tm_min=13, tm_sec=17, tm_wday=6, tm_yday=96, tm_isdst=-1)
    Is first time struct prior to second?: True
    First timestamp generated by mktime: 1049623097.0
    Second timestamp generated by mktime: 1049620397.0
    Is first timestamp less than second timestamp?: False
    First recovered datetime: 2003-04-06 03:58:17
    Second recovered datetime: 2003-04-06 03:13:17
    Is first recovered prior to second recovered?: False
    Is first recovered datetime same as original?: False
    Is second recovered datetime same as original?: True

    @barnburnr barnburnr mannequin added the type-bug An unexpected behavior, bug, or error label Oct 14, 2010
    @abalkin
    Copy link
    Member

    abalkin commented Oct 14, 2010

    It looks like you have just discovered the joys of daylight saving time. The problem with your example is that datetime(2003,4,6,2,58,17) is not a valid time in your timezone (most likely you are in the US). In the US, prior to 2007, the clocks moved 1 hour ahead at 2AM on the first Sunday in April. An thus 1:59 AM was followed by 3:00 AM and 2:58:17 never occurred.

    See the following link for detailed discussion of these issues:

    http://docs.python.org/dev/py3k/library/datetime.html#tzinfo-objects

    @barnburnr
    Copy link
    Mannequin Author

    barnburnr mannequin commented Oct 14, 2010

    Wow. Should have caught that. Thanks for the response.

    Kevin

    @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
    type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant