Skip to content

fixed DST - #45

Merged
mariusbancila merged 2 commits into
masterfrom
fix/dst
Aug 11, 2026
Merged

fixed DST#45
mariusbancila merged 2 commits into
masterfrom
fix/dst

Conversation

@mariusbancila

Copy link
Copy Markdown
Owner

Changes:

include/croncpp.h:

  • tm_isdst = -1 is now set for every field before mktime, not just the date ones. Whatever field changes, the resulting time may fall on the other side of a transition, so the flag is never still known.
  • New detail::find_next_after, the single search entry point for both cron_next overloads. It rejects any candidate that is not strictly later than the input and retries a second on, bounded by
    CRON_MAX_DST_SHIFT. This makes "the result is always in the future" an invariant rather than a special case, and it removes the duplicated "if the answer equals the input, add a second and search again" logic from both overloads.
  • New detail::field_value, plus a guard in the bitset find_next: if a field does not hold the value just written, that local time does not exist and the search moves on to the next larger field.

README.md - a Time zones and daylight saving time section: croncpp works in local time, there is no UTC mode, TZ controls it, with a worked example of the spring gap and an explicit statement of what is and is not guaranteed at the autumn repeat.

test/test_dst.cpp - pins TZ=CST6CDT through an RAII helper. That name is understood both by the Windows CRT and by the zoneinfo database; the POSIX rule syntax used in the issue threads, such as CET-1CEST,M3.5.0,M10.5.0/3, is not portable to Windows. The first test case asserts the fixture really selected a zone with the expected transitions, so a platform that resolves the name differently fails with an obvious message instead of a confusing one.

Testing

  • New DST suite covering both transitions: the spring gap, the autumn repeat, a named regression test for Daylight savings issue #24, and dense sweeps asserting that cron_next is always strictly in the future and that the std::tm and std::time_t overloads agree.
  • Whole suite: 42,806 assertions in 41 test cases, 164 ms. Two sweep cases account for ~42,200 of those and carry comments explaining the arithmetic.
  • Built and run against C++11, C++14, C++17, C++20 and C++23, tests and benchmark, all green.

Fixes #34
Fixes #24

@mariusbancila
mariusbancila merged commit 6f3ca9d into master Aug 11, 2026
17 checks passed
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.

Time zones / daylight savings time? Daylight savings issue

1 participant