Repository navigation
[TEST] DateTime: pin locale- and timezone-independent parsing/formatting (#9460) - #9533
Conversation
…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]>
|
@timosachsenberg The following names might be missing from the
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 |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds three C standard headers ( ChangesDateTime locale/timezone invariant test
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 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.
What
Adds a
DateTime_testsection that runs a battery of parse/format checks — ISOT,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), andfromString → toString— and asserts the output is byte-identical under:UTC,America/New_York,Asia/Kolkata,Pacific/Chatham,Etc/GMT-14);C,POSIX,de_DE,tr_TR), each guarded bysetlocale()success so the section still passes on minimal images that lackde_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(POSIXsetenv/tzset).Why
Closes the §1 (Qt removal:
QDate/QDateTime → std::chrono)[AUTO]task in the OpenMS 3.6.0 pre-release testing plan (#9460):DateTimedocuments 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,strncmpfor month abbreviations,timegm/gmtimefor arithmetic — and thatlocaltimeappears only innow(). So the invariance is a real, intended contract; this pins it.Test plan
Tests only — no production code changed. Verified locally:
-fsyntax-onlyclean, full build green, test runs PASSED. The TZ axis is exercised end-to-end locally (tzdata present); thede_DE/tr_TRcases run where those locales are installed (guarded-skipped otherwise). No bug surfaced —DateTimeis confirmed TZ-independent.Scoped to
DateTime_test(the class with the TZ-offset / millisecond / month-name surface); the analogousDate_testharness can follow.Part of #9460. Follows #9524, #9525, #9526, #9528, #9530, #9531, #9532.
🤖 Generated with Claude Code
Summary by CodeRabbit
DateTimeparsing and formatting across different timezones and C locale settings.