Repository navigation
Fix timezoneOffset losing the whole-day component of the UTC offset - #115332
Conversation
timezoneOffset did not read the offset, it reconstructed it from the
distance between two start-of-day timestamps:
res = (lut[index].date - lut[epoch].date) % 86400;
res = res > 43200 ? (86400 - res) : (0 - res);
return res + offset_at_start_of_epoch;
lut[i].date is the UTC instant of local midnight of day i, so the
difference of two such instants is days * 86400 - (offset_now -
offset_epoch). Taking it modulo 86400 keeps only the sub-day part of the
offset change since the epoch and discards any whole-day part, which the
added offset_at_start_of_epoch cannot restore. The zones that
permanently shifted their offset by 24 hours when they crossed the
international date line therefore stayed pinned at their pre-jump
offset, which is why each of them reported correctly before its jump and
wrongly after it.
The wrap on the second line also handles only one sign. In C++ the
remainder takes the sign of the dividend, so for a day before the epoch
res is negative, the res > 43200 test can never fire, and 0 - res yields
a value near +86400 rather than a small negative offset. That is a
second, independent defect affecting most zones at pre-1970 instants,
not just the seven date-line ones from the report.
Compute the offset directly instead. The UTC offset at local midnight of
a day is day_number * 86400 - lut[index].date, since local midnight is
that many seconds of local time from the epoch while date is the UTC
instant of the same midnight. This is exact for either sign and any
magnitude, needs no modulo and no wrap branches. The existing correction
for an offset change later in the same day is kept as it was, and
offset_at_start_of_epoch is no longer added here because the new base
term is absolute rather than epoch-relative. The member itself stays, it
still has other users.
Measured over all 597 rows of system.time_zones at 14 instants spanning
1900 to 2300, against Python zoneinfo as an independent oracle, wrong
samples drop from 500 across 307 zones to 18, and each of those 18 is a
tzdata version difference between the bundled 2025a and the system
2026a. Every one of the 488 samples this changes differs by exactly one
day, so nothing sub-day moved and no previously correct sample
regressed.
The same offset feeds parseDateTime and its OrNull, OrZero, 64 and Joda
variants, a zone named inside a Joda format string,
EXTRACT(TIMEZONE_HOUR / TIMEZONE_MINUTE ...), the %z specifier of
formatDateTime, and toUTCTimestamp / fromUTCTimestamp, all of which were
wrong by a day on the affected zones and are fixed here. The remaining
consumers reduce the offset modulo a day, so an exact one-day error
already cancelled for them; they were correct before and remain so, and
the test pins them as controls.
Reported by PedroTadim.
Closes ClickHouse#115281.
Internal second-model review (1 finding fixed, 3 declined with evidence)Before publishing I reviewed the resulting code cold, then ran an independent second-model review of the full diff, then adjudicated both sets against the recorded validation. No source file changed during review.
1 (fixed). The real split of the 12 call sites is seven wrong and five that reduce the offset modulo a day. The recorded per-site A/B probe agreed with that; only the description prose was wrong. Corrected, and "consumers" became "call sites" so the 12 has one unambiguous unit (seven sites, but six user-facing functions). 2 (declined). The dependency is real but the reference is invariant across the whole randomization list by construction, not by luck: every zone that setting can take here has a fixed offset across 2025-06-14..16, so the 14-hour shift lands on the same wall-clock text in all of them. The 50-run randomized pass confirms it. 3 (declined). The four pre-1970 arms already fail on the base binary, so the class is covered and only its breadth is narrower. Extending the sweep below 1970 would pull in the 4 (declined). The rendered body already carries a live |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20260818-151000 |
|
Workflow [PR], commit [c35cc8b] Summary: ✅
AI ReviewSummaryThis PR fixes Final Verdict
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 5/5 (100.00%) · Uncovered code |
|
cc @yariks5s @alexey-milovidov, could you review this? |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units2667 translation units recompiled, 15378 s compile time in total, 2667 of them have a recent master baseline. Median compile-time ratio to the baselines is ×1.10 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
CI finish ledger - c35cc8bCI is fully finished on this head: 178 check-runs, none queued or in progress, No failures, so there is nothing to own. One note on the record so it is not misread later: CIDB holds a single The bugfix validation actually ran and passed rather than being skipped: Session id: cron:our-pr-ci-monitor:20260819-020000 |
|
📊 Cloud Performance Report
This PR is a correctness fix to timeZoneOffset in DateLUTImpl, adjusting how the whole-day UTC offset is computed for international-date-line and pre-epoch zones. The two flagged queries are TPC-H Q7 (+20.9%) and Q17 (+62.5%), both of which run in UTC where the changed offset path returns 0 unchanged, so neither can be affected by this diff. The deterministic gates already marked both as unstable baselines and left them as not_sure; the underlying measurements were noisy (especially Q17), so these deltas are baseline instability rather than a real regression. No action is needed on the perf numbers. clickbench🟢 No significant changes tpch_adapted_1_officialFlagged queries (2 of 22)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. Debug info
|
8290f87
|
Hi — this looks like a backport candidate for |
|
@yariks5s you merged this, so asking you: could you apply I verified the request rather than relaying it. All five branches named are active release branches, the fix is absent from each, and the bug reproduces on each published binary (
Two arms that are already correct before the fix stay identical on every branch ( One label is enough: The port applies cleanly. One caveat before the robot runs: the source fix ports correctly everywhere, but the test does not pass unmodified on four of the five. Test portability per branch, measured
The 26.6 difference is setting-driven, not fix-driven: master with the fix and Adaptations, if you want the test on the older branches: replace the If you would rather keep it narrow, |
…d file, test from 1900 On this branch `DateLUT` loads zones that are not embedded (`libc:` names, the host database), so the ORC reader and writer threw `LOGICAL_ERROR` for them. `DateTime64` starts at 1900 here, so the test uses values between 1900 and the first transition, and checks the day shift fixed by #115332. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d file, test from 1900 On this branch `DateLUT` loads zones that are not embedded (`libc:` names, the host database), so the ORC reader and writer threw `LOGICAL_ERROR` for them. `DateTime64` starts at 1900 here, so the test uses values between 1900 and the first transition, and checks the day shift fixed by #115332. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
timezoneOffset(aliastimeZoneOffset) returning an offset wrong by exactly one day for time zones whose UTC offset differs from their 1970-01-01 offset by a whole day, such asPacific/KiritimatiandPacific/Apiaafter they crossed the international date line, and for most zones before 1970. This also fixesparseDateTime,parseDateTimeOrNull,parseDateTime64,parseDateTimeInJodaSyntax,EXTRACT(TIMEZONE_HOUR / TIMEZONE_MINUTE ...),formatDateTime's%z,toUTCTimestampandfromUTCTimestamp, which consume that offset. Closes #115281.Description
Reported by @ PedroTadim in #115281 (comment).
timezoneOffsetdid not read the offset, it reconstructed it as(lut[index].date - lut[epoch].date) % 86400plusoffset_at_start_of_epoch. That difference isdays * 86400 - (offset_now - offset_epoch), so the modulo keeps only the sub-day part of the change since the epoch and discards any whole-day part; the date-line zones stayed pinned at their pre-jump offset, correct before the jump and wrong after. Separately,%takes the sign of the dividend, so on a pre-epoch day the remainder is negative, theres > 43200wrap never fired, and the result came out near+86400instead of a small negative offset.The fix computes the offset directly as
day_number * 86400 - lut[index].date: local midnight is that many seconds of local time from the epoch, anddateis the UTC instant of the same midnight. Exact for either sign, no modulo, no wrap branches. The same-dayamount_of_offset_changecorrection is unchanged.All 12 in-tree call sites checked. Seven were wrong and are repaired by this one change: the function itself, the
parseDateTimefamily (including a zone named in the format string),EXTRACT(TIMEZONE_HOUR / TIMEZONE_MINUTE ...),formatDateTime's%z, andtoUTCTimestamp/fromUTCTimestamp. The other five reduce the offset modulo a day (CAST ... AS Time/Time64,localtime), so an exact one-day error already cancelled; the test pins those as controls.Over all 597 rows of
system.time_zonesat 14 instants from 1900 to 2300, against Pythonzoneinfoas an independent oracle: 500 wrong samples across 307 zones before, 18 after, all 18 beingtzdatadifferences between the bundled 2025a and the system 2026a. All 488 changed samples differ by exactly one day, so nothing sub-day moved.Validation
Both directions through
tests/clickhouse-test: on the base master debug snapshot (build id09e3d57a4bbe30cd)01252_weird_time_zonefails with a 39-line reference diff; with the fix (build id485b33ed0bf6e99c) it passes, including 50 of 50 randomized runs.unit_tests_dbms --gtest_filter='*DateLUT*:*DateTime*:*Date*'passes 7906 tests, so no calendar component moved. Thetimezonestateless suite passes 42 of 42. Six failures in the widerdatetimeandextractsuites are pre-existing gaps in my local environment (noremote()cluster config, no parquet/iceberg fixtures, notest.hits) and reproduce identically on the base binary.New arms: the seven reported zones after their jump; the same zones before it and
Pacific/Chatham(+13:45) as controls that must not move; the pre-1970 class; agreement betweenparseDateTime*andtoDateTime; the other offset consumers; the modulo-a-day consumers as regression controls; DST transition days; agreement between the in-range and out-of-range paths; and a sweep oversystem.time_zoneswith no zone list hardcoded, comparing the reported offset to rendering the instant as local text and reading it back as UTC.Workflow [PR]
Sync PR [sync-upstream/pr/115332]
Version info
26.8.1.1888(included in26.8and later)