fix(libSceRtc): retain Windows offsets across the supported date range #4939

Closed
QRMOE wants to merge 3 commits from upstream-pr/4939 into main
QRMOE commented 2026-10-13 05:42:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by QRMOE on 2026-10-13T05:42:37Z.


What

Keep the configured host time-zone offset when libSceRtc converts valid dates outside the Windows CRT's time range. Main calls the host localtime_s, treats a rejected date as an offset of zero, and reports UTC instead of the selected zone for dates before 1970 or after January 3001. For example, 1969-12-31T23:59:59.50 in XXX-5:30 should format as 1970-01-01T05:29:59.50+05:30; main emits the UTC value.

On Windows, use the existing libc local-time conversion and its tm_gmtoff, and link libSceRtc to libc. This extends the offset calculation to RTC's years 1 to 9999, including conversion, local-clock queries and local RFC formatting. Linux keeps its existing native conversion. The existing libc 400-year calendar fallback and its historical daylight-saving limitation are recorded in RTC's technical debt.

Microsoft's localtime documentation identifies the CRT range and the failure for negative or oversized timestamps.

Tested

Windows, MinGW GCC 15.2, Release, BUILD_TESTING=ON; regression reproduced on main 46e7cd3e8, rebased onto 88107b7de:

  • The new regression fails on unchanged main with RTC local offset lost for year 1 in XXX-5:30.
  • Fixed-offset tests cover years 1, 1601, 1900, 1969, 1970, 2024, 3001 and 9999 in UTC, UTC+05:30 and UTC-03:00. They check both conversion directions, in-place results, microseconds, local RFC3339/RFC2822 formatting across the Unix epoch and out-of-range results at RTC's lower and upper limits.
  • RTC, libc time conversion and mktime tests passed with the fix.
  • Explicit libs build, all six RTC/time/clock runtime tests and the patched-library loading test passed. Conventions and whitespace checks passed.
  • The full build on the previous base 7e181fcc3 completed every remaining target except recreation of the unrelated guest_fstatfs_tests.exe output, which Windows denies. After rebasing to 88107b7de, the explicit libs build and seven runtime/loading checks passed; unrelated executable outputs remain blocked during rebuilds. Avast's log records automatic sandboxing of that test. The local full-build limitation remains; local full-build success is not claimed.
  • No title playback or console time-zone configuration was tested. Named zones outside the CRT range use libc's corresponding calendar-cycle rule, not historical zone data.

Review validation

  • xXPBSXx's Windows report: Reports a clean merge, full Windows build with 0 errors, relevant runtime checks and conventions passing.

Ready for maintainer review. Full Linux/Windows CI requires a maintainer's manual dispatch; marking this PR ready does not claim those jobs passed.

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 (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4838914553 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4939). Originally posted by [QRMOE](https://github.com/QRMOE) on 2026-10-13T05:42:37Z. --- ### What Keep the configured host time-zone offset when libSceRtc converts valid dates outside the Windows CRT's time range. Main calls the host `localtime_s`, treats a rejected date as an offset of zero, and reports UTC instead of the selected zone for dates before 1970 or after January 3001. For example, `1969-12-31T23:59:59.50` in `XXX-5:30` should format as `1970-01-01T05:29:59.50+05:30`; main emits the UTC value. On Windows, use the existing libc local-time conversion and its `tm_gmtoff`, and link libSceRtc to libc. This extends the offset calculation to RTC's years 1 to 9999, including conversion, local-clock queries and local RFC formatting. Linux keeps its existing native conversion. The existing libc 400-year calendar fallback and its historical daylight-saving limitation are recorded in RTC's technical debt. [Microsoft's localtime documentation](https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/localtime-s-localtime32-s-localtime64-s) identifies the CRT range and the failure for negative or oversized timestamps. ### Tested Windows, MinGW GCC 15.2, Release, `BUILD_TESTING=ON`; regression reproduced on main `46e7cd3e8`, rebased onto `88107b7de`: - The new regression fails on unchanged main with `RTC local offset lost for year 1 in XXX-5:30`. - Fixed-offset tests cover years 1, 1601, 1900, 1969, 1970, 2024, 3001 and 9999 in UTC, UTC+05:30 and UTC-03:00. They check both conversion directions, in-place results, microseconds, local RFC3339/RFC2822 formatting across the Unix epoch and out-of-range results at RTC's lower and upper limits. - RTC, libc time conversion and mktime tests passed with the fix. - Explicit libs build, all six RTC/time/clock runtime tests and the patched-library loading test passed. Conventions and whitespace checks passed. - The full build on the previous base `7e181fcc3` completed every remaining target except recreation of the unrelated `guest_fstatfs_tests.exe` output, which Windows denies. After rebasing to `88107b7de`, the explicit libs build and seven runtime/loading checks passed; unrelated executable outputs remain blocked during rebuilds. Avast's log records automatic sandboxing of that test. The local full-build limitation remains; local full-build success is not claimed. - No title playback or console time-zone configuration was tested. Named zones outside the CRT range use libc's corresponding calendar-cycle rule, not historical zone data. ### Review validation - [xXPBSXx's Windows report](https://github.com/boykopovar/AnyPS5/pull/4939#issuecomment-6141721589): Reports a clean merge, full Windows build with 0 errors, relevant runtime checks and conventions passing. Ready for maintainer review. Full Linux/Windows CI requires a maintainer's manual dispatch; marking this PR ready does not claim those jobs passed. ### 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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's technical debt file - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none - [x] AI-assisted: yes
xXPBSXx commented 2026-10-13 08:41:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T08:41:08Z.


Windows test: head ae307efe0 merged onto current main a373241de (clean merge, no conflicts). Windows 10, MinGW GCC (WinLibs), Ninja Release, -j2: full build 0 errors; ctest with the filter guest_rtc: guest_rtc passed (1 test(s), 0 failed); python tools/check_conventions.py --base upstream/main passed. I did not run the new tests against main without the change.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6141721589 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4939#issuecomment-6141721589). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-13T08:41:08Z. --- Windows test: head `ae307efe0` merged onto current `main` `a373241de` (clean merge, no conflicts). Windows 10, MinGW GCC (WinLibs), Ninja Release, `-j2`: full build 0 errors; ctest with the filter `guest_rtc`: guest_rtc passed (1 test(s), 0 failed); `python tools/check_conventions.py --base upstream/main` passed. I did not run the new tests against `main` without the change. AI-assisted (Claude Code).
github-actions[bot] commented 2026-10-13 23:25:53 +00:00 (Migrated from github.com)

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


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#5544 docs/dev/debt/libSceRtc.md L8
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6157341021 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4939#issuecomment-6157341021). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T23:25:53Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #5544 | `docs/dev/debt/libSceRtc.md` [L8](https://github.com/boykopovar/AnyPS5/blob/0df6e295c52e7cd6afa394ed35513bd252045c74/docs/dev/debt/libSceRtc.md#L8) | | |
oneandonlydean commented 2026-10-14 02:35:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T02:35:36Z.


Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6159618783 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4939#issuecomment-6159618783). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T02:35:36Z. --- Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.
QRMOE commented 2026-10-15 07:45:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by QRMOE on 2026-10-15T07:45:28Z.


Understood. I’ll leave this closed and revisit it only with a title ID and a current-main log showing the failure. I’ll hold off on new PRs without a title needing the change while the queue is high.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6187146451 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4939#issuecomment-6187146451). Originally posted by [QRMOE](https://github.com/QRMOE) on 2026-10-15T07:45:28Z. --- Understood. I’ll leave this closed and revisit it only with a title ID and a current-main log showing the failure. I’ll hold off on new PRs without a title needing the change while the queue is high.

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!4939
No description provided.