Skip to content

[TEST] Date: pin locale-independent date parsing/formatting (#9460) - #9537

Merged
timosachsenberg merged 1 commit into
OpenMS:developfrom
timosachsenberg:test/9460-date-locale
Jun 16, 2026
Merged

timosachsenberg merged 1 commit into
OpenMS:developfrom
timosachsenberg:test/9460-date-locale

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

What

Adds a Date_test section running German (dd.mm.yyyy), English (mm/dd/yyyy) and ISO (yyyy-mm-dd) parse + get() checks under 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.

Why

Completes the Date_test half of the §1 (Qt removal: QDate/QDateTime → std::chrono) [AUTO] task in the OpenMS 3.6.0 pre-release testing plan (#9460) — the DateTime_test half is #9533:

Wrap key DateTime_test/Date_test asserts in a harness that sets setlocale(de_DE/tr_TR) … Pass: get()/parse output is byte-identical across all locale settings (tr_TR catches the dotted-i bug).

I confirmed from the implementation that Date::set parses via sscanf("%d.%d.%d", …) and Date::get formats via snprintf("%04d-%02d-%02d", …) — locale-independent integer ops, no locale-sensitive number/string functions — so the invariance is a real, intended contract.

No TZ axis here: unlike DateTime, Date carries no time-of-day and set()/get() never touch localtime/mktime, so timezone is not applicable; today() (which does read local time) is excluded.

Test plan

Tests only — no production code changed. Verified locally: -fsyntax-only clean, full build green, test runs PASSED. Locally exercises the C/POSIX locales (de_DE/tr_TR guarded-skipped where not installed; they run on images that have them).

Part of #9460. Follows #9524, #9525, #9526, #9528, #9530, #9531, #9532, #9533, #9534, #9535, #9536.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Added test coverage for Date parsing and formatting to verify consistent behavior across different C locale configurations, strengthening reliability and quality assurance.

)

Companion to the DateTime locale/TZ guard. Date is naive and date-only:
set() parses via sscanf("%d.%d.%d", ...) and get() formats via
snprintf("%04d-%02d-%02d", ...) -- both locale-independent integer operations
with no locale-sensitive number/string functions -- so parsing and formatting
must be byte-identical across C locales (tr_TR dotted-i, de_DE decimal comma).

Adds an [EXTRA] section running the German/English/ISO parse + get() checks
under multiple C locales (C, POSIX, de_DE, tr_TR), guarded by setlocale()
success so it still passes on minimal images lacking those locales. No TZ axis
(Date carries no time-of-day; today() is excluded). Non-Windows-guarded.

Verified: builds clean and the test runs PASSED.

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 16:37:57.067412038 +0000
+++ AUTHORS.new	2026-06-15 16:38:02.577272060 +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

📝 Walkthrough

Walkthrough

A new test section is added to Date_test.cpp that verifies Date parsing and formatting produce consistent results regardless of the active C locale. The section includes <clocale> and <string> headers, saves the initial locale, runs assertions, then iterates over candidate locales and reruns the same assertions when each setlocale call succeeds. The section is skipped on Windows.

Changes

Date locale-invariance test

Layer / File(s) Summary
Locale-invariant Date parsing and formatting test
src/tests/class_tests/openms/source/Date_test.cpp
Adds <clocale> and <string> includes; introduces a START_SECTION that defines a reusable assertion lambda for multiple date string formats, executes it under the initial locale, then reruns it after each successful setlocale(LC_ALL, ...) across several candidate locales. Entire section is guarded against Windows with a preprocessor check.

Possibly related PRs

  • OpenMS/OpenMS#8937: This PR directly validates the locale-independent Date parsing and formatting introduced by removing Qt dependencies in PR #8937, where manual parsing and formatting were implemented.

Poem

A rabbit hops through locales with care,
French, German, UTF-8 — all checked with flair.
setlocale shifts, but Date holds its form,
Parsing and printing stay steady and warm.
🐇 No locale shall shake what's already right! 🗓️

🚥 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 title clearly summarizes the main change: adding a test to validate locale-independent date parsing and formatting, which directly corresponds to the changes in the raw summary.
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.

🧹 Nitpick comments (2)
src/tests/class_tests/openms/source/Date_test.cpp (2)

161-161: ⚡ Quick win

Rename lambda to follow lowerCamelCase convention.

The lambda check_invariant should be checkInvariant to comply with the method naming guideline. As per coding guidelines, method names (including callable objects like lambdas) should use lowerCamelCase, not snake_case.

♻️ Proposed fix
-  auto check_invariant = []()
+  auto checkInvariant = []()
   {

And update the calls:

-  check_invariant();
+  checkInvariant();

...

-      check_invariant();
+      checkInvariant();
🤖 Prompt for 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.

In `@src/tests/class_tests/openms/source/Date_test.cpp` at line 161, The lambda
function check_invariant uses snake_case naming convention, which violates the
coding guideline requiring lowerCamelCase for method and callable names. Rename
the lambda from check_invariant to checkInvariant, and update all calls to this
lambda throughout the test to use the new checkInvariant name.

Source: Coding guidelines


168-169: ⚡ Quick win

Follow the established TEST_EQUAL formatting pattern.

These TEST_EQUAL calls deviate from the file's existing style: the rest of the file uses one TEST_EQUAL per line with semicolons (see lines 54–56, 63–66, 97–99). Maintaining consistency improves readability.

♻️ Proposed fix
     d.set("01.12.1977");          // dd.mm.yyyy (German)
     d.get(mo, dy, yr);
-    TEST_EQUAL(mo, 12) TEST_EQUAL(dy, 1) TEST_EQUAL(yr, 1977)
-    TEST_EQUAL(d.get(), "1977-12-01")
+    TEST_EQUAL(mo, 12);
+    TEST_EQUAL(dy, 1);
+    TEST_EQUAL(yr, 1977);
+    TEST_EQUAL(d.get(), "1977-12-01");

     d.set("12/01/1977");          // mm/dd/yyyy (English)
-    TEST_EQUAL(d.get(), "1977-12-01")
+    TEST_EQUAL(d.get(), "1977-12-01");

     d.set("1967-12-23");          // ISO yyyy-mm-dd
-    TEST_EQUAL(d.get(), "1967-12-23")
+    TEST_EQUAL(d.get(), "1967-12-23");

Also applies to: 172-172, 175-175

🤖 Prompt for 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.

In `@src/tests/class_tests/openms/source/Date_test.cpp` around lines 168 - 169,
The TEST_EQUAL calls in the Date_test.cpp file are not following the established
formatting pattern used throughout the rest of the file. The current code has
multiple TEST_EQUAL statements on a single line without semicolons, while the
established pattern (as seen in lines 54-56, 63-66, and 97-99) places each
TEST_EQUAL call on its own line followed by a semicolon. Reformat all TEST_EQUAL
calls to place each one on a separate line with a semicolon, ensuring
consistency with the file's existing style.
🤖 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.

Nitpick comments:
In `@src/tests/class_tests/openms/source/Date_test.cpp`:
- Line 161: The lambda function check_invariant uses snake_case naming
convention, which violates the coding guideline requiring lowerCamelCase for
method and callable names. Rename the lambda from check_invariant to
checkInvariant, and update all calls to this lambda throughout the test to use
the new checkInvariant name.
- Around line 168-169: The TEST_EQUAL calls in the Date_test.cpp file are not
following the established formatting pattern used throughout the rest of the
file. The current code has multiple TEST_EQUAL statements on a single line
without semicolons, while the established pattern (as seen in lines 54-56,
63-66, and 97-99) places each TEST_EQUAL call on its own line followed by a
semicolon. Reformat all TEST_EQUAL calls to place each one on a separate line
with a semicolon, ensuring consistency with the file's existing style.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 47a8aa13-8709-4097-b265-d953a7efc0d6

📥 Commits

Reviewing files that changed from the base of the PR and between aacd941 and 7bc9ccd.

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

@timosachsenberg
timosachsenberg merged commit 58fd0e1 into OpenMS:develop Jun 16, 2026
41 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