Title: datetime library doesn't support valid ISO-8601 alternative for midnight · Issue #102450 · python/cpython · GitHub
Open Graph Title: datetime library doesn't support valid ISO-8601 alternative for midnight · Issue #102450 · python/cpython
X Title: datetime library doesn't support valid ISO-8601 alternative for midnight · Issue #102450 · python/cpython
Description: Bug report According to ISO-8601, a time of 24:00 on a given date is a valid alternative to 00:00 of the following date, however Python does not support this, raising the following error when attempted: ValueError: hour must be in 0..23....
Open Graph Description: Bug report According to ISO-8601, a time of 24:00 on a given date is a valid alternative to 00:00 of the following date, however Python does not support this, raising the following error when attem...
X Description: Bug report According to ISO-8601, a time of 24:00 on a given date is a valid alternative to 00:00 of the following date, however Python does not support this, raising the following error when attem...
Opengraph URL: https://github.com/python/cpython/issues/102450
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"datetime library doesn't support valid ISO-8601 alternative for midnight","articleBody":"\u003c!--\r\n If you're new to Python and you're not sure whether what you're experiencing is a bug, the CPython issue tracker is not\r\n the right place to seek help. Consider the following options instead:\r\n\r\n - reading the Python tutorial: https://docs.python.org/3/tutorial/\r\n - posting in the \"Users\" category on discuss.python.org: https://discuss.python.org/c/users/7\r\n - emailing the Python-list mailing list: https://mail.python.org/mailman/listinfo/python-list\r\n - searching our issue tracker (https://github.com/python/cpython/issues) to see if\r\n your problem has already been reported\r\n--\u003e\r\n\r\n# Bug report\r\n\r\nAccording to [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601), a time of `24:00` on a given date is a valid alternative to `00:00` of the following date, however Python does not support this, raising the following error when attempted: `ValueError: hour must be in 0..23`.\r\n\r\nThis bug can be seen from multiple scenarios, specifically anything that internally calls the [`_check_time_fields` function](https://github.com/python/cpython/blob/main/Lib/datetime.py#L531-L546), such as the following:\r\n```python\r\n\u003e\u003e\u003e import datetime\r\n\u003e\u003e\u003e datetime.datetime(2022, 1, 2, 24, 0, 0) # should be equivalent to 2022-01-03 00:00:00\r\nTraceback (most recent call last):\r\n File \"\u003cpyshell#2\u003e\", line 1, in \u003cmodule\u003e\r\n datetime.datetime(2022, 3, 4, 24, 0, 0)\r\nValueError: hour must be in 0..23\r\n```\r\nThe fix for this is relatively simple: have an explicit check within [`_check_time_fields`](https://github.com/python/cpython/blob/main/Lib/datetime.py#L531-L546) for the scenario where `hour == 24 and minute == 0 and second == 0 and microsecond == 0`, or more concisely `hour == 24 and not any((minute, second, microsecond))`, and in this scenario increase the day by one (adjusting the week/month/year as necessary) and set the hour to 0.\r\n\r\nI imagine the [`check_time_args` C function](https://github.com/python/cpython/blob/main/Modules/_datetimemodule.c#L467-L499) would also have to be updated.\r\n\r\n\r\n# Your environment\r\n\r\n\u003c!-- Include as many relevant details as possible about the environment you experienced the bug in --\u003e\r\n\r\n- CPython versions tested on: 3.9.12, 3.10.7, 3.11.2 (presumably applies to all)\r\n- Operating system and architecture: MacOS Ventura arm64 (presumably applies to all)\r\n\r\n\u003c!--\r\nYou can freely edit this text. Remove any lines you believe are unnecessary.\r\n--\u003e\r\n\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-105856\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/TizzySaurus","@type":"Person","name":"TizzySaurus"},"datePublished":"2023-03-05T20:45:11.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":19},"url":"https://github.com/102450/cpython/issues/102450"}
| 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:0abde9b5-afed-5dbe-899b-ec7795ea8143 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 909A:B7306:23F5E59:316D39D:696AC1D2 |
| html-safe-nonce | d76c05af4b0f7da6e7a92a6857dff51a2e91281399edbcf0bc672ef61a9c6152 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MDlBOkI3MzA2OjIzRjVFNTk6MzE2RDM5RDo2OTZBQzFEMiIsInZpc2l0b3JfaWQiOiIyNjI5NTkwMjY3MDAwOTYzNTM4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | c07544ee5cedc0f3074d6b9835bff57ce9b6617e2683c3e2fe98e54b798e1777 |
| hovercard-subject-tag | issue:1610356937 |
| 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/python/cpython/102450/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a37513e0d9496fd404e43e9616eab52ca1ac91f54bd3c451bd6fee0fc5b231a7/python/cpython/issues/102450 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a37513e0d9496fd404e43e9616eab52ca1ac91f54bd3c451bd6fee0fc5b231a7/python/cpython/issues/102450 |
| og:image:alt | Bug report According to ISO-8601, a time of 24:00 on a given date is a valid alternative to 00:00 of the following date, however Python does not support this, raising the following error when attem... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | TizzySaurus |
| hostname | github.com |
| expected-hostname | github.com |
| None | 986b6a1d774985095564e64d6963d11f094da3d0e2bfda2ab1a27d63662eb033 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| 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 | 89ad2112b9c4e11df6a0c13c8c1f8eedd36b0977 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width