Skip to content

[TEST] DateTime: pin locale- and timezone-independent parsing/formatting (#9460) - #9533

Merged
timosachsenberg merged 2 commits into
OpenMS:developfrom
timosachsenberg:test/9460-datetime-locale-tz
Jun 17, 2026
Merged

timosachsenberg merged 2 commits into
OpenMS:developfrom
timosachsenberg:test/9460-datetime-locale-tz

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

What

Adds a DateTime_test section that runs a battery of parse/format checks — ISO T, dd.mm.yyyy, millisecond + timezone-offset stripping (2011-08-05T15:32:07.468+02:00 → 2011-08-05 15:32:07), asctime-style month names (Wed Dec 14 11:59:58 2006), and fromString → toString — and asserts the output is byte-identical under:

  • multiple TZ values (UTC, America/New_York, Asia/Kolkata, Pacific/Chatham, Etc/GMT-14);
  • multiple C locales (C, POSIX, de_DE, tr_TR), each guarded by setlocale() success so the section still passes on minimal images that lack de_DE/tr_TR.

now() is excluded (it legitimately returns local wall-clock time). The TZ/locale process state is saved and restored; the varying block is #ifndef OPENMS_WINDOWSPLATFORM (POSIX setenv/tzset).

Why

Closes the §1 (Qt removal: QDate/QDateTime → std::chrono) [AUTO] task in the OpenMS 3.6.0 pre-release testing plan (#9460):

Wrap key DateTime_test/Date_test asserts in a harness that sets setlocale(de_DE/tr_TR) and TZ=UTC vs America/New_York. Pass: get()/parse output is byte-identical across all locale/TZ settings (tr_TR catches the dotted-i bug). Guard locale names by platform.

DateTime documents itself as naive/offset-stripping, but no test varied locale or TZ. I confirmed by reading the implementation that the parse/format path uses only locale-independent primitives — sscanf("%d", …) for numbers, strncmp for month abbreviations, timegm/gmtime for arithmetic — and that localtime appears only in now(). So the invariance is a real, intended contract; this pins it.

Test plan

Tests only — no production code changed. Verified locally: -fsyntax-only clean, full build green, test runs PASSED. The TZ axis is exercised end-to-end locally (tzdata present); the de_DE/tr_TR cases run where those locales are installed (guarded-skipped otherwise). No bug surfaced — DateTime is confirmed TZ-independent.

Scoped to DateTime_test (the class with the TZ-offset / millisecond / month-name surface); the analogous Date_test harness can follow.

Part of #9460. Follows #9524, #9525, #9526, #9528, #9530, #9531, #9532.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Added an additional invariant test to verify byte-identical DateTime parsing and formatting across different timezones and C locale settings.
    • The test exercises multiple input formats and validates roundtrip behavior, while skipping unsupported locales and avoiding Windows where applicable.

…ing (OpenMS#9460)

DateTime is naive (offset-stripping) and built on sscanf("%d",...) integer
parsing, strncmp month matching, and timegm/gmtime (UTC) -- never localtime or
locale-sensitive number/string functions -- so set()/get()/toString()/fromString()
must be byte-identical regardless of the C locale and the TZ environment variable.
The existing sections never vary either.

Adds an [EXTRA] section running a battery of parse/format checks (ISO, dd.mm.yyyy,
millisecond + timezone-offset stripping, asctime-style month names, fromString ->
toString) under:
- multiple TZ values (UTC, America/New_York, Asia/Kolkata, Pacific/Chatham, Etc/GMT-14)
- multiple C locales (C, POSIX, de_DE, tr_TR) -- guarded by setlocale() success, so
  the section still passes on minimal images lacking de_DE/tr_TR

now() is excluded (it legitimately returns local wall-clock time). The TZ/locale
state is saved and restored. Non-Windows-guarded (POSIX setenv/tzset).

Verified: builds clean and the test runs PASSED (TZ axis exercised locally; locale
cases run where the locales exist).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

@timosachsenberg The following names might be missing from the AUTHORS file:

  • Timo Sachsenberg

Please consider applying the following patch:

--- AUTHORS	2026-06-15 15:58:01.363222348 +0000
+++ AUTHORS.new	2026-06-15 15:58:06.644211611 +0000
@@ -23,8 +23,8 @@
  - Chirag Dave
  - Chris Bauer
  - Chris Bielow
- - Christie Mathews
  - Christian Ehrlich
+ - Christie Mathews
  - Clemens Groepl
  - Cornelia Friedle
  - Daniel Jameson

@coderabbitai

coderabbitai Bot commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a6b38dca-18e3-4a38-a1d4-40b8374bf2cc

📥 Commits

Reviewing files that changed from the base of the PR and between 32c9a9d and a6041ec.

📒 Files selected for processing (1)
  • src/tests/class_tests/openms/source/DateTime_test.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/tests/class_tests/openms/source/DateTime_test.cpp

📝 Walkthrough

Walkthrough

Adds three C standard headers (<clocale>, <cstdlib>, <ctime>) and a new START_SECTION block to DateTime_test.cpp. The section verifies that DateTime parsing and formatting produce byte-identical results across multiple TZ environment values (non-Windows only, with save/restore) and multiple C locales (skipping unavailable ones).

Changes

DateTime locale/timezone invariant test

Layer / File(s) Summary
Headers and locale/timezone invariant test section
src/tests/class_tests/openms/source/DateTime_test.cpp
Adds <clocale>, <cstdlib>, <ctime> includes and a new test section that uses a shared invariant-check lambda to assert byte-identical DateTime parsing/formatting output under multiple TZ values (POSIX-only, with environment save/restore) and multiple C locales (guarded by setlocale availability checks).

Possibly related PRs

  • OpenMS/OpenMS#8937: The new test section directly validates the locale- and timezone-independent DateTime parsing/formatting behavior introduced by the refactor in this PR.

Poem

🐇 Hoppity-hop through timezones we go,
Locales and TZ values all in a row,
Parse it and format it, byte-for-byte the same,
No matter the region or calendar game.
The clock stays true wherever I roam—
This rabbit tests thoroughly, then hops back home! 🕐

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title directly and specifically describes the main change: adding a test to ensure DateTime parsing/formatting is locale and timezone-independent, which aligns with the substantial test additions in the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/tests/class_tests/openms/source/DateTime_test.cpp`:
- Around line 366-396: The `#endif` closing the `#ifndef OPENMS_WINDOWSPLATFORM`
guard is currently placed after the locale loop, preventing Windows from running
locale tests. However, only the timezone manipulation code (using POSIX-specific
setenv, unsetenv, and tzset functions) needs the platform guard; the locale loop
using standard C setlocale can run on Windows. Move the `#endif` to immediately
after the tzset() call that restores the timezone (after the code that restores
the TZ environment variable), leaving the locale loop (the for loop iterating
over {"C", "POSIX", "de_DE.UTF-8", "tr_TR.UTF-8", "de_DE.utf8", "tr_TR.utf8"})
and its accompanying locale restoration code outside the platform guard so
Windows can exercise locale variations.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d682fc33-729e-4b33-9e41-47d54ad733fd

📥 Commits

Reviewing files that changed from the base of the PR and between aacd941 and 32c9a9d.

📒 Files selected for processing (1)
  • src/tests/class_tests/openms/source/DateTime_test.cpp

Only the timezone manipulation (POSIX setenv/unsetenv/tzset) needs the
OPENMS_WINDOWSPLATFORM guard. The C-locale loop uses standard setlocale, which
is available on Windows, so move the #endif to right after the TZ-restore
tzset() and leave the locale loop unguarded. Unavailable locales are still
skipped individually, so the section continues to pass on minimal images.
@timosachsenberg
timosachsenberg merged commit 73cc92e into OpenMS:develop Jun 17, 2026
38 checks passed
@timosachsenberg timosachsenberg mentioned this pull request Jun 17, 2026
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.

1 participant