pcsx-redux icon indicating copy to clipboard operation
pcsx-redux copied to clipboard

Remove deprecated fmt::localtime API and update fmt to 12.0.0

Open njfox opened this issue 2 months ago โ€ข 3 comments

Fixes #1969

fmt::localtime was deprecated and finally removed in fmt 12, which was pushed to Arch Linux recently, and this caused build failures and runtime errors when linked against the system fmt library. This PR removes the deprecated function and replaces it with a new formatTimestamp() function in VersionInfo that formats the timestamp based on a format string argument passed by the caller.

Note that these changes are incompatible with fmt10, so we needed to update the submodule as well.

njfox avatar Oct 22 '25 16:10 njfox

Walkthrough

Centralized timestamp formatting by adding VersionInfo::formatTimestamp(format) which converts the stored timestamp to local time and returns a preformatted string; callers in the About dialog and main JSON output now call this method instead of using inline fmt::localtime. Unit tests added for the new formatter.

Changes

Cohort / File(s) Summary
Version formatting API
src/support/version.h, src/support/version.cc, tests/support/version.cc
Added VersionInfo::formatTimestamp(const std::string& format) const declaration and implementation; new unit tests verifying formatted output, empty format, non-placeholder behavior, and negative timestamps.
GUI timestamp refactoring
src/gui/gui.cc
Precompute timestamp via version.formatTimestamp("{:%Y-%m-%d %H:%M:%S}") and reuse for display and clipboard text; removed inline fmt::localtime usage.
Main version output refactoring
src/main/main.cc
Removed fmt/chrono.h include and replaced inline fmt::localtime formatting with version.formatTimestamp(...) for JSON output.
Third-party submodule
third_party/fmt
Updated submodule reference commit; no source API changes in this diff.

Sequence Diagram(s)

sequenceDiagram
    participant VersionInfo
    participant GUI as AboutDialog
    participant Main as main.cc
    participant Clipboard
    participant JSON

    Note over VersionInfo: new API: formatTimestamp(format)

    GUI->>VersionInfo: formatTimestamp("{:%Y-%m-%d %H:%M:%S}")
    VersionInfo-->>GUI: "2025-01-18 02:27:53"
    GUI->>Clipboard: copy(preformatted timestamp + other fields)
    GUI->>GUI: display(preformatted timestamp)

    Main->>VersionInfo: formatTimestamp("{:%Y-%m-%d %H:%M:%S}")
    VersionInfo-->>Main: "2025-01-18 02:27:53"
    Main->>JSON: insert(timestamp = preformatted string)

Estimated code review effort

๐ŸŽฏ 3 (Moderate) | โฑ๏ธ ~20 minutes

Suggested reviewers

  • nicolasnoble

Poem

๐Ÿฐ I hopped through time with a tiny reform,
One method to format kept output warm.
GUI and main now share the same chime,
Tests check the ticks, second by second in time.
Carrots for tidy code and no more fmt grime!

Pre-merge checks and finishing touches

โŒ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage โš ๏ธ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
โœ… Passed checks (4 passed)
Check name Status Explanation
Title Check โœ… Passed The PR title "Remove deprecated fmt::localtime API and update fmt to 12.0.0" directly and clearly summarizes the two main changes in the changeset: removing the deprecated fmt::localtime function calls and updating the fmt library version. The title is concise, specific, and a teammate scanning history would immediately understand the primary purpose of this change. The title accurately reflects both the core refactoring (deprecation removal) and the submodule update that are evident across all modified files.
Linked Issues Check โœ… Passed The PR successfully addresses all requirements from the linked issue #1969. The issue reports that fmt::localtime was removed in fmt 12.x, causing compilation failures, and expects pcsx-redux to compile with fmt 12.x. The PR removes all fmt::localtime usage from gui.cc and main.cc [#1969], introduces a new formatTimestamp() method in VersionInfo that uses std::localtime instead [#1969], updates the fmt submodule to version 12.0.0 [#1969], and adds comprehensive unit tests for the new formatting function. These changes directly resolve the build incompatibility reported in the issue.
Out of Scope Changes Check โœ… Passed All code changes are directly related to the objective of removing deprecated fmt::localtime API and updating fmt to 12.0.0. The changes to gui.cc and main.cc refactor timestamp formatting to remove fmt::localtime usage, version.cc and version.h implement the new formatTimestamp() replacement method, tests/support/version.cc provides necessary unit test coverage for the new functionality, and the fmt submodule update is required to resolve the build failure. No extraneous or unrelated changes are present in the changeset.
Description Check โœ… Passed The PR description is directly related to the changeset and provides clear context for the changes. It explains the motivation (fmt::localtime was removed in fmt 12.x causing build failures), the solution (new formatTimestamp() function in VersionInfo), the decision to update the fmt submodule, and notes the incompatibility with fmt10. The description is specific, contextual, and references the related issue #1969, making it clear what problem the PR solves and how it does so.
โœจ Finishing touches
๐Ÿงช Generate unit tests (beta)
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

๐Ÿ“œ Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

๐Ÿ“ฅ Commits

Reviewing files that changed from the base of the PR and between 5f47854bdfef61b3773e0248a626ef204e920a17 and 7b90c96de2b33c21ae1e48e5d89fa07297ff08ca.

๐Ÿ“’ Files selected for processing (1)
  • third_party/fmt (1 hunks)
โœ… Files skipped from review due to trivial changes (1)
  • third_party/fmt
โฐ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: pcsx-redux (aarch64-linux)
  • GitHub Check: pcsx-redux (x86_64-linux)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: asan
  • GitHub Check: cross-arm64
  • GitHub Check: build-openbios
  • GitHub Check: macos-build-and-test-toolchain
  • GitHub Check: build
  • GitHub Check: toolchain
  • GitHub Check: coverage

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[bot] avatar Oct 22 '25 16:10 coderabbitai[bot]

5f47854 takes the AI suggestion and removes the TZ assumption in the tests, but I don't love how it essentially reimplements the function in order to handle it. I'm open to suggestions on that.

njfox avatar Oct 23 '25 13:10 njfox

fwiw, I needed this patch to get pcsx-redux to compile again on Arch Linux (using the pcsx-redux-git AUR package, which does not use third-party/fmt btw)

rubin55 avatar Nov 03 '25 09:11 rubin55