Title: Dates equality check fails when a date is folded and the other is not · Issue #115845 · python/cpython · GitHub
Open Graph Title: Dates equality check fails when a date is folded and the other is not · Issue #115845 · python/cpython
X Title: Dates equality check fails when a date is folded and the other is not · Issue #115845 · python/cpython
Description: Bug report Bug description: In the example I have two dates in the Europe/Rome format, representing 2:00 AM on a day with DST change. One of the dates is folded, the other is not. from datetime import datetime from zoneinfo import ZoneIn...
Open Graph Description: Bug report Bug description: In the example I have two dates in the Europe/Rome format, representing 2:00 AM on a day with DST change. One of the dates is folded, the other is not. from datetime imp...
X Description: Bug report Bug description: In the example I have two dates in the Europe/Rome format, representing 2:00 AM on a day with DST change. One of the dates is folded, the other is not. from datetime imp...
Opengraph URL: https://github.com/python/cpython/issues/115845
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Dates equality check fails when a date is folded and the other is not","articleBody":"# Bug report\r\n\r\n### Bug description:\r\n\r\nIn the example I have two dates in the Europe/Rome format, representing 2:00 AM on a day with DST change. One of the dates is folded, the other is not.\r\n\r\n```python\r\nfrom datetime import datetime\r\nfrom zoneinfo import ZoneInfo\r\n\r\nnot_folded = datetime(2023, 10, 29, 2, 0, tzinfo=ZoneInfo(\"Europe/Rome\"))\r\nfolded = datetime(2023, 10, 29, 2, 0, tzinfo=ZoneInfo(\"Europe/Rome\"), fold=1)\r\n\r\nprint(\"Not folded date: \", not_folded.isoformat())\r\nprint(\"The folded date: \", folded.isoformat())\r\n\r\nassert folded != not_folded\r\n```\r\n\r\nThe two dates are different, as the isoformat() print shows, and they represent a different moment in time (one is 00:00 UTC, the other one is 01:00 UTC). However, the assert fails:\r\n```\r\nNot folded date: 2023-10-29T02:00:00+02:00\r\nThe folded date: 2023-10-29T02:00:00+01:00\r\nTraceback (most recent call last):\r\n File \"/Users/alerinaldi/prova.py\", line 10, in \u003cmodule\u003e\r\n assert folded != not_folded\r\n ^^^^^^^^^^^^^^^^^^^^\r\nAssertionError\r\n```\r\n\r\nOf course, this also applies to other situations where dates are compared: I discovered the issue while memoizing the result of a function based on dates using a dict.\r\n```python\r\nfrom datetime import datetime\r\nfrom zoneinfo import ZoneInfo\r\n\r\n__memoized_dict = {}\r\n\r\n\r\ndef process_date(dt: datetime) -\u003e int:\r\n return int(dt.timestamp())\r\n\r\n\r\ndef memoized_result(dt: datetime) -\u003e int:\r\n if dt in __memoized_dict:\r\n return __memoized_dict[dt]\r\n res = process_date(dt)\r\n __memoized_dict[dt] = res\r\n return res\r\n\r\n\r\nprint(memoized_result(datetime(2023, 10, 29, 2, 0, tzinfo=ZoneInfo(\"Europe/Rome\"))))\r\nprint(memoized_result(datetime(2023, 10, 29, 2, 0, tzinfo=ZoneInfo(\"Europe/Rome\"), fold=1)))\r\n```\r\n\r\nThe second call returns a wrong result.\r\n\r\n### CPython versions tested on:\r\n\r\n3.12\r\n\r\n### Operating systems tested on:\r\n\r\nmacOS","author":{"url":"https://github.com/ale-rinaldi","@type":"Person","name":"ale-rinaldi"},"datePublished":"2024-02-23T09:23:44.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/115845/cpython/issues/115845"}
| 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:68db7991-51ee-8fd2-ff82-50d19eb347db |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BCA4:418ED:4E7F4EC:6CEEC8E:6A4F6D16 |
| html-safe-nonce | 6f689c021b2c89d7834ae3e12f354a0ed0307d7a4f674585d44a5ae71c530e0a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQ0E0OjQxOEVEOjRFN0Y0RUM6NkNFRUM4RTo2QTRGNkQxNiIsInZpc2l0b3JfaWQiOiI1NTczNzgzNzgxNDE4OTU0MDA2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | c5d462d01933fa653663b5520bfc48e46c4e52f448c606cf5c8597e684a534a7 |
| hovercard-subject-tag | issue:2150692322 |
| 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/115845/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e86af48b9d118792201cba9a6fd51c58968b191de9d05a9b8e5cc7f68c208e7b/python/cpython/issues/115845 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e86af48b9d118792201cba9a6fd51c58968b191de9d05a9b8e5cc7f68c208e7b/python/cpython/issues/115845 |
| og:image:alt | Bug report Bug description: In the example I have two dates in the Europe/Rome format, representing 2:00 AM on a day with DST change. One of the dates is folded, the other is not. from datetime imp... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ale-rinaldi |
| hostname | github.com |
| expected-hostname | github.com |
| None | b92d11c0aa4a77d54ef4af1078b6a15fb5a70a215b30c4ecf28889d5a8e656d9 |
| 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 | 4b249b445842943ed31549e027f57a8ade9881ed |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width