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

Use 'timezone.localtime()' when calculating the next run time #520

Merged
merged 1 commit into from
Mar 21, 2021

Conversation

wy-z
Copy link
Contributor

@wy-z wy-z commented Mar 18, 2021

Signed-off-by: weiyang weiyang.ones@gmail.com

Hi friends, first of all, thank you for your excellent work.
When calculating the next run time of a cron job, we should use the correct time zone to get the correct time.

Example codes

>>> from django_q.conf import croniter
>>> from django.utils import timezone
>>> import arrow
>>> timezone.localtime()
datetime.datetime(2021, 3, 18, 12, 15, 15, 723112, tzinfo=<DstTzInfo 'Asia/Shanghai' CST+8:00:00 STD>)
>>>
>>>
>>> arrow.get(croniter("0 17 * * 2-5", timezone.now()).get_next())
<Arrow [2021-03-18T17:00:00+00:00]>
>>> arrow.get(croniter("0 17 * * 2-5", timezone.localtime()).get_next())
<Arrow [2021-03-18T09:00:00+00:00]>

Related Documents

How can I obtain the local time in the current time zone?

>>> from django.utils import timezone
>>> timezone.localtime(timezone.now())
datetime.datetime(2012, 3, 3, 20, 10, 53, 873365, tzinfo=<DstTzInfo 'Europe/Paris' CET+1:00:00 STD>)

Signed-off-by: weiyang <weiyang.ones@gmail.com>
@wy-z
Copy link
Contributor Author

wy-z commented Mar 18, 2021

@Koed00 Thank you for your excellent work again.

@Koed00 Koed00 merged commit 1869a94 into Koed00:master Mar 21, 2021
@Koed00
Copy link
Owner

Koed00 commented Mar 21, 2021

Thanks! Hope this will solve some of the timezone issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants