Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

job_queue.run_daily fails for timezone aware datetime.datetime objects #1409

Closed
Tianmaru opened this issue May 21, 2019 · 5 comments
Closed

Comments

@Tianmaru
Copy link

job_queue.run_daily fails for timezone aware datetime.datetime objects (version 12.0.0b1).
It would be nice if you could give timezone-information, for example, if the bot is being hosted in another timezone.

@torresjrjr
Copy link

torresjrjr commented Jul 20, 2019

I have the same problem. My testing is local at BST (British Summer Time) but my hosting uses UTC time. I think personally the wrapper should use utcnow() instead of now() when calculating timedeltas for the job queue, because it avoids ambiguous code.

Otherwise, I also wish jobqueue.run_once(when=DT_OBJ) could accept timezone/utc_offset-aware datetime objects too.

torresjrjr added a commit to torresjrjr/python-telegram-bot that referenced this issue Jul 20, 2019
## 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.
torresjrjr added a commit to torresjrjr/python-telegram-bot that referenced this issue Jul 20, 2019
## 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.
@torresjrjr
Copy link

A solution in the case for jobqueue.run_once() is:

timedelta_obj = datetime_obj - datetime.datetime.utcnow()
jobqueue.run_once(callback, timedelta_obj)

The issue still stands for jobqueue.run_daily.

@Eldinnie
Copy link
Member

As we mentioned on the linked closed PR.
Servers should run on UTC, calculations to different timezones should be the responsibility of the user. closing this.

@Tianmaru
Copy link
Author

As we mentioned on the linked closed PR.
Servers should run on UTC, calculations to different timezones should be the responsibility of the user. closing this.

It would be a clean and easy solution if the user has just to calculate the UTC offset, but it can become very cumbersome for timezones with Daylight Saving Time. If you want a job to run daily on a specific time, you have to restart jobqueue.run_daily atleast two times a year with different UTC-timestamps. The use of timezone aware datetime objects would simplify this a lot.

@Bibo-Joshi
Copy link
Member

@Tianmaru Regarding DST: This was "fixed" by documentation, see #1381

@github-actions github-actions bot locked and limited conversation to collaborators Aug 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants