fix(libc): preserve guest time zones in Windows strftime #2665

Closed
ArjenS-LA wants to merge 1 commit from upstream-pr/2665 into main
ArjenS-LA commented 2026-10-10 10:25:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ArjenS-LA on 2026-10-10T10:25:21Z.


What

On Windows, formatting a guest UTC timestamp with %z %Z uses the host timezone: with TZ=PST8PDT, gmtime_s followed by strftime produces -0800 PST instead of +0000 UTC. With TZ=JST-9, it produces +0900 JST.

Format these two specifiers from GuestTm::tm_gmtoff and tm_zone before delegating the remaining format to the Windows CRT. Preserve literal percent signs, existing Windows # modifiers, unknown-zone handling and buffer limits. Both guest exports share the fix; the Linux implementation is unchanged.

This follows the timezone-field handling in FreeBSD strftime. Microsoft documents the CRT's use of global timezone state for these specifiers. It addresses a formatting gap remaining after #1606.

Checked 154 open PRs, their changed files, and the related discussions. No competing implementation found. #545 touches the same file but adds unrelated ctime_s and asctime_s functions.

Tested

  • Windows, MinGW-w64 GCC 15.2.0, Release: the new regression fails against unchanged upstream Time.cpp and passes with this fix. The original UTC/Pacific/Japan reproduction now produces +0000 UTC in all three host timezones.
  • Full Windows build passed. Registered tests guest_time_conversion, guest_process_time, guest_process_time_counter and guest_cpu_time_clocks: 4/4 passed.
  • Ubuntu under WSL: compiled and ran the time-conversion regression with -std=c++20 -O2 -Wall -Wextra -Werror -pthread; passed.
  • Regression coverage includes both exports, UTC/local and fractional-hour offsets, repeated and escaped specifiers, literal percent signs in zone names, unknown zones, and output capacities from zero through exact fit and larger.
  • Rebased onto a29ef592; both changed files are byte-for-byte identical to tested commit 9093f1c4. The full build and runtime runs above preceded this rebase and were not repeated for the unrelated upstream changes. Conventions and diff checks pass after the rebase.
  • No title or console run; no full Linux build or full CTest-suite run.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; no silent stubs added
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source — none added
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes (Codex)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4810508054 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2665). Originally posted by [ArjenS-LA](https://github.com/ArjenS-LA) on 2026-10-10T10:25:21Z. --- ### What On Windows, formatting a guest UTC timestamp with `%z %Z` uses the host timezone: with `TZ=PST8PDT`, `gmtime_s` followed by `strftime` produces `-0800 PST` instead of `+0000 UTC`. With `TZ=JST-9`, it produces `+0900 JST`. Format these two specifiers from `GuestTm::tm_gmtoff` and `tm_zone` before delegating the remaining format to the Windows CRT. Preserve literal percent signs, existing Windows `#` modifiers, unknown-zone handling and buffer limits. Both guest exports share the fix; the Linux implementation is unchanged. This follows the timezone-field handling in [FreeBSD strftime](https://github.com/freebsd/freebsd-src/blob/releng/9.0/lib/libc/stdtime/strftime.c). [Microsoft documents](https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/strftime-wcsftime-strftime-l-wcsftime-l?view=msvc-170) the CRT's use of global timezone state for these specifiers. It addresses a formatting gap remaining after #1606. Checked 154 open PRs, their changed files, and the related discussions. No competing implementation found. #545 touches the same file but adds unrelated `ctime_s` and `asctime_s` functions. ### Tested - Windows, MinGW-w64 GCC 15.2.0, Release: the new regression fails against unchanged upstream `Time.cpp` and passes with this fix. The original UTC/Pacific/Japan reproduction now produces `+0000 UTC` in all three host timezones. - Full Windows build passed. Registered tests `guest_time_conversion`, `guest_process_time`, `guest_process_time_counter` and `guest_cpu_time_clocks`: 4/4 passed. - Ubuntu under WSL: compiled and ran the time-conversion regression with `-std=c++20 -O2 -Wall -Wextra -Werror -pthread`; passed. - Regression coverage includes both exports, UTC/local and fractional-hour offsets, repeated and escaped specifiers, literal percent signs in zone names, unknown zones, and output capacities from zero through exact fit and larger. - Rebased onto `a29ef592`; both changed files are byte-for-byte identical to tested commit `9093f1c4`. The full build and runtime runs above preceded this rebase and were not repeated for the unrelated upstream changes. Conventions and diff checks pass after the rebase. - No title or console run; no full Linux build or full CTest-suite run. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw; no silent stubs added - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source — none added - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes (Codex)
github-actions[bot] commented 2026-10-10 10:25:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T10:25:54Z.


Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6096547906 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2665#issuecomment-6096547906). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-10T10:25:54Z. --- Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!2665
No description provided.