Skip to content

refactor: replace QDateTime/QDate/QSysInfo/QLocale with std::chrono - #8937

Merged
timosachsenberg merged 5 commits into
developfrom
remove-qt/pr2-datetime
Mar 19, 2026
Merged

timosachsenberg merged 5 commits into
developfrom
remove-qt/pr2-datetime

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Mar 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • DateTime and Date classes rewritten from unique_ptr<QDateTime/QDate> pimpl to plain struct
  • All parsing uses sscanf, formatting uses snprintf — locale-independent
  • BuildInfo.h uses platform-specific APIs (RtlGetVersion, sysctlbyname, /etc/os-release)
  • DimMapper uses custom formatWithGroupSeparators (locale-independent via std::to_chars)
  • TOPPBase direct QDateTime calls replaced with DateTime::now().get()
  • Part 2/7 of removing Qt6::Core from libOpenMS core library

Test plan

  • DateTime_test passes (all 8 parse formats, 7 toString formats)
  • Date_test passes
  • DimMapper_test passes

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor

    • Replaced Qt-based date/time internals with a lightweight native implementation; improves parsing, validation, supported input/output formats, and current-time retrieval used in logs.
    • Replaced legacy OS/version detection with a more accurate, platform-aware approach.
    • Streamlined numeric formatting for dimension displays for consistent grouping and precision.
  • Tests

    • Updated unit tests to match the new date handling implementation.

timosachsenberg and others added 2 commits March 18, 2026 13:27
…nd platform APIs

Remove Qt dependencies from DateTime, Date, BuildInfo, DimMapper, and
TOPPBase. DateTime and Date now use plain struct Fields with
sscanf/snprintf for parsing and formatting instead of QDateTime/QDate
via unique_ptr PImpl. BuildInfo uses platform APIs (RtlGetVersion,
sysctlbyname, /etc/os-release) instead of QSysInfo. DimMapper uses a
custom snprintf-based formatter with comma group separators instead of
QLocale. TOPPBase uses DateTime::now().get() instead of
QDateTime::currentDateTime().

All DateTime_test and Date_test cases pass unchanged (except removing
the QDate constructor test from Date_test since that constructor was
removed).

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
- Guard toString() against invalid DateTime (return empty string)
- Normalize millisecond parsing (sscanf %d ignores width, so ".4" was
  read as 4 instead of 400; now count fractional digits and scale)
- Handle ISO datetime with milliseconds but no timezone in set()
  (e.g. "2011-08-05T15:32:07.468" was falling to the plain ISO branch)
- Replace locale-dependent snprintf with std::to_chars in DimMapper
  formatWithGroupSeparators to avoid decimal comma on non-C locales

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Mar 18, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Replaces Qt-based Date/DateTime storage and formatting with lightweight internal Fields structs, defaulted special members, custom parsing/validation, and std::chrono-based now/nowUTC; adds platform-aware OS version helper, removes several Qt locale/time dependencies, and updates related logging, formatting, and tests.

Changes

Cohort / File(s) Summary
Date header
src/openms/include/OpenMS/DATASTRUCTURES/Date.h
Replaced std::unique_ptr<QDate> date_ with struct Fields { int year, month, day; bool valid; } fields_;. Defaulted copy/move constructors, assignments, and destructor. Removed Date(const QDate&) and Qt includes.
Date implementation
src/openms/source/DATASTRUCTURES/Date.cpp
Removed Qt usage; added isValidDate_, multi-format parsing (dd.MM.yyyy, MM/dd/yyyy, yyyy-MM-dd), chrono-based today(), string formatting, comparisons, and clear/get/set operating on fields_.
DateTime header
src/openms/include/OpenMS/DATASTRUCTURES/DateTime.h
Removed std::unique_ptr<QDateTime> dt_;. Added Fields { year, month, day, hour, minute, second, millisecond, valid } fields_;. Defaulted special members and destructor.
DateTime implementation
src/openms/source/DATASTRUCTURES/DateTime.cpp
Eliminated QDateTime dependency; added parsing for many formats (ISO, ms, timezone, month abbrev), validation helpers, chrono-based now/nowUTC, arithmetic helpers, fromString(), field-based formatting/getters, and updated relational ops and clear/set.
OS version / BuildInfo
src/openms/include/OpenMS/SYSTEM/BuildInfo.h
Added OpenMS::Internal::getOSVersionString_() with platform-specific implementations (Windows/macOS/Unix), replaced QSysInfo usage for OS/version, and changed architecture detection to pointer-size check; added platform headers.
Formatting replacement
src/openms/source/KERNEL/DimMapper.cpp
Removed QLocale::c().toString usage; added internal formatWithGroupSeparators(double,int) to format doubles with fixed precision and thousands separators using standard library utilities.
Application logging change
src/openms/source/APPLICATIONS/TOPPBase.cpp
Replaced QDateTime::currentDateTime().toString(...) calls with DateTime::now().get() and added DateTime include for logging output.
Tests updated
src/tests/class_tests/openms/source/Date_test.cpp
Removed QDate-based test; replaced with constructing a Date via set(12, 24, 1999) and updated test label to reflect new construction path.

