Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Support for tz-aware datetime.datetime objects#1451

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

torresjrjr
Copy link

Original issue

Issue:#1409
version: 12.0.0b1

Changes

The._put() method can now accept utc_offset-aware/timezone-awaredatetime.datetime objects. This helps bots to be hosted on a server with any timezone without complications.

To convert datetimes to UTC, a "UTC" subclass of thedatetime.tzinfo class was added, and used in._put().

Other options considered

  • Changing all the.now() comparisons in._put() to.utcnow(). This was not chosen, since it would cause a major compatibility issue. Bots would have to be rewritten to pass in UTC datetimes, instead of local (computer time) datetimes, into the jobqueue.run_once and other methods. This would likely be unwanted behaivour.

## Original issue ##Issue:python-telegram-bot#1409 version: 12.0.0b1## Changes ##The `._put()` method can now accept utc_offset-aware/timezone-aware `datetime.datetime` objects. This helps bots to be hosted on a server with any timezone without complications.To convert datetimes to UTC, a "UTC" subclass of the `datetime.tzinfo` class was added, and used in `._put()`.## Other options considered ##- Changing all the `.now()` comparisons in `._put()` to `.utcnow()`. This was not chosen, since it would cause a major compatibility issue. Bots would have to be rewritten to pass in UTC datetimes, instead of local (computer time) datetimes, into the jobqueue.run_once and other methods. This would likely be unwanted behaivour.
@Eldinnie
Copy link
Member

Hi@torresjrjr
Thanks for making this PR, and our excuse for not responding sooner.
I like the addition and the idea behind it, but I would like to see you add some tests reflecting the changes.

Could you add those please?

@EldinnieEldinnie added the 📋 pending-replywork status: pending-reply labelAug 23, 2019
@tsnoam
Copy link
Member

Actually, I like to open this for discussion with the other maintainers.
IMHO, servers should run on UTC . Timezones add so many questions and problems.
My vote is not to add this code to the library.

@EldinnieTelegram GithubBot Revised
Copy link
Member

@tsnoam the point they make in the issue, is that sometimes you want to userun_daily for the user-aware timezone. This PR makes it possible to say:
Run daily on timezone +5 and it will convert to UTC to put in the job_queue.
It assumes the server on UTC and makes it easier to add jobs for all timezones without the hassle of calculating the timedelta manually or program it in every bot

@tsnoam
Copy link
Member

Well, that's a subset of what a timezone is.
A timezone can also be "Asia/Jerusalem". Now go and map between summer and winter clock. Or, if you're on the edge of switching between them, switch.
Not to mention countries which change their decision when to move between summer & winter clock every year.
I prefer not to "put a healthy head inside a sick bed".

@torresjrjr
Copy link
Author

Actually, I'm not so invested in this PR as much, since this was an attempt at a solution to a problem I later solved. I wanted to "help my bot to be hosted on a server with any timezone without complications" but I ended up simply adding an extra step in my code.

I created atimedelta object of the time fromnow() to thedatetime, and submitted that to my job creations. It's a quick solution others might find useful :) and could be used in the final PR in the.put() method.

I should also stress that I'm a python noob/intermediate. I find PRs scary. So please, take my idea and do what you will. Thanks.

@Eldinnie
Copy link
Member

We were debating whether this should be a here, in helpers or in the programmers hands. I guess you helped us answering that. I'm closing this PR.

@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsAug 20, 2020
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers
No reviews
Assignees
No one assigned
Labels
📋 pending-replywork status: pending-reply
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@torresjrjr@Eldinnie@tsnoam

[8]ページ先頭

©2009-2025 Movatter.jp