taichino / croniter

croniter is a python module to provide iteration for datetime object.
http://github.com/taichino/croniter
387 stars 105 forks source link

Wrong datetime related to change from DST to standard time #147

Closed Dunedan closed 2 years ago

Dunedan commented 4 years ago

I just noticed croniter producing wrong next datetimes when iterating over the change from DST to standard time.

Take this example, where the change from DST to standard time happens on 2020-10-25 03:00:00+02:00 to 2020-10-25 02:00:00+01:00:

from datetime import datetime

from croniter import croniter_range
from dateutil.tz import gettz

for i in croniter_range(
        datetime(2020, 10, 24, tzinfo=gettz("Europe/Berlin")),
        datetime(2020, 10, 29, tzinfo=gettz("Europe/Berlin")),
        "0 1 * * *"
):
    print(i)

When running this, it results in:

2020-10-24 00:00:00+02:00
2020-10-25 00:00:00+02:00
2020-10-26 01:00:00+01:00
2020-10-27 00:00:00+01:00
2020-10-28 00:00:00+01:00
2020-10-29 00:00:00+01:00

Notice the 2020-10-26 01:00:00+01:00 which is obviously wrong.

When choosing an hour after the change, the problem persists, but moves to the day the DST -> standard time change happened:

2020-10-24 10:00:00+02:00
2020-10-25 11:00:00+01:00
2020-10-26 10:00:00+01:00
2020-10-27 10:00:00+01:00
2020-10-28 10:00:00+01:00
Dunedan commented 4 years ago

I also noticed that this affects the change from standard time to DST as well:

2021-03-27 00:00:00+01:00
2021-03-28 00:00:00+01:00
2021-03-28 23:00:00+02:00
2021-03-29 00:00:00+02:00
2021-03-30 00:00:00+02:00
kiorky commented 2 years ago

i wont have time to fix dst changes, unfortunatly, if you can, you may submit a PR. Thanks though for the report.

kiorky commented 6 months ago

dup kiorky/croniter#1