Suggested reviewers

  • jpfeuffer
  • cbielow

Poem

🐰
I swapped out Qt for fields so neat,
Chrono and parsers tap their feet.
No hidden pointers in my burrow,
Dates hop light — precise and thorough.
A tiny rabbit clap and beat!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.92% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main objective of the pull request: replacing Qt components (QDateTime, QDate, QSysInfo, QLocale) with std::chrono and standard library alternatives across multiple files.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch remove-qt/pr2-datetime
📝 Coding Plan
  • Generate coding plan for human review comments

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 (1)
src/openms/source/DATASTRUCTURES/DateTime.cpp (1)

188-345: Complex but necessary parsing logic.

Static analysis flagged this method as complex (188-346), which is accurate given the many date formats supported. The parsing handles:

  • German, US, ISO formats
  • ISO with/without milliseconds
  • ISO with timezone suffixes (stripped)
  • Legacy protXML formats

The millisecond normalization logic (lines 224-232, 249-257) is duplicated. Consider extracting to a helper:

♻️ Optional: Extract millisecond normalization
// Add helper function near other helpers:
static int normalizeMilliseconds_(int millisecond, size_t frac_digits)
{
  for (size_t i = frac_digits; i < 3; ++i) millisecond *= 10;
  return millisecond % 1000;
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/openms/source/DATASTRUCTURES/DateTime.cpp` around lines 188 - 345, The
DateTime::set method contains duplicated millisecond-normalization logic in the
ISO-with-timezone branch and the ISO-no-timezone branch; extract that logic into
a new static helper (e.g., normalizeMilliseconds_(int millisecond, size_t
frac_digits)) placed near other helpers (same translation unit), implement the
normalization there (multiply until 3 digits then modulo 1000) and replace the
duplicated loops in DateTime::set with calls to normalizeMilliseconds_, updating
the code paths that compute frac_digits (keep computing frac_digits via
find('.') and digit scan) and then assign fields_.millisecond from the helper
result before setting fields_.valid.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/openms/source/DATASTRUCTURES/DateTime.cpp`:
- Around line 188-345: The DateTime::set method contains duplicated
millisecond-normalization logic in the ISO-with-timezone branch and the
ISO-no-timezone branch; extract that logic into a new static helper (e.g.,
normalizeMilliseconds_(int millisecond, size_t frac_digits)) placed near other
helpers (same translation unit), implement the normalization there (multiply
until 3 digits then modulo 1000) and replace the duplicated loops in
DateTime::set with calls to normalizeMilliseconds_, updating the code paths that
compute frac_digits (keep computing frac_digits via find('.') and digit scan)
and then assign fields_.millisecond from the helper result before setting
fields_.valid.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3a8684d4-d32c-45b1-a1b0-733ffda52108

📥 Commits

Reviewing files that changed from the base of the PR and between 0bcae36 and b11acb5.

📒 Files selected for processing (8)
  • src/openms/include/OpenMS/DATASTRUCTURES/Date.h
  • src/openms/include/OpenMS/DATASTRUCTURES/DateTime.h
  • src/openms/include/OpenMS/SYSTEM/BuildInfo.h
  • src/openms/source/APPLICATIONS/TOPPBase.cpp
  • src/openms/source/DATASTRUCTURES/Date.cpp
  • src/openms/source/DATASTRUCTURES/DateTime.cpp
  • src/openms/source/KERNEL/DimMapper.cpp
  • src/tests/class_tests/openms/source/Date_test.cpp

Clang reports ambiguity between String and std::string operator+
when mixing const char* with std::string. Explicit std::string cast.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

@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

🧹 Nitpick comments (2)
src/openms/source/KERNEL/DimMapper.cpp (2)

14-15: Consider removing unused includes.

<cstdio> and <cstring> don't appear to be used in this file after the refactor. If they were previously needed for Qt interop and are now dead, consider removing them.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/openms/source/KERNEL/DimMapper.cpp` around lines 14 - 15, Remove the
unused C headers from DimMapper.cpp: delete the `#include` <cstdio> and `#include`
<cstring> lines (they appear unused after the refactor in
src/openms/source/KERNEL/DimMapper.cpp); after removing them, rebuild to ensure
no missing symbols and, if the compiler complains, re-add only the specific
header(s) actually required by functions referenced in this file.

58-58: Use Size or SignedSize instead of (int) cast for .size().

Per coding guidelines, STL .size() values should use Size/SignedSize types rather than raw int.

♻️ Proposed fix
-      int len = (int)integer_part.size();
+      SignedSize len = static_cast<SignedSize>(integer_part.size());

Note: You'll also need to adjust the loop variable i on line 65 accordingly, or use Size (unsigned) if negative indices aren't needed.

As per coding guidelines: "use Size/SignedSize for STL .size() values in C++"

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/openms/source/KERNEL/DimMapper.cpp` at line 58, Change the type of len
from int to the appropriate OpenMS size type (Size or SignedSize) when assigning
from integer_part.size(), i.e. replace the cast "(int)integer_part.size()" with
a Size/SignedSize variable; also update the loop index variable used later (the
loop using i around the code referencing len) to match the chosen signedness
(use SignedSize if the loop uses negative values or subtraction, otherwise use
Size) so types are consistent with integer_part.size().
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/openms/source/KERNEL/DimMapper.cpp`:
- Around line 36-39: The call to std::to_chars stores an error code in ec but
never checks it; validate ec after std::to_chars (check ec != std::errc() or ec
== std::errc::value_too_large) and handle failures before using ptr or
constructing result. On error, provide a safe fallback (e.g., format with
snprintf/ostringstream, or set a sentinel string like "nan"/"inf" or log/throw),
using the same variables (buf, ptr, ec, result) so you don't build result from
an indeterminate buffer.

---

Nitpick comments:
In `@src/openms/source/KERNEL/DimMapper.cpp`:
- Around line 14-15: Remove the unused C headers from DimMapper.cpp: delete the
`#include` <cstdio> and `#include` <cstring> lines (they appear unused after the
refactor in src/openms/source/KERNEL/DimMapper.cpp); after removing them,
rebuild to ensure no missing symbols and, if the compiler complains, re-add only
the specific header(s) actually required by functions referenced in this file.
- Line 58: Change the type of len from int to the appropriate OpenMS size type
(Size or SignedSize) when assigning from integer_part.size(), i.e. replace the
cast "(int)integer_part.size()" with a Size/SignedSize variable; also update the
loop index variable used later (the loop using i around the code referencing
len) to match the chosen signedness (use SignedSize if the loop uses negative
values or subtraction, otherwise use Size) so types are consistent with
integer_part.size().

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: fadc9dd4-dc40-4824-ab1d-26bcf7f76f8e

📥 Commits

Reviewing files that changed from the base of the PR and between b11acb5 and 9734fb8.

📒 Files selected for processing (1)
  • src/openms/source/KERNEL/DimMapper.cpp

Comment thread src/openms/source/KERNEL/DimMapper.cpp Resolved
Wrap formatWithGroupSeparators() return value in String() to avoid
Clang ambiguity between OpenMS::String and std::string operator+.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

@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 (3)
src/openms/source/KERNEL/DimMapper.cpp (3)

63-63: Single-line if statement should use braces.

As per coding guidelines, use braces even for single-line blocks in C++.

♻️ Proposed fix
-        if (first_group == 0) first_group = 3;
+        if (first_group == 0)
+        {
+          first_group = 3;
+        }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/openms/source/KERNEL/DimMapper.cpp` at line 63, Replace the single-line
if statement that sets first_group with a braced block: locate the statement "if
(first_group == 0) first_group = 3;" in DimMapper.cpp and rewrite it to use
braces around the assignment (i.e., if (first_group == 0) { first_group = 3; })
so it follows the project's C++ coding guideline for using braces even for
single-line blocks.

14-15: Unused includes.

<cstdio> and <cstring> are included but not used in the current implementation. If these were intended for fallback error handling (as suggested in past reviews), they can be removed if not implementing that path, or kept if you plan to add the error handling.

♻️ Proposed cleanup
 `#include` <charconv>
-#include <cstdio>
-#include <cstring>
 `#include` <string>
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/openms/source/KERNEL/DimMapper.cpp` around lines 14 - 15, The includes
<cstdio> and <cstring> in DimMapper.cpp are unused; remove these two headers
from the top of src/openms/source/KERNEL/DimMapper.cpp (leave any other existing
includes) or reintroduce them only if you will add fallback error handling that
requires C stdio/string functions; specifically update the include block in the
DimMapper.cpp file so only the actually used headers remain (remove the lines
with `#include` <cstdio> and `#include` <cstring>).

58-58: Consider using SignedSize for .size() result.

Per coding guidelines, prefer Size/SignedSize for STL .size() values. While int works fine here given the bounded string length, using SignedSize would be more consistent with the codebase style.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/openms/source/KERNEL/DimMapper.cpp` at line 58, Replace the use of a
plain int for the length with the project's SignedSize type: change the
declaration "int len = (int)integer_part.size();" to use SignedSize (e.g.
"SignedSize len = static_cast<SignedSize>(integer_part.size());") so the
variable type matches the codebase convention for .size() results; locate this
change in DimMapper.cpp where the integer_part and len variables are used.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/openms/source/KERNEL/DimMapper.cpp`:
- Line 63: Replace the single-line if statement that sets first_group with a
braced block: locate the statement "if (first_group == 0) first_group = 3;" in
DimMapper.cpp and rewrite it to use braces around the assignment (i.e., if
(first_group == 0) { first_group = 3; }) so it follows the project's C++ coding
guideline for using braces even for single-line blocks.
- Around line 14-15: The includes <cstdio> and <cstring> in DimMapper.cpp are
unused; remove these two headers from the top of
src/openms/source/KERNEL/DimMapper.cpp (leave any other existing includes) or
reintroduce them only if you will add fallback error handling that requires C
stdio/string functions; specifically update the include block in the
DimMapper.cpp file so only the actually used headers remain (remove the lines
with `#include` <cstdio> and `#include` <cstring>).
- Line 58: Replace the use of a plain int for the length with the project's
SignedSize type: change the declaration "int len = (int)integer_part.size();" to
use SignedSize (e.g. "SignedSize len =
static_cast<SignedSize>(integer_part.size());") so the variable type matches the
codebase convention for .size() results; locate this change in DimMapper.cpp
where the integer_part and len variables are used.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2fa6c472-d7e2-4171-ba82-2a6ef167e5b9

📥 Commits

Reviewing files that changed from the base of the PR and between 9734fb8 and c81b98e.

📒 Files selected for processing (1)
  • src/openms/source/KERNEL/DimMapper.cpp

timosachsenberg pushed a commit to enetz/OpenMS that referenced this pull request Mar 18, 2026
Replace QLocale::c().toString with std::to_chars-based formatting that
matches Qt behavior: NaN returns "nan", Inf returns "inf"/"-inf".
Check std::to_chars error code to avoid UB on buffer overflow, and
use a 512-byte buffer sufficient for any fixed-format double.

Addresses CodeRabbit review concern on PR OpenMS#8937.

https://claude.ai/code/session_015odPaUy23pSDYFufRXv4Rr
timosachsenberg added a commit that referenced this pull request Mar 18, 2026
…rs (#8947)

Replace QLocale::c().toString with std::to_chars-based formatting that
matches Qt behavior: NaN returns "nan", Inf returns "inf"/"-inf".
Check std::to_chars error code to avoid UB on buffer overflow, and
use a 512-byte buffer sufficient for any fixed-format double.

Addresses CodeRabbit review concern on PR #8937.

https://claude.ai/code/session_015odPaUy23pSDYFufRXv4Rr

Co-authored-by: Claude <[email protected]>
@timosachsenberg
timosachsenberg merged commit a064988 into develop Mar 19, 2026
40 of 41 checks passed
@timosachsenberg
timosachsenberg deleted the remove-qt/pr2-datetime branch March 19, 2026 07:32
github-actions Bot added a commit that referenced this pull request Mar 20, 2026
Add changelog entries for three Qt-removal refactors merged since
the last sync (2026-03-19):

- #8937: QDateTime/QDate/QSysInfo/QLocale replaced with std::chrono
  (BREAKING: QDate constructor removed from Date class)
- #8938: QDir/QFile/QFileInfo replaced with std::filesystem
  (BREAKING: copyDirRecursively/removeDir signatures, ToolHandler return type)
- #8939: QProcess/QObject replaced with boost::process
  (BREAKING: ExternalProcess/TOPPBase/RWrapper APIs; boost-process added)

Co-authored-by: Copilot <[email protected]>
github-actions Bot pushed a commit that referenced this pull request Mar 20, 2026
Document the incremental Qt removal from libOpenMS core library:
- QDateTime/QDate/QSysInfo/QLocale replaced by std::chrono (#8937)
- QDir/QFile/QFileInfo replaced by std::filesystem (#8938)
- QProcess/QObject replaced by boost::process (#8939)
- QJsonDocument/QJsonObject replaced by nlohmann/json (#8936)

These changes landed after the 2026-03-19 changelog sync and represent
significant steps toward making Qt6 optional for the core library.

Co-authored-by: Copilot <[email protected]>
timosachsenberg pushed a commit that referenced this pull request Mar 20, 2026
Add changelog entries for three Qt-removal refactors merged since
the last sync (2026-03-19):

- #8937: QDateTime/QDate/QSysInfo/QLocale replaced with std::chrono
  (BREAKING: QDate constructor removed from Date class)
- #8938: QDir/QFile/QFileInfo replaced with std::filesystem
  (BREAKING: copyDirRecursively/removeDir signatures, ToolHandler return type)
- #8939: QProcess/QObject replaced with boost::process
  (BREAKING: ExternalProcess/TOPPBase/RWrapper APIs; boost-process added)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Copilot <[email protected]>
timosachsenberg added a commit that referenced this pull request Mar 20, 2026
Document the incremental Qt removal from libOpenMS core library:
- QDateTime/QDate/QSysInfo/QLocale replaced by std::chrono (#8937)
- QDir/QFile/QFileInfo replaced by std::filesystem (#8938)
- QProcess/QObject replaced by boost::process (#8939)
- QJsonDocument/QJsonObject replaced by nlohmann/json (#8936)

These changes landed after the 2026-03-19 changelog sync and represent
significant steps toward making Qt6 optional for the core library.

Co-authored-by: GitHub Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Timo Sachsenberg <[email protected]>
github-actions Bot pushed a commit that referenced this pull request Mar 24, 2026
After the Qt removal refactoring (#8937-#8940, #8965), Qt6::Core is no
longer a dependency of libOpenMS itself. Update AGENTS.md to reflect
that Qt6 is required only for TOPP tools and GUI (openms_gui) builds,
and is optional when building only the core library or pyOpenMS.

Co-authored-by: Copilot <[email protected]>
timosachsenberg pushed a commit that referenced this pull request Mar 24, 2026
…8977)

After the Qt removal refactoring (#8937-#8940, #8965), Qt6::Core is no
longer a dependency of libOpenMS itself. Update AGENTS.md to reflect
that Qt6 is required only for TOPP tools and GUI (openms_gui) builds,
and is optional when building only the core library or pyOpenMS.

Co-authored-by: GitHub Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
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