René's URL Explorer Experiment


Title: datetime.fromisoformat() (C) drops the sub-second part of a UTC offset, breaking round-trips · Issue #152079 · python/cpython · GitHub

Open Graph Title: datetime.fromisoformat() (C) drops the sub-second part of a UTC offset, breaking round-trips · Issue #152079 · python/cpython

X Title: datetime.fromisoformat() (C) drops the sub-second part of a UTC offset, breaking round-trips · Issue #152079 · python/cpython

Description: Bug report Bug description: The C implementation of datetime.fromisoformat() silently drops the sub-second part of a UTC offset whenever the offset's whole-second part is zero, returning timezone.utc. This breaks round-trips: a value the...

Open Graph Description: Bug report Bug description: The C implementation of datetime.fromisoformat() silently drops the sub-second part of a UTC offset whenever the offset's whole-second part is zero, returning timezone.u...

X Description: Bug report Bug description: The C implementation of datetime.fromisoformat() silently drops the sub-second part of a UTC offset whenever the offset's whole-second part is zero, returning timezo...

Opengraph URL: https://github.com/python/cpython/issues/152079

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"datetime.fromisoformat() (C) drops the sub-second part of a UTC offset, breaking round-trips","articleBody":"# Bug report\n\n### Bug description:\n\nThe C implementation of `datetime.fromisoformat()` silently drops the sub-second part of a\nUTC offset whenever the offset's whole-second part is zero, returning `timezone.utc`. This\nbreaks round-trips: a value the module itself produces via `isoformat()` is not parsed\nback faithfully.\n\n```python\n>>> from datetime import datetime, timezone, timedelta\n>>> dt = datetime(2020, 6, 15, 12, 34, 56, tzinfo=timezone(timedelta(microseconds=1)))\n>>> s = dt.isoformat()\n>>> s\n'2020-06-15T12:34:56+00:00:00.000001'\n>>> datetime.fromisoformat(s).utcoffset()      # C accelerator\ndatetime.timedelta(0)                          # the 1-microsecond offset is gone\n```\n\nThe pure-Python implementation is correct:\n\n```python\n>>> import _pydatetime\n>>> _pydatetime.datetime.fromisoformat(s).utcoffset()\ndatetime.timedelta(microseconds=1)\n```\n\nThe negative case `'...-00:00:00.000001'` is dropped the same way.\n\nThis is not a non-standard format: `isoformat()` is documented to emit\n`+HH:MM[:SS[.ffffff]]` and `fromisoformat()` is documented to accept it (\"Time zone\noffsets may have fractional seconds\"), so this is documented round-trippable data being\nsilently dropped.\n\n### Root cause\n\n`Modules/_datetimemodule.c`, `tzinfo_from_isoformat_results()` short-circuits to UTC on the\nwhole-second offset alone, ignoring the parsed sub-second component:\n\n```c\n// Create a timezone from offset in seconds (0 returns UTC)\nif (tzoffset == 0) {\n    return Py_NewRef(CONST_UTC(NO_STATE));\n}\n```\n\nWhen `tzoffset == 0` but `tz_useconds != 0`, the sub-second part is discarded. The\npure-Python implementation checks all offset components before collapsing to UTC.\n\n### Suggested fix\n\nOnly short-circuit to UTC when both the whole-second and sub-second parts are zero:\n\n```c\nif (tzoffset == 0 && tz_useconds == 0) {\n    return Py_NewRef(CONST_UTC(NO_STATE));\n}\n```\n\nThe fall-through path already builds the correct `timezone(timedelta(...))`. A plain\n`+00:00` offset still returns `timezone.utc`. I confirmed against a full C-vs-pure-Python\ndifferential that the only inputs whose behaviour changes are exactly these zero-whole-\nsecond sub-second offsets, with no other divergence introduced. I have a patch and a\nround-trip regression test (running under both implementations) ready.\n\nThis is a sibling to #152060, a separate `fromisoformat()` defect in the pure-Python\nimplementation.\n\n### CPython versions tested on:\n\n3.16 (main, built from source)\n\n### Operating systems tested on:\n\nmacOS\n\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-152087\n* gh-152174\n* gh-152175\n* gh-152176\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/tonghuaroot","@type":"Person","name":"tonghuaroot"},"datePublished":"2026-06-24T13:09:23Z","url":"https://github.com/python/cpython/issues/152079"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:cd8fdd1a-1302-f714-f930-346e307afd41
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id967A:2A98A:1CB713:241B83:6B02029B
html-safe-nonce86432a4030eb03a121492a8f4765f14995963034105d51d6f6ea9cda2e3efbb8
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NjdBOjJBOThBOjFDQjcxMzoyNDFCODM6NkIwMjAyOUIiLCJ2aXNpdG9yX2lkIjoiNDEwNDI3ODc2ODU1NjgzNTQ4MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacdb729c48c5d1cd5a59365dae000b5d0cedeb9aa00cbaec8a0eaee33b6b893faa
hovercard-subject-tagissue:4735108937
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/152079/issue_layout
twitter:imagehttps://opengraph.githubassets.com/81793f6c65cc69d87813e4e827a524cfdd27f2ffbd3f02de4d103c2b5e0ebe3f/python/cpython/issues/152079
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/81793f6c65cc69d87813e4e827a524cfdd27f2ffbd3f02de4d103c2b5e0ebe3f/python/cpython/issues/152079
og:image:altBug report Bug description: The C implementation of datetime.fromisoformat() silently drops the sub-second part of a UTC offset whenever the offset's whole-second part is zero, returning timezone.u...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernametonghuaroot
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/152079#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F152079
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F152079
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/152079
Reloadhttps://github.com/python/cpython/issues/152079
Reloadhttps://github.com/python/cpython/issues/152079
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
https://github.com/python/cpython
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/152079
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/152079
#152087https://github.com/python/cpython/pull/152087
datetime.fromisoformat() (C) drops the sub-second part of a UTC offset, breaking round-tripshttps://github.com/python/cpython/issues/152079#top
#152087https://github.com/python/cpython/pull/152087
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com/tonghuaroot
tonghuaroothttps://github.com/tonghuaroot
on Jun 24, 2026https://github.com/python/cpython/issues/152079#issue-4735108937
#152060https://github.com/python/cpython/issues/152060
gh-152079: Fix C datetime.fromisoformat() dropping sub-second UTC offset #152087https://github.com/python/cpython/pull/152087
[3.15] gh-152079: Fix _datetime.fromisoformat() mishandling a sub-second tz offset (GH-152087) #152174https://github.com/python/cpython/pull/152174
[3.14] gh-152079: Fix _datetime.fromisoformat() mishandling a sub-second tz offset (GH-152087) #152175https://github.com/python/cpython/pull/152175
[3.13] gh-152079: Fix _datetime.fromisoformat() mishandling a sub-second tz offset (GH-152087) #152176https://github.com/python/cpython/pull/152176
StanFromIrelandhttps://github.com/StanFromIreland
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
on Jun 24, 2026https://github.com/python/cpython/issues/152079#event-27146548125
StanFromIrelandhttps://github.com/StanFromIreland
Date and time issues 🕰️https://github.com/orgs/python/projects/21
on Jun 24, 2026https://github.com/python/cpython/issues/152079#event-27146555882
https://github.com/StanFromIreland
StanFromIrelandhttps://github.com/StanFromIreland
on Jun 24, 2026https://github.com/python/cpython/issues/152079#issuecomment-4792830893
#152060https://github.com/python/cpython/issues/152060
StanFromIrelandhttps://github.com/StanFromIreland
completedhttps://github.com/python/cpython/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#152087https://github.com/python/cpython/pull/152087
on Jun 25, 2026https://github.com/python/cpython/issues/152079#event-27187017123
StanFromIrelandhttps://github.com/StanFromIreland
on Jun 25, 2026https://github.com/python/cpython/issues/152079#event-27187017135
gh-152079: Fix `_datetime.fromisoformat()` mishandling a sub-second t…https://github.com/python/cpython/commit/6f9c76d8d86997012acfa09fed05396aa9349bbf
gh-152079https://github.com/python/cpython/issues/152079
6f9c76dhttps://github.com/python/cpython/commit/6f9c76d8d86997012acfa09fed05396aa9349bbf
github-project-automationhttps://github.com/apps/github-project-automation
Date and time issues 🕰️https://github.com/orgs/python/projects/21
on Jun 25, 2026https://github.com/python/cpython/issues/152079
https://github.com/tonghuaroot
tonghuaroothttps://github.com/tonghuaroot
on Jun 25, 2026https://github.com/python/cpython/issues/152079#issuecomment-4797799408
https://github.com/StanFromIreland
StanFromIrelandhttps://github.com/StanFromIreland
on Jun 25, 2026https://github.com/python/cpython/issues/152079#issuecomment-4797840499
https://github.com/python/cpython/pull/124550/changeshttps://github.com/python/cpython/pull/124550/changes
StanFromIrelandhttps://github.com/StanFromIreland
on Jun 25, 2026https://github.com/python/cpython/issues/152079#event-27188302221
[3.13] gh-152079: Fix `_datetime.fromisoformat()` mishandling a sub-s…https://github.com/python/cpython/commit/c5ac8251b535cc2f282af1d428855bc52b5b5645
gh-152079https://github.com/python/cpython/issues/152079
c5ac825https://github.com/python/cpython/commit/c5ac8251b535cc2f282af1d428855bc52b5b5645
[3.15] gh-152079: Fix `_datetime.fromisoformat()` mishandling a sub-s…https://github.com/python/cpython/commit/cf8051b2e782e626062bf85e223b46e92b1ab2bb
gh-152079https://github.com/python/cpython/issues/152079
cf8051bhttps://github.com/python/cpython/commit/cf8051b2e782e626062bf85e223b46e92b1ab2bb
[3.14] gh-152079: Fix `_datetime.fromisoformat()` mishandling a sub-s…https://github.com/python/cpython/commit/6e7de8670c7375c71e5a37e31467fc0f4c3cbe7f
gh-152079https://github.com/python/cpython/issues/152079
6e7de86https://github.com/python/cpython/commit/6e7de8670c7375c71e5a37e31467fc0f4c3cbe7f
https://github.com/tonghuaroot
tonghuaroothttps://github.com/tonghuaroot
on Jun 25, 2026https://github.com/python/cpython/issues/152079#issuecomment-4800288709
https://gist.github.com/tonghuaroot/b2a17a17c5c30ae7b8b4667c570c45b1https://gist.github.com/tonghuaroot/b2a17a17c5c30ae7b8b4667c570c45b1
#124550https://github.com/python/cpython/pull/124550
#152079https://github.com/python/cpython/issues/152079
#152157https://github.com/python/cpython/issues/152157
datetime: pure Python implementation of fromisoformat() handles times with trailing spaces inconsistently with the C extension #130959https://github.com/python/cpython/issues/130959
#152204https://github.com/python/cpython/issues/152204
#152205https://github.com/python/cpython/pull/152205
#124550https://github.com/python/cpython/pull/124550
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/152079
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/152079
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
Date and time issues 🕰️https://github.com/orgs/python/projects/21
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.