Title: [Bug]: PDF and PGF CreationDate/ModDate carry the wrong UTC offset · Issue #32630 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: PDF and PGF CreationDate/ModDate carry the wrong UTC offset · Issue #32630 · matplotlib/matplotlib
X Title: [Bug]: PDF and PGF CreationDate/ModDate carry the wrong UTC offset · Issue #32630 · matplotlib/matplotlib
Description: Bug summary PDF and PGF files generated by Matplotlib can contain incorrect UTC offsets in their CreationDate and ModDate metadata when no explicit dates are provided. The issue occurs in _datetime_to_pdf in lib/matplotlib/backends/backe...
Open Graph Description: Bug summary PDF and PGF files generated by Matplotlib can contain incorrect UTC offsets in their CreationDate and ModDate metadata when no explicit dates are provided. The issue occurs in _datetime...
X Description: Bug summary PDF and PGF files generated by Matplotlib can contain incorrect UTC offsets in their CreationDate and ModDate metadata when no explicit dates are provided. The issue occurs in _datetime...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/32630
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: PDF and PGF CreationDate/ModDate carry the wrong UTC offset","articleBody":"### Bug summary\n\nPDF and PGF files generated by Matplotlib can contain incorrect UTC offsets in their `CreationDate` and `ModDate` metadata when no explicit dates are provided.\n\nThe issue occurs in `_datetime_to_pdf` in `lib/matplotlib/backends/backend_pdf.py`, which uses a naive `datetime.today()`.\n\nThere are three problems:\n\n* Naive datetimes use `time.altzone` or `time.timezone`, causing daylight-saving offsets to be applied incorrectly throughout the year.\n* The minutes field is calculated from seconds incorrectly.\n* Timezone-aware datetimes have their UTC offset sign reversed.\n\nFor example, on the current main branch and Matplotlib 3.11.2:\n\n* India: `+05'1800'` instead of `+05'30'`.\n* New York in winter: `-04'00'` instead of `-05'00'`.\n* Amsterdam in winter: `+02'00'` instead of `+01'00'`.\n\n### Code for reproduction\n\n```python\nimport io, re, time\nimport matplotlib\nmatplotlib.use(\"pdf\")\nimport matplotlib.pyplot as plt\n\nbuf = io.BytesIO()\nplt.plot([1])\nplt.savefig(buf, format=\"pdf\")\nprint(\"matplotlib\", matplotlib.__version__, \"| TZ:\", time.tzname)\nprint(re.search(rb\"/CreationDate \\(([^)]*)\\)\", buf.getvalue()).group(1).decode())\n```\n\n```\nTZ=Asia/Kolkata python pdf_date_repro.py\nTZ=America/New_York python pdf_date_repro.py\n```\n\n### Actual outcome\n\nThe generated PDF and PGF metadata contain incorrect timezone offsets. The problem affects both `CreationDate` and `ModDate`.\n\n```\nmatplotlib 3.11.2 | TZ: ('IST', 'IST')\nD:20261121104550+05'1800'\nmatplotlib 3.11.2 | TZ: ('EST', 'EDT')\nD:20261121001551-04'00'\n```\n\n### Expected outcome\n\nOffsets should follow the PDF date format:\n\n`D:YYYYMMDDHHmmSSOHH'mm'`\n\nHere, `O` is the sign of the local UTC offset.\n\nThe generated metadata should contain the correct local UTC offset, including the correct daylight-saving adjustment and minutes.\n\n`SOURCE_DATE_EPOCH` output is not affected and continues to use UTC (`Z`).\n\n### Operating system\n\nConfirmed with the reproduction on the current main branch. The issue is timezone-dependent and affects systems using non-UTC timezones.\n\n### Matplotlib Version\n\n* Current main\n* Matplotlib 3.11.2\n\n### Additional information\n\nNo existing open issue reporting this problem was found.\n\nThe issue was initially identified through AI-assisted testing of date handling and confirmed by running the reproduction.\n","author":{"url":"https://github.com/sohailshk","@type":"Person","name":"sohailshk"},"datePublished":"2026-11-21T05:17:29Z","url":"https://github.com/matplotlib/matplotlib/issues/32630"}
| react-profiling | 0 |
| react-import-map | react,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-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:33de612f-62ed-4f02-1cd0-7c3eafbb470c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D88C:3690E2:E7BD08:1365E5B:6B064EDF |
| html-safe-nonce | 6a4bf51bd5e53fef435f19987d6ccaa1409a999fa98ce7075bf76abe1ed40458 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEODhDOjM2OTBFMjpFN0JEMDg6MTM2NUU1Qjo2QjA2NEVERiIsInZpc2l0b3JfaWQiOiI0NDIzNTA2MTIxMjUyNTU2NTExIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 47adb18a3897b34f8268c5a08c3686c5342d24775cf5408b506e0af37c820997 |
| hovercard-subject-tag | issue:6524833016 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/32630/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7f505d0400083df15f7bc63c06e5d6b37a4312676b4f3dda19e5335be717ad3e/matplotlib/matplotlib/issues/32630 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7f505d0400083df15f7bc63c06e5d6b37a4312676b4f3dda19e5335be717ad3e/matplotlib/matplotlib/issues/32630 |
| og:image:alt | Bug summary PDF and PGF files generated by Matplotlib can contain incorrect UTC offsets in their CreationDate and ModDate metadata when no explicit dates are provided. The issue occurs in _datetime... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sohailshk |
| hostname | github.com |
| expected-hostname | github.com |
| None | 772b6997ca4daa0428dd49a25d76052e765555ae560fe9c88517eb828bbd861e |
| turbo-cache-control | no-preview |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | f1f9a08f7c769a37f1dfc18ad43d463c222a7eea |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width