Skip to content

Conversation

@njfox
Copy link
Contributor

@njfox njfox commented Oct 22, 2025

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.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 22, 2025

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)
Loading

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 5f47854 and 7b90c96.

📒 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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/main/main.cc (1)

245-249: Bug: memcard2 CLI arg assigned from memcard1 variable

SettingMcd2() is set from argPath1.value() instead of argPath2.value(). This breaks the --memcard2 flag.

Apply this fix:

-        if (argPath2.has_value()) emuSettings.get<PCSX::Emulator::SettingMcd2>() = argPath1.value();
+        if (argPath2.has_value()) emuSettings.get<PCSX::Emulator::SettingMcd2>() = argPath2.value();
src/support/version.cc (1)

278-281: Wrong exception type: std::runtime_exception → std::runtime_error

std::runtime_exception doesn't exist and will fail to compile on unsupported platforms.

Apply this fix:

-    throw std::runtime_exception("No platform support for updates");
+    throw std::runtime_error("No platform support for updates");
🧹 Nitpick comments (3)
src/main/main.cc (1)

219-221: Centralized timestamp formatting (fmt12-safe) looks good

Switching to version.formatTimestamp("{:%Y-%m-%d %H:%M:%S}") removes the deprecated fmt::localtime usage and keeps output stable. Nice.

Optional: consider emitting JSON numeric for "timestamp" (unquoted) in a future change; keep as-is if consumers rely on string.

src/support/version.h (1)

63-63: API polish: take std::string_view

Avoid needless allocation by accepting std::string_view; callers can still pass literals and std::string.

Proposed change:

-    std::string formatTimestamp(const std::string& format) const;
+    std::string formatTimestamp(std::string_view format) const;

Add #include <string_view> in this header.

src/support/version.cc (1)

71-75: Timezone conversion: add robust fallback for environments without tzdb

std::chrono::current_zone()->to_local(...) may throw on platforms lacking the timezone database or with stripped tzdata. Consider a safe fallback to std::localtime to keep formatting working rather than propagating exceptions.

Example:

 std::string PCSX::VersionInfo::formatTimestamp(const std::string& format) const {
-    auto timepoint = std::chrono::system_clock::from_time_t(timestamp);
-    auto local = std::chrono::current_zone()->to_local(timepoint);
-    return fmt::format(fmt::runtime(format), floor<std::chrono::seconds>(local));
+    auto tp = std::chrono::system_clock::from_time_t(timestamp);
+    try {
+        auto local = std::chrono::current_zone()->to_local(tp);
+        return fmt::format(fmt::runtime(format), std::chrono::floor<std::chrono::seconds>(local));
+    } catch (...) {
+        // Fallback: thread-unsafe but acceptable here; copy the result.
+        std::tm tm_copy{};
+        if (auto* tm_ptr = std::localtime(&timestamp)) tm_copy = *tm_ptr;
+        return fmt::format(fmt::runtime(format), tm_copy);
+    }
 }
📜 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 718f091 and 94f3b8d.

📒 Files selected for processing (4)
  • src/gui/gui.cc (1 hunks)
  • src/main/main.cc (1 hunks)
  • src/support/version.cc (2 hunks)
  • src/support/version.h (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/support/version.h (1)
src/support/version.cc (2)
  • formatTimestamp (71-75)
  • formatTimestamp (71-71)
⏰ 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 (x86_64-linux)
  • GitHub Check: pcsx-redux (aarch64-linux)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: macos-build-and-test-toolchain
  • GitHub Check: asan
  • GitHub Check: build-openbios
  • GitHub Check: coverage
  • GitHub Check: toolchain
  • GitHub Check: cross-arm64
  • GitHub Check: build
🔇 Additional comments (2)
src/support/version.cc (1)

30-33: Includes are appropriate for chrono/fmt formatting

Adding <chrono>, <fmt/chrono.h>, and <fmt/format.h> is correct for the new approach.

src/gui/gui.cc (1)

2415-2438: Good: precompute timestamp once and reuse; removes deprecated API usage

This centralizes formatting via VersionInfo::formatTimestamp and avoids repeated conversions; clipboard and UI stay consistent.

@pull-request-size pull-request-size bot added size/M and removed size/S labels Oct 22, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 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 94f3b8d and 464c22f.

📒 Files selected for processing (1)
  • tests/support/version.cc (1 hunks)
🧰 Additional context used
🪛 Clang (14.0.6)
tests/support/version.cc

[error] 20-20: 'support/version.h' file not found

(clang-diagnostic-error)

⏰ 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 (x86_64-linux)
  • GitHub Check: pcsx-redux (aarch64-linux)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: build
  • GitHub Check: build-openbios
  • GitHub Check: toolchain
  • GitHub Check: cross-arm64
  • GitHub Check: coverage
  • GitHub Check: asan
  • GitHub Check: macos-build-and-test-toolchain

@njfox
Copy link
Contributor Author

njfox commented Oct 23, 2025

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 njfox changed the title Remove deprecated fmt::localtime API Remove deprecated fmt::localtime API and update fmt to 12.0.0 Oct 24, 2025
@rubin55
Copy link

rubin55 commented Nov 3, 2025

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compilation with fmt 12.x fails

2 participants