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

Croniter skips 2021-03-01 for "0 0 */10 * *" #178 (DST related bugs) #1

Open
cuu508 opened this issue Oct 23, 2021 · 6 comments
Open

Comments

@cuu508
Copy link
Contributor

cuu508 commented Oct 23, 2021

(originally reported in taichino/croniter#178)

Test snippet:

from datetime import datetime
from croniter import croniter

it = croniter("0 0 */10 * *", datetime(2021, 1, 1))

for i in range(0, 15):
    print(it.get_next(datetime).isoformat())

Result:

2021-01-11T00:00:00
2021-01-21T00:00:00
2021-01-31T00:00:00
2021-02-01T00:00:00
2021-02-11T00:00:00
2021-02-21T00:00:00
2021-03-11T00:00:00
2021-03-21T00:00:00
2021-03-31T00:00:00
2021-04-01T00:00:00
2021-04-11T00:00:00
2021-04-21T00:00:00
2021-05-01T00:00:00
2021-05-11T00:00:00
2021-05-21T00:00:00

In the above output, 2021-03-01T00:00:00 is missing.

@kiorky
Copy link
Owner

kiorky commented Nov 25, 2021

dup taichino/croniter#147

@kiorky
Copy link
Owner

kiorky commented Nov 25, 2021

as said on taichino/croniter#147 (comment) and
taichino/croniter#178 (comment) and
taichino/croniter#141

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

@kiorky
Copy link
Owner

kiorky commented Nov 25, 2021

The last work i didnt have time to finish was there : https://github.com/kiorky/croniter-fork/pull/34

@evanpurkhiser
Copy link
Contributor

Seems like some of these tickets are missing implementation detail differences about which tzinfo implementation is being used.

I've noticed for our case at Sentry, we use the newer zoneinfo implementation, and this test case is failing

@pytest.mark.skipif(
    sys.version_info < (3, 9),
    reason="Test only valid on python 3.9 and above"
)
def test_dst_zoneinfo(self):
    """
    Test DST crossover with zoneinfo
    """
    from zoneinfo import ZoneInfo

    # 5:00 AM EST before EDST crossover
    tz = ZoneInfo("America/New_York")
    ts = datetime(2024, 3, 9, 5, 0, 0, tzinfo=tz)

    # Next tick is after the EDST crossover. Closk move forward one hour,
    # but we would still expect the next cron iteration at 5:00 AM EDST.
    ts_after_dst = croniter("0 5 * * *", ts).get_next(datetime)
    self.assertEqual(ts_after_dst, datetime(2024, 3, 10, 5, 0, 0, tzinfo=tz))

This test case is producing 2024-3-10 4:00:00-04:00, but we would expect 2024-3-10 5:00:00-04:00.

The same test case using pytz

def test_dst_pytz(self):
    """
    Test DST crossover with zoneinfo
    """
    # 5:00 AM EST before EDST crossover
    tz = pytz.timezone("America/New_York")
    ts = tz.localize(datetime(2024, 3, 9, 5, 0, 0))

    # Next tick is after the EDST crossover. Closk move forward one hour,
    # but we would still expect the next cron iteration at 5:00 AM EDST.
    ts_after_dst = croniter("0 5 * * *", ts).get_next(datetime)
    self.assertEqual(ts_after_dst, tz.localize(datetime(2024, 3, 10, 5, 0, 0)))

This test passes.

@cuu508
Copy link
Contributor Author

cuu508 commented Oct 31, 2024

@evanpurkhiser have you looked into using redacted? It is designed to use zoneinfo, and handles DST.

@kiorky
Copy link
Owner

kiorky commented Oct 31, 2024

@cuu508 chiming in grabbing users to another library is not something i ll tolerate on this tracker related to croniter issues.

You have been warned.

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