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

Does not work on DST changes (depends on system timezone) #35

Closed
mateuszf opened this issue Oct 20, 2014 · 1 comment
Closed

Does not work on DST changes (depends on system timezone) #35

mateuszf opened this issue Oct 20, 2014 · 1 comment

Comments

@mateuszf
Copy link

croniter 0.3.5, Python 2.7.8
Consider test case executed on machine with 'Europe/Warsaw' (UTC+1) timezone, change from DST to normal occurs on 2014-10-26 02:59 +2:00 (UTC 00:59) -> 02:00 +1:00 (UTC 01:00):

from datetime import datetime
from croniter import croniter
import pytz

Using datetime objects:

Before change (naive datetime) - VALID
cr = croniter('0 * * * *', datetime(2014, 10, 26, 0))
print 'next = ', cr.get_next(datetime)   # 2014-10-26 01:00:00, OK
print 'prev = ', cr.get_prev(datetime)   # 2014-10-26 00:00:00, OK 
Before change (UTC datetime) - INVALID
cr = croniter('0 * * * *', datetime(2014, 10, 26, 0).replace(tzinfo=pytz.utc))
print 'next = ', cr.get_next(datetime)   # 2014-10-26 02:00:00+00:00, INVALID
print 'prev = ', cr.get_prev(datetime)   # 2014-10-26 02:00:00+00:00, INVALID
After change (naive datetime) - INVALID
cr = croniter('0 * * * *', datetime(2014, 10, 26, 1))
print 'next = ', cr.get_next(datetime)   # 2014-10-26 02:00:00, OK
print 'prev = ', cr.get_prev(datetime)   # 2014-10-26 02:00:00, INVALID
After change (UTC datetime) - INVALID
cr = croniter('0 * * * *', datetime(2014, 10, 26, 1).replace(tzinfo=pytz.utc))
print 'next = ', cr.get_next(datetime)   # 2014-10-26 03:00:00+00:00, INVALID
print 'prev = ', cr.get_prev(datetime)   # 2014-10-26 02:00:00+00:00, INVALID

Using timestamps:

Before change - INVALID
cr = croniter('0 * * * *', 1414281600) # UTC 00:00
print 'next = ', cr.get_next()   # 1414288800.0 (UTC 02:00), INVALID
print 'prev = ', cr.get_prev()   # 1414285200.0 (UTC 01:00), INVALID
After change - VALID
cr = croniter('0 * * * *', 1414285200) # UTC 01:00
print 'next = ', cr.get_next()   # 1414288800.0 (UTC 02:00), OK
print 'prev = ', cr.get_prev()   # 1414285200.0 (UTC 01:00), OK

Despite the fact that timestamps are UTC hardcoded all of test cases give much better results when system timezone is changed to e.g. Fiji UTC+12:00

@josegonzalez
Copy link
Contributor

This can be closed.

@kiorky kiorky closed this as completed Nov 1, 2016
kiorky added a commit that referenced this issue Nov 2, 2020
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

No branches or pull requests

3 participants