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

plistlib should create non-naïve datetime objects #53502

Closed
wiml mannequin opened this issue Jul 14, 2010 · 6 comments
Closed

plistlib should create non-naïve datetime objects #53502

wiml mannequin opened this issue Jul 14, 2010 · 6 comments
Assignees
Labels
OS-mac stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error type-feature A feature request or enhancement

Comments

@wiml
Copy link
Mannequin

wiml mannequin commented Jul 14, 2010

BPO 9256
Nosy @ronaldoussoren, @abalkin, @ned-deily, @bitdancer, @hynek
Files
  • plistdt.py: a simple test case
  • 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 = 'https://github.com/ronaldoussoren'
    closed_at = None
    created_at = <Date 2010-07-14.01:34:02.327>
    labels = ['OS-mac', 'type-bug', 'library']
    title = 'plistlib should create non-na\xc3\xafve datetime objects'
    updated_at = <Date 2014-06-30.00:02:22.179>
    user = 'https://bugs.python.org/wiml'

    bugs.python.org fields:

    activity = <Date 2014-06-30.00:02:22.179>
    actor = 'belopolsky'
    assignee = 'ronaldoussoren'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)', 'macOS']
    creation = <Date 2010-07-14.01:34:02.327>
    creator = 'wiml'
    dependencies = []
    files = ['17993']
    hgrepos = []
    issue_num = 9256
    keywords = []
    message_count = 3.0
    messages = ['110249', '110250', '162471']
    nosy_count = 6.0
    nosy_names = ['ronaldoussoren', 'belopolsky', 'ned.deily', 'r.david.murray', 'wiml', 'hynek']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = 'needs patch'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue9256'
    versions = ['Python 3.5']

    Linked PRs

    @wiml
    Copy link
    Mannequin Author

    wiml mannequin commented Jul 14, 2010

    The plistlib module parses <date> elements in the plist into datetime objects. (This is good.) However, it produces naïve datetimes, even though the <date> elements include an explicit timezone specification ('Z' for UTC, since they're in ISO 8601 format).

    Now that bpo-5094 has been fixed, this should be a pretty trivial thing to fix— just pass tzinfo=UTC when creating the datetime (since the regex it uses won't even accept a date that doesn't have the 'Z' suffix, this will be correct).

    As an aside: RFC 3339 section 4.3 suggests a convention for distinguishing between "timestamps in UTC" and "timestamps which happen to be defined in terms of UTC, but don't really live in any particular timezone". The python datetime module is not currently able to make this distinction AFAIK, but even though the plist date strings don't follow the RFC 3339 convention, they are most accurately described as having an unknown local offset (like POSIX timestamps, they are UTC-referenced but cannot carry local-timezone info).

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

    abalkin commented Jul 14, 2010

    Yes, parsing <date> elements ending with 'Z' into aware datetime objects makes perfect sense, but this should be done carefully because doing so will break any code that mixes the result with naive datetimes.

    There is a lengthy RFC 3339 discussion in bpo-7584.

    @abalkin abalkin added the stdlib Python modules in the Lib dir label Jul 14, 2010
    @abalkin abalkin self-assigned this Jul 14, 2010
    @bitdancer
    Copy link
    Member

    An alternative is to do what the email package in 3.3 does, and treat naive datetimes as exactly "UTC referenced but with no information as to what local timezone they originated in". Either way, a program using the plistlib is going to have to know about this and handle the distinction itself, since as you say datetime doesn't have a way to make this differentiation (other than naive vs aware). So it needs to be documented clearly if it isn't already.

    @abalkin abalkin removed their assignment Jun 30, 2014
    @abalkin abalkin added the OS-mac label Jun 30, 2014
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @ronaldoussoren ronaldoussoren added the type-feature A feature request or enhancement label May 21, 2022
    @ronaldoussoren
    Copy link
    Contributor

    I've added a feature label because changing this is a feature change and likely can only be done by adding a new option to plist parsers.

    @ronaldoussoren
    Copy link
    Contributor

    O my, the PR causes builtbot failures (looks like 32 bit time_t)

    @ronaldoussoren ronaldoussoren reopened this Jan 1, 2024
    ronaldoussoren added a commit to ronaldoussoren/cpython that referenced this issue Jan 1, 2024
    1. Use 32-bit compatible date in test_dump_naive_datetime_with_aware_datetime_option
    
    2. test_dump_naive_datetime_with_aware_datetime_option: Writing non-aware datetimes
       with aware_datetime==True leads to the time being off by twice
       the timezone offset from UTC
    ronaldoussoren added a commit that referenced this issue Jan 1, 2024
    * gh-53502: Fixes for tests in gh-113363
    
    * Use 32-bit compatible date in test_dump_naive_datetime_with_aware_datetime_option
    
    * Saving non-aware datetimes will use the old behaviour regardless of the aware_datimetime setting
    serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Jan 2, 2024
    @hugovk
    Copy link
    Member

    hugovk commented Jan 11, 2024

    Triage: can this be re-closed following the recent fix PRs?

    kulikjak pushed a commit to kulikjak/cpython that referenced this issue Jan 22, 2024
    …or dumps aware datetime. (python#113363)
    
    * add options to loads and dumps aware datetime in plistlib
    kulikjak pushed a commit to kulikjak/cpython that referenced this issue Jan 22, 2024
    * pythongh-53502: Fixes for tests in pythongh-113363
    
    * Use 32-bit compatible date in test_dump_naive_datetime_with_aware_datetime_option
    
    * Saving non-aware datetimes will use the old behaviour regardless of the aware_datimetime setting
    kulikjak pushed a commit to kulikjak/cpython that referenced this issue Jan 22, 2024
    aisk added a commit to aisk/cpython that referenced this issue Feb 11, 2024
    …or dumps aware datetime. (python#113363)
    
    * add options to loads and dumps aware datetime in plistlib
    aisk pushed a commit to aisk/cpython that referenced this issue Feb 11, 2024
    * pythongh-53502: Fixes for tests in pythongh-113363
    
    * Use 32-bit compatible date in test_dump_naive_datetime_with_aware_datetime_option
    
    * Saving non-aware datetimes will use the old behaviour regardless of the aware_datimetime setting
    aisk pushed a commit to aisk/cpython that referenced this issue Feb 11, 2024
    Glyphack pushed a commit to Glyphack/cpython that referenced this issue Sep 2, 2024
    …or dumps aware datetime. (python#113363)
    
    * add options to loads and dumps aware datetime in plistlib
    Glyphack pushed a commit to Glyphack/cpython that referenced this issue Sep 2, 2024
    * pythongh-53502: Fixes for tests in pythongh-113363
    
    * Use 32-bit compatible date in test_dump_naive_datetime_with_aware_datetime_option
    
    * Saving non-aware datetimes will use the old behaviour regardless of the aware_datimetime setting
    Glyphack pushed a commit to Glyphack/cpython that referenced this issue Sep 2, 2024
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    OS-mac stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error type-feature A feature request or enhancement
    Projects
    Archived in project
    Development

    No branches or pull requests

    5 participants