René's URL Explorer Experiment


Title: Inconsistent use of UTC/local naïve datetimes · Issue #1505 · python-telegram-bot/python-telegram-bot · GitHub

Open Graph Title: Inconsistent use of UTC/local naïve datetimes · Issue #1505 · python-telegram-bot/python-telegram-bot

X Title: Inconsistent use of UTC/local naïve datetimes · Issue #1505 · python-telegram-bot/python-telegram-bot

Description: PR #1485 made telegram.utils.helpers.from_timestamp return a naïve datetime.datetime object in UTC, but this created an inconsistency with the rest of the repository in the handling of naïve datetime.datetimes, where it is assumed that t...

Open Graph Description: PR #1485 made telegram.utils.helpers.from_timestamp return a naïve datetime.datetime object in UTC, but this created an inconsistency with the rest of the repository in the handling of naïve dateti...

X Description: PR #1485 made telegram.utils.helpers.from_timestamp return a naïve datetime.datetime object in UTC, but this created an inconsistency with the rest of the repository in the handling of naïve dateti...

Opengraph URL: https://github.com/python-telegram-bot/python-telegram-bot/issues/1505

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Inconsistent use of UTC/local naïve datetimes","articleBody":"PR #1485 made `telegram.utils.helpers.from_timestamp` return a naïve `datetime.datetime` object in UTC, but this created an inconsistency with the rest of the repository in the handling of naïve `datetime.datetime`s, where it is assumed that these objects represent *local* time. In fact, there is a direct inconsistency between `from_timestamp` and `to_timestamp` helpers, since the latter still assumes that the `datetime` object is in local time.\r\n\r\nSee [#1497 (comment)](https://github.com/python-telegram-bot/python-telegram-bot/pull/1497#issuecomment-527256274) (point `3.`) for extended discussion.\r\n\r\nI've already fixed the issue in #1497 (and added tests), but should I make a separate PR to isolate the change?\r\n\r\n\r\n### Steps to reproduce\r\n\r\n0. Go to a place with nonzero UTC offset. I live in CEST (GMT +2).\r\n\r\n1. Construct a `telegram.Message` from a JSON data dictionary. This is a message I sent to a test bot of mine (stripped of the optional fields), as received from an HTTP request to Telegram:\r\n\r\n    ```python\r\n    import telegram as tg\r\n    \r\n    message_json = {\r\n        'message_id': 462,\r\n        'from': {\r\n            'id': 41214001,\r\n            'is_bot': False,\r\n            'first_name': 'Paolo',\r\n        },\r\n        'chat': {\r\n            'id': 41214001,\r\n            'type': 'private'\r\n        },\r\n        'date': 1567596574,\r\n    }\r\n    \r\n    original_timestamp = message_json['date']\r\n\r\n    bot = tg.Bot('000:not_a_token')\r\n    message = tg.Message.de_json(message_json, bot=bot)\r\n    ```\r\n\r\n2.  Re-form the `Message`'s JSON `dict` and extract the timestamp:\r\n    ```python\r\n    restored_timestamp = message.to_dict()['date']\r\n    ```\r\n\r\n3. Check that the timestamps are the same:\r\n    ```python\r\n    assert restored_timestamp == original_timestamp, \\\r\n        f\"Timestamps differ by {restored_timestamp - original_timestamp} seconds\"\r\n    ```\r\n\r\n### Expected behaviour\r\nThe timestamps should be the same.\r\n\r\n### Actual behaviour\r\nThe timestamps differ by the local UTC offset (reversed):\r\n\r\n```text\r\nAssertionError: Timestamps differ by -7200 seconds\r\n```\r\n\r\nWhen the `Message` is constructed, the `datetime` object it gets represents UTC time, but when it gets re-converted to a timestamp, that same object is assumed to be in local time, which in my case is `7200` seconds ahead of UTC, so the resulting timestamp is `7200` seconds behind the original.\r\n\r\n### Configuration\r\n\u003cdetails>\r\n\r\n**Operating System:**  Windows\r\n\r\n\r\n**Version of Python, python-telegram-bot & dependencies:**\r\n\r\n``$ python -m telegram``\r\n\r\n```\r\npython-telegram-bot 12.0.0 (v12.0.0-0-gc84e21d)\r\ncertifi 2019.03.09\r\nfuture 0.17.1\r\nPython 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)]\r\n```\r\n\r\n\u003c/details>\r\n","author":{"url":"https://github.com/plammens","@type":"Person","name":"plammens"},"datePublished":"2019-09-04T12:20:33Z","url":"https://github.com/python-telegram-bot/python-telegram-bot/issues/1505"}

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:681b9814-f561-e9f0-b3a8-862056e7fb63
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idDED2:9E08E:157129E:1AC502B:6B0258A2
html-safe-nonce4d35bd135607d73213334ad126d379cb36817867e273c71226b7a4a5339def91
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERUQyOjlFMDhFOjE1NzEyOUU6MUFDNTAyQjo2QjAyNThBMiIsInZpc2l0b3JfaWQiOiI3MTgyNDgzMzYxODgxMzU1ODYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac5304cabbc9830406f8ea2550d79b178655f9c570abb1f663ce40200dcee875f8
hovercard-subject-tagissue:489125782
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-telegram-bot/python-telegram-bot/1505/issue_layout
twitter:imagehttps://opengraph.githubassets.com/416df4137a4aeddec8ea24c47b2e8339a9ffabcdcf3a74b9bcd54e237098e797/python-telegram-bot/python-telegram-bot/issues/1505
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/416df4137a4aeddec8ea24c47b2e8339a9ffabcdcf3a74b9bcd54e237098e797/python-telegram-bot/python-telegram-bot/issues/1505
og:image:altPR #1485 made telegram.utils.helpers.from_timestamp return a naïve datetime.datetime object in UTC, but this created an inconsistency with the rest of the repository in the handling of naïve dateti...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameplammens
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
go-importgithub.com/python-telegram-bot/python-telegram-bot git https://github.com/python-telegram-bot/python-telegram-bot.git
octolytics-dimension-user_id16178365
octolytics-dimension-user_loginpython-telegram-bot
octolytics-dimension-repository_id38696925
octolytics-dimension-repository_nwopython-telegram-bot/python-telegram-bot
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id38696925
octolytics-dimension-repository_network_root_nwopython-telegram-bot/python-telegram-bot
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-telegram-bot/python-telegram-bot/issues/1505#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython-telegram-bot%2Fpython-telegram-bot%2Fissues%2F1505
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-telegram-bot%2Fpython-telegram-bot%2Fissues%2F1505
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-telegram-bot%2Fpython-telegram-bot
Reloadhttps://github.com/python-telegram-bot/python-telegram-bot/issues/1505
Reloadhttps://github.com/python-telegram-bot/python-telegram-bot/issues/1505
Reloadhttps://github.com/python-telegram-bot/python-telegram-bot/issues/1505
python-telegram-bothttps://github.com/python-telegram-bot
python-telegram-bothttps://github.com/python-telegram-bot/python-telegram-bot
Codehttps://github.com/python-telegram-bot/python-telegram-bot
Issues23 (23)https://github.com/python-telegram-bot/python-telegram-bot/issues
Pull requests19 (19)https://github.com/python-telegram-bot/python-telegram-bot/pulls
Discussionshttps://github.com/python-telegram-bot/python-telegram-bot/discussions
Actionshttps://github.com/python-telegram-bot/python-telegram-bot/actions
Projectshttps://github.com/python-telegram-bot/python-telegram-bot/projects
Wikihttps://github.com/python-telegram-bot/python-telegram-bot/wiki
Security and qualityhttps://github.com/python-telegram-bot/python-telegram-bot/security
Insightshttps://github.com/python-telegram-bot/python-telegram-bot/insights
https://github.com/python-telegram-bot/python-telegram-bot
New issuehttps://github.com/login?return_to=https://github.com/python-telegram-bot/python-telegram-bot/issues/1505
New issuehttps://github.com/login?return_to=https://github.com/python-telegram-bot/python-telegram-bot/issues/1505
💡 featurehttps://github.com/python-telegram-bot/python-telegram-bot/issues?q=type:"💡 feature"
#1506https://github.com/python-telegram-bot/python-telegram-bot/pull/1506
Inconsistent use of UTC/local naïve datetimeshttps://github.com/python-telegram-bot/python-telegram-bot/issues/1505#top
#1506https://github.com/python-telegram-bot/python-telegram-bot/pull/1506
📋 pending-mergework status: pending-mergehttps://github.com/python-telegram-bot/python-telegram-bot/issues?q=state%3Aopen%20label%3A%22%F0%9F%93%8B%20pending-merge%22
https://github.com/plammens
plammenshttps://github.com/plammens
on Sep 4, 2019https://github.com/python-telegram-bot/python-telegram-bot/issues/1505#issue-489125782
#1485https://github.com/python-telegram-bot/python-telegram-bot/pull/1485
#1497 (comment)https://github.com/python-telegram-bot/python-telegram-bot/pull/1497#issuecomment-527256274
#1497https://github.com/python-telegram-bot/python-telegram-bot/pull/1497
https://github.com/Bibo-Joshi
Bibo-Joshihttps://github.com/Bibo-Joshi
on Sep 4, 2019https://github.com/python-telegram-bot/python-telegram-bot/issues/1505#issuecomment-527891333
https://github.com/plammens
plammenshttps://github.com/plammens
on Sep 4, 2019https://github.com/python-telegram-bot/python-telegram-bot/issues/1505#issuecomment-527903015
#1409 (comment)https://github.com/python-telegram-bot/python-telegram-bot/issues/1409#issuecomment-524462823
plammenshttps://github.com/plammens
on Sep 4, 2019https://github.com/python-telegram-bot/python-telegram-bot/issues/1505#event-2607316188
fix: unify naive datetime treatment to assume UTChttps://github.com/plammens/python-telegram-bot/commit/ab64d4e6946b1a5280453ce0ba855f47e042e699
ab64d4ehttps://github.com/plammens/python-telegram-bot/commit/ab64d4e6946b1a5280453ce0ba855f47e042e699
Poolitzerhttps://github.com/Poolitzer
enhancementhttps://github.com/python-telegram-bot/python-telegram-bot/issues?q=state%3Aopen%20label%3A%22enhancement%22
📋 pending-mergework status: pending-mergehttps://github.com/python-telegram-bot/python-telegram-bot/issues?q=state%3Aopen%20label%3A%22%F0%9F%93%8B%20pending-merge%22
on Sep 29, 2019https://github.com/python-telegram-bot/python-telegram-bot/issues/1505#event-2670948928
tsnoamhttps://github.com/tsnoam
completedhttps://github.com/python-telegram-bot/python-telegram-bot/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#1506https://github.com/python-telegram-bot/python-telegram-bot/pull/1506
on Nov 15, 2019https://github.com/python-telegram-bot/python-telegram-bot/issues/1505#event-2803950634
github-actionshttps://github.com/apps/github-actions
on Aug 21, 2020https://github.com/python-telegram-bot/python-telegram-bot/issues/1505#event-3677960040
Bibo-Joshihttps://github.com/Bibo-Joshi
enhancementhttps://github.com/python-telegram-bot/python-telegram-bot/issues?q=state%3Aopen%20label%3A%22enhancement%22
on Nov 4, 2024https://github.com/python-telegram-bot/python-telegram-bot/issues/1505#event-15107523341
Sign up for freehttps://github.com/signup?return_to=https://github.com/python-telegram-bot/python-telegram-bot/issues/1505
Sign in to commenthttps://github.com/login?return_to=https://github.com/python-telegram-bot/python-telegram-bot/issues/1505
📋 pending-mergework status: pending-mergehttps://github.com/python-telegram-bot/python-telegram-bot/issues?q=state%3Aopen%20label%3A%22%F0%9F%93%8B%20pending-merge%22
💡 featurehttps://github.com/python-telegram-bot/python-telegram-bot/issues?q=type:"💡 feature"
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.