-
-
Notifications
You must be signed in to change notification settings - Fork 31.2k
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
Comments
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). |
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. |
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. |
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. |
…ps aware datetime. (#113363) * add options to loads and dumps aware datetime in plistlib
O my, the PR causes builtbot failures (looks like 32 bit time_t) |
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
Triage: can this be re-closed following the recent fix PRs? |
…or dumps aware datetime. (python#113363) * add options to loads and dumps aware datetime in plistlib
* 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
…or dumps aware datetime. (python#113363) * add options to loads and dumps aware datetime in plistlib
* 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
…or dumps aware datetime. (python#113363) * add options to loads and dumps aware datetime in plistlib
* 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
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:
Linked PRs
The text was updated successfully, but these errors were encountered: