fix(libc): normalize a pre-1970 calendar before the Windows host mktime #12549

Merged
JJenkx merged 2 commits from upstream-pr/12549 into main 2026-10-29 22:28:21 +00:00
JJenkx commented 2026-10-28 19:11:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-28T19:11:55Z.


What

On Windows, host mktime can reject a calendar whose raw year is before 1969 even when its fields normalize into representable early 1970. Rebuild nonordinary fields from normalized UTC seconds before passing them to the host.

The initial PR also computed a 400-year window shift for every such calendar. On macOS that could move a valid far-future calendar into a historical time zone: equivalent representations of 3520-10-22 18:22:37 in Pacific/Kiritimati differed by 88,800 seconds. The review follow-up keeps moved = 0 for in-range dates and computes the cycle shift only when the normalized timestamp is actually outside the host range. The Windows early-year normalization remains in place.

Add equivalent-calendar tests for years 2320, 2390 and 3520 through both exported entry points. POSIX also exercises America/New_York and Pacific/Kiritimati; both hosts exercise EST5EDT, and the existing fixed-zone/early-year regressions remain. These tests compare equivalent calendars and normalized fields rather than assume one host's historical offset.

Integration with #10409: its current head already produces identical conflict blocks in four files against main 319621ba2e as against this updated PR. Our normalization change adds no conflict block, and does not replace its separate 36-byte GuestTm ABI fix. Author coordination requested: proposed order is #12549 first, then #10409 refreshed while retaining the normalization guard/tests. Author confirmation remains pending; no agreement is presumed.

Tested

Exact updated head 5d02c43cc567d638269e1ae818fd7030cc1a32a7, based on main 319621ba2e578bd053b0baba2877fe70520e0737. This is a normal fast-forward functional follow-up, with no rebase or merge commits.

Check Result
Linux x86_64 Release: patched libc plus six focused groups, three executions each 18/18 pass, no skips
Windows 11, WinLibs GCC 15.2 UCRT r7, Release: same library/test build 18/18 pass, no skips
Windows main Time.cpp with the new PR tests Expected failure: mktime refused a calendar that normalizes into 1970
Historical-zone replay of the macOS window algorithm on Linux Prior: 5/9 equivalent-calendar pairs differ; updated: 0/9
Fresh guarded 20,015-calendar replay on Windows Updated matches previous PR on all 20,015 timestamp/field results
SDK controls: FAR PPSA03766 and Tetris PPSA07923, executed on Linux Agree on all 20,015 timestamp/field results
Conventions, whitespace, current-main merge preview Pass/clean

Groups: guest_mktime, guest_time_conversion, guest_time_extras, guest_strftime, guest_system_service_time_zone and guest_utime. All ran as actual local project test executables. The patched library is built separately; tests link the unpatched library from the same source.

Fresh SDK comparison: each arm uses the original study's 15 fixed inputs and the same 20,000 deterministic random calendars, with process-local UTC0 and a verified zero epoch anchor. The two SDK modules run natively on Linux; main, previous PR and updated DLLs each run in separate Windows processes. The probe uses canonical GuestTm storage with guard bytes, compares only the nine guest fields and timestamp, and reuses no old scratch executable. It does not change the system time zone.

Exact timestamp + nine-field comparison Differing rows
Windows main vs SDK 6,657
Previous PR vs SDK 6,651
Updated PR vs SDK 6,651
Updated vs previous PR 0

Main-to-PR results change in nine rows; six become exact SDK matches, and no previously matching main row becomes a mismatch. The 6,651 residual rows are pre-existing behavior: 6,650 explicit positive-DST-hint rows (host CRT subtracts an hour in UTC0, SDK ignores the hint) and the 1899 case where SDK returns -1. This is not a claim of full 20,015-case SDK equivalence. These original-study inputs cover early-year normalization; the separate tests cover far-future equivalent calendars.

macOS qualification limit: the reviewer independently measured the historical-zone problem on macOS. Our replay exposes the exact macOS branch of Time.cpp through private preprocessor substitutions while retaining Linux/glibc host types and timezone data. It reproduces the 88,800-second Kiritimati example and verifies the guard fix, but is not actual updated macOS runtime qualification. Please rerun the new head on macOS; no full macOS library result is claimed from hosted relinker jobs.

cmake --build BUILD --parallel 8 --target core/libs/libs/libc.prx guest_mktime_tests guest_time_conversion_tests guest_time_extras_tests guest_strftime_tests guest_system_service_time_zone_tests guest_utime_tests
ctest --test-dir BUILD -R '^(guest_mktime|guest_time_conversion|guest_time_extras|guest_strftime|guest_system_service_time_zone|guest_utime)$' --repeat until-fail:3 --output-on-failure
python3 tools/check_conventions.py --base origin/main
git diff --check origin/main...HEAD

Source reproducer, guarded calendar rows, both-host builds/runtime logs, negative control, JUnit results and #10409 conflict comparison. SHA-256 19703ea57d4ce7cc73c19ec50d7457c759ff26105fa70d1e6dac16703f29c454 (download verified). No SDK/game binaries or disassembly included. No game/GPU test, console execution or performance claim is made. Windows validation sources and builds were restored after the private control snapshots.

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 (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5056221427 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12549). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-28T19:11:55Z. --- ### What On Windows, host `mktime` can reject a calendar whose raw year is before 1969 even when its fields normalize into representable early 1970. Rebuild nonordinary fields from normalized UTC seconds before passing them to the host. The initial PR also computed a 400-year window shift for every such calendar. On macOS that could move a valid far-future calendar into a historical time zone: equivalent representations of 3520-10-22 18:22:37 in Pacific/Kiritimati differed by 88,800 seconds. The review follow-up keeps `moved = 0` for in-range dates and computes the cycle shift only when the normalized timestamp is actually outside the host range. The Windows early-year normalization remains in place. Add equivalent-calendar tests for years 2320, 2390 and 3520 through both exported entry points. POSIX also exercises America/New_York and Pacific/Kiritimati; both hosts exercise EST5EDT, and the existing fixed-zone/early-year regressions remain. These tests compare equivalent calendars and normalized fields rather than assume one host's historical offset. **Integration with #10409:** its current head already produces identical conflict blocks in four files against `main` `319621ba2e` as against this updated PR. Our normalization change adds no conflict block, and does not replace its separate 36-byte GuestTm ABI fix. [Author coordination requested](https://github.com/boykopovar/AnyPS5/pull/10409#issuecomment-6480087172): proposed order is #12549 first, then #10409 refreshed while retaining the normalization guard/tests. Author confirmation remains pending; no agreement is presumed. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Exact updated head `5d02c43cc567d638269e1ae818fd7030cc1a32a7`, based on `main` `319621ba2e578bd053b0baba2877fe70520e0737`. This is a normal fast-forward functional follow-up, with no rebase or merge commits. | Check | Result | |---|---| | Linux x86_64 Release: patched libc plus six focused groups, three executions each | 18/18 pass, no skips | | Windows 11, WinLibs GCC 15.2 UCRT r7, Release: same library/test build | 18/18 pass, no skips | | Windows main Time.cpp with the new PR tests | Expected failure: `mktime refused a calendar that normalizes into 1970` | | Historical-zone replay of the macOS window algorithm on Linux | Prior: 5/9 equivalent-calendar pairs differ; updated: 0/9 | | Fresh guarded 20,015-calendar replay on Windows | Updated matches previous PR on all 20,015 timestamp/field results | | SDK controls: FAR PPSA03766 and Tetris PPSA07923, executed on Linux | Agree on all 20,015 timestamp/field results | | Conventions, whitespace, current-main merge preview | Pass/clean | Groups: `guest_mktime`, `guest_time_conversion`, `guest_time_extras`, `guest_strftime`, `guest_system_service_time_zone` and `guest_utime`. All ran as actual local project test executables. The patched library is built separately; tests link the unpatched library from the same source. **Fresh SDK comparison:** each arm uses the original study's 15 fixed inputs and the same 20,000 deterministic random calendars, with process-local UTC0 and a verified zero epoch anchor. The two SDK modules run natively on Linux; main, previous PR and updated DLLs each run in separate Windows processes. The probe uses canonical GuestTm storage with guard bytes, compares only the nine guest fields and timestamp, and reuses no old scratch executable. It does not change the system time zone. | Exact timestamp + nine-field comparison | Differing rows | |---|---| | Windows main vs SDK | 6,657 | | Previous PR vs SDK | 6,651 | | Updated PR vs SDK | 6,651 | | Updated vs previous PR | 0 | Main-to-PR results change in nine rows; six become exact SDK matches, and no previously matching main row becomes a mismatch. The 6,651 residual rows are pre-existing behavior: 6,650 explicit positive-DST-hint rows (host CRT subtracts an hour in UTC0, SDK ignores the hint) and the 1899 case where SDK returns -1. **This is not a claim of full 20,015-case SDK equivalence.** These original-study inputs cover early-year normalization; the separate tests cover far-future equivalent calendars. **macOS qualification limit:** the reviewer independently measured the historical-zone problem on macOS. Our replay exposes the exact macOS branch of Time.cpp through private preprocessor substitutions while retaining Linux/glibc host types and timezone data. It reproduces the 88,800-second Kiritimati example and verifies the guard fix, but is **not actual updated macOS runtime qualification**. Please rerun the new head on macOS; no full macOS library result is claimed from hosted relinker jobs. ```sh cmake --build BUILD --parallel 8 --target core/libs/libs/libc.prx guest_mktime_tests guest_time_conversion_tests guest_time_extras_tests guest_strftime_tests guest_system_service_time_zone_tests guest_utime_tests ctest --test-dir BUILD -R '^(guest_mktime|guest_time_conversion|guest_time_extras|guest_strftime|guest_system_service_time_zone|guest_utime)$' --repeat until-fail:3 --output-on-failure python3 tools/check_conventions.py --base origin/main git diff --check origin/main...HEAD ``` [Source reproducer, guarded calendar rows, both-host builds/runtime logs, negative control, JUnit results and #10409 conflict comparison](https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/pr12549-calendar-review-linux-windows-20261028.tar.gz). SHA-256 `19703ea57d4ce7cc73c19ec50d7457c759ff26105fa70d1e6dac16703f29c454` (download verified). No SDK/game binaries or disassembly included. No game/GPU test, console execution or performance claim is made. Windows validation sources and builds were restored after the private control snapshots. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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 (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-28 19:43:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T19:43:26Z.

Review: CHANGES_REQUESTED


Reviewed — changes requested

The calendar change is narrowly scoped, but its merge with open PR #10409 conflicts in Time.cpp and GuestMktime.cpp, and the checklist currently says there is no dependency.

What I ran

  • Reviewed exact head ba5890f3c060c957b7469a9b8fd733fcab90cc9a against base 319621ba2e578bd053b0baba2877fe70520e0737; merge tree 6ac1c750f9e77ab1461cab334f9d14d8d40be88d is clean.
  • Ran git diff --check refs/review/current-main...refs/review/12549 — pass, no output.
  • Compared the changes with open #10409 and ran git merge-tree --write-tree refs/review/10409 refs/review/12549; the combined merge reports content conflicts in Time.cpp, GuestMktime.cpp, GuestStrftime.cpp, and GuestTimeConversion.cpp.
  • Refreshed hosted checks: Windows, Ubuntu/Windows relinker, relinker ASan, Ubuntu register-context, conventions and policy checks pass; Linux product is skipped; macOS jobs are pending.

Results

Check Result
Current-main merge preview Clean
Diff check Pass
Combined merge preview with #10409 Content conflicts, including Time.cpp and GuestMktime.cpp
Hosted Windows and Ubuntu/Windows relinker Pass
Linux product tests Skipped
macOS tests Pending
Focused Windows regression Reported by author as passing; not independently run
Raw combined-merge conflict output
CONFLICT (content): Merge conflict in core/libs/prx/libc/src/Time.cpp
CONFLICT (content): Merge conflict in core/libs/tests/GuestMktime.cpp
CONFLICT (content): Merge conflict in core/libs/tests/GuestStrftime.cpp
CONFLICT (content): Merge conflict in core/libs/tests/GuestTimeConversion.cpp

Negative control

Assertion Change under test Result
Early-year calendars normalizing into 1970 are rejected by the base Windows implementation Author reports running the added tests with main's Time.cpp Author reports failure with “mktime refused a calendar that normalizes into 1970”; I did not independently run the Windows control

Findings

Blocking

  • Resolve the open-PR integration conflict and declare the agreed order. The merge preview with #10409 has content conflicts in files changed by this PR, including both the production Time.cpp and its GuestMktime.cpp test. The repository contribution rules require agreeing which overlapping PR goes first and declaring it with Depends on. Please coordinate the order with #10409's author, update this checklist, and rebase/restack or otherwise resolve the combined changes. Re-run the focused tests after integration.

Non-blocking

The one-line normalization condition is consistent with the reported Windows UCRT failure mode, and no separate code defect was established in this source review. Author-reported 20,015-calendar SDK comparison and focused Windows results were not independently reproduced here.

Sources

Not verified

I did not run Windows or macOS builds/tests, the 20,015-calendar comparison, the base negative control, or console behavior. Hosted macOS jobs were still pending at review time.

To get this to a good state

Coordinate and declare the integration order with #10409, then rerun the focused time suite and recheck the combined merge. I will review the updated head and repeat the relevant checks.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5688701505 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12549#pullrequestreview-5688701505). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-28T19:43:26Z. **Review:** CHANGES_REQUESTED --- # Reviewed — changes requested The calendar change is narrowly scoped, but its merge with open PR #10409 conflicts in `Time.cpp` and `GuestMktime.cpp`, and the checklist currently says there is no dependency. ## What I ran - Reviewed exact head `ba5890f3c060c957b7469a9b8fd733fcab90cc9a` against base `319621ba2e578bd053b0baba2877fe70520e0737`; merge tree `6ac1c750f9e77ab1461cab334f9d14d8d40be88d` is clean. - Ran `git diff --check refs/review/current-main...refs/review/12549` — pass, no output. - Compared the changes with open #10409 and ran `git merge-tree --write-tree refs/review/10409 refs/review/12549`; the combined merge reports content conflicts in `Time.cpp`, `GuestMktime.cpp`, `GuestStrftime.cpp`, and `GuestTimeConversion.cpp`. - Refreshed hosted checks: Windows, Ubuntu/Windows relinker, relinker ASan, Ubuntu register-context, conventions and policy checks pass; Linux product is skipped; macOS jobs are pending. ## Results | Check | Result | |---|---| | Current-main merge preview | Clean | | Diff check | Pass | | Combined merge preview with #10409 | Content conflicts, including `Time.cpp` and `GuestMktime.cpp` | | Hosted Windows and Ubuntu/Windows relinker | Pass | | Linux product tests | Skipped | | macOS tests | Pending | | Focused Windows regression | Reported by author as passing; not independently run | <details> <summary>Raw combined-merge conflict output</summary> ```text CONFLICT (content): Merge conflict in core/libs/prx/libc/src/Time.cpp CONFLICT (content): Merge conflict in core/libs/tests/GuestMktime.cpp CONFLICT (content): Merge conflict in core/libs/tests/GuestStrftime.cpp CONFLICT (content): Merge conflict in core/libs/tests/GuestTimeConversion.cpp ``` </details> ## Negative control | Assertion | Change under test | Result | |---|---|---| | Early-year calendars normalizing into 1970 are rejected by the base Windows implementation | Author reports running the added tests with main's `Time.cpp` | Author reports failure with “mktime refused a calendar that normalizes into 1970”; I did not independently run the Windows control | ## Findings ### Blocking - **Resolve the open-PR integration conflict and declare the agreed order.** The merge preview with #10409 has content conflicts in files changed by this PR, including both the production `Time.cpp` and its `GuestMktime.cpp` test. The repository contribution rules require agreeing which overlapping PR goes first and declaring it with `Depends on`. Please coordinate the order with #10409's author, update this checklist, and rebase/restack or otherwise resolve the combined changes. Re-run the focused tests after integration. ### Non-blocking The one-line normalization condition is consistent with the reported Windows UCRT failure mode, and no separate code defect was established in this source review. Author-reported 20,015-calendar SDK comparison and focused Windows results were not independently reproduced here. ## Sources - [Normalization condition at this PR head](https://github.com/boykopovar/AnyPS5/blob/ba5890f3c060c957b7469a9b8fd733fcab90cc9a/core/libs/prx/libc/src/Time.cpp) - [Early-year regression at this PR head](https://github.com/boykopovar/AnyPS5/blob/ba5890f3c060c957b7469a9b8fd733fcab90cc9a/core/libs/tests/GuestMktime.cpp) - [Open integration PR #10409](https://github.com/boykopovar/AnyPS5/pull/10409) - [Contribution rule for overlapping pull requests](https://github.com/boykopovar/AnyPS5/blob/319621ba2e578bd053b0baba2877fe70520e0737/CONTRIBUTING.md) ## Not verified I did not run Windows or macOS builds/tests, the 20,015-calendar comparison, the base negative control, or console behavior. Hosted macOS jobs were still pending at review time. ## To get this to a good state Coordinate and declare the integration order with #10409, then rerun the focused time suite and recheck the combined merge. I will review the updated head and repeat the relevant checks.
rooklz commented 2026-10-28 19:51:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-28T19:51:22Z.

Review: COMMENTED


I reviewed head ba5890f3c0 on macOS. The body says that platform was left to CI. The new condition does change macOS results, and for far-future dates some of them are wrong.

Setup. macOS 26.2, Apple clang, -arch x86_64 under Rosetta, -O1 -fsanitize=address,undefined, the target's -include HostStandardStreams.hpp. Standalone build of Time.cpp, Environment.cpp, Multibyte.cpp with GuestMktime.cpp.

  • guest_mktime passes 50/50 with no sanitizer reports, and also under TZ=UTC, America/New_York and Pacific/Kiritimati. With main's Time.cpp it passes on macOS too. That's expected, since macOS already normalizes these calendars through timeOfLocalSeconds.

Differential, head vs main. A harness feeds both builds the same 40,000 random calendars (out-of-range fields, years -2000..3000, tm_isdst -1/0/1). I compared the returned seconds against Python zoneinfo as the oracle. Only rows where the oracle gives one unambiguous answer are counted.

zone rows changed head right, main wrong main right, head wrong
UTC0 / UTC-2 / UTC5 0 – –
America/New_York 145 7 138
Europe/London 143 5 94
Australia/Lord_Howe 1235 3 400
Pacific/Kiritimati 962 0 463

Every regression is in a year ≥ 2300. Here is a minimal pair. These two calendars name the same instant, 3520-10-22 18:22:37:

TZ=Pacific/Kiritimati  {1620, 9, 22, 18:22:37}    head 48938703757   main 48938703757
TZ=Pacific/Kiritimati  {1620, 21, -343, 18:22:37}  head 48938792557   main 48938703757

On head, the second one comes back as 23 October 19:02:37, 88,800 s later, with tm_gmtoff +14:00. That's the −10:40 offset Kiritimati used before 1979.

Cause. !ordinary now also sends in-range calendars into the block, and that block still computes moved as whole 400-year cycles. On macOS firstOrdinary is 1900-01-02. A year-3520 calendar is therefore moved into 1920 and converted there by the host mktime, which applies the zone's 1920 rules. main only moved calendars that were actually outside the host range. With ordinary fields, head is the same as main (first row), so this only affects calendars with out-of-range fields.

Suggested fix. Keep the new entry condition, but only move the window when it's really out of range:

     if (!ordinary || approximate < firstOrdinary || approximate > HOST_LAST_SECOND - SECONDS_PER_DAY) {
-        moved = calendarCycles(approximate - firstOrdinary, CALENDAR_CYCLE_SECONDS) * CALENDAR_CYCLE_SECONDS;
+        if (approximate < firstOrdinary || approximate > HOST_LAST_SECOND - SECONDS_PER_DAY)
+            moved = calendarCycles(approximate - firstOrdinary, CALENDAR_CYCLE_SECONDS) * CALENDAR_CYCLE_SECONDS;

An in-range calendar is then rebuilt from its normalized UTC fields with moved = 0. UCRT gets ordinary fields, which is the point of this PR, and nothing gets moved across zone history. On macOS with this change:

  • guest_mktime (head test) passes.
  • 0 rows differ from main in Kiritimati, plus seeds 11/12.
  • The only rows that differ from main in New York (8), London (5) and Lord Howe (3) are all cases where main was wrong and the oracle agrees with the change. These are tm_isdst = -1 calendars whose out-of-range fields land on a DST transition, which macOS mktime resolves differently.
  • With moved left out on Windows the early-1970 cases go through the same path as head, but I couldn't run that. Please rerun your 20,015-calendar comparison with the suggested change.

I'd also add a test that exercises this: one non-normalized calendar in a far-future year in a zone whose pre-1970 offsets differ from its current ones, checking that it matches the normalized form. The current zones (UTC0, UTC-2, UTC5) have no history, so this path can't show up in them.

Gates. check_conventions --base upstream/main passes and git merge-tree against upstream/main 319621ba2e is clean.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5688797048 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12549#pullrequestreview-5688797048). Originally posted by [rooklz](https://github.com/rooklz) on 2026-10-28T19:51:22Z. **Review:** COMMENTED --- I reviewed head `ba5890f3c0` on macOS. The body says that platform was left to CI. The new condition does change macOS results, and for far-future dates some of them are wrong. **Setup.** macOS 26.2, Apple clang, `-arch x86_64` under Rosetta, `-O1 -fsanitize=address,undefined`, the target's `-include HostStandardStreams.hpp`. Standalone build of `Time.cpp`, `Environment.cpp`, `Multibyte.cpp` with `GuestMktime.cpp`. - `guest_mktime` passes 50/50 with no sanitizer reports, and also under `TZ=UTC`, `America/New_York` and `Pacific/Kiritimati`. With `main`'s `Time.cpp` it passes on macOS too. That's expected, since macOS already normalizes these calendars through `timeOfLocalSeconds`. **Differential, head vs `main`.** A harness feeds both builds the same 40,000 random calendars (out-of-range fields, years -2000..3000, `tm_isdst` -1/0/1). I compared the returned seconds against Python `zoneinfo` as the oracle. Only rows where the oracle gives one unambiguous answer are counted. | zone | rows changed | head right, main wrong | main right, head wrong | |---|---|---|---| | `UTC0` / `UTC-2` / `UTC5` | 0 | – | – | | `America/New_York` | 145 | 7 | 138 | | `Europe/London` | 143 | 5 | 94 | | `Australia/Lord_Howe` | 1235 | 3 | 400 | | `Pacific/Kiritimati` | 962 | 0 | 463 | Every regression is in a year ≥ 2300. Here is a minimal pair. These two calendars name the same instant, 3520-10-22 18:22:37: ``` TZ=Pacific/Kiritimati {1620, 9, 22, 18:22:37} head 48938703757 main 48938703757 TZ=Pacific/Kiritimati {1620, 21, -343, 18:22:37} head 48938792557 main 48938703757 ``` On head, the second one comes back as 23 October 19:02:37, 88,800 s later, with `tm_gmtoff` +14:00. That's the −10:40 offset Kiritimati used before 1979. **Cause.** `!ordinary` now also sends in-range calendars into the block, and that block still computes `moved` as whole 400-year cycles. On macOS `firstOrdinary` is 1900-01-02. A year-3520 calendar is therefore moved into 1920 and converted there by the host `mktime`, which applies the zone's 1920 rules. `main` only moved calendars that were actually outside the host range. With `ordinary` fields, head is the same as `main` (first row), so this only affects calendars with out-of-range fields. **Suggested fix.** Keep the new entry condition, but only move the window when it's really out of range: ```diff if (!ordinary || approximate < firstOrdinary || approximate > HOST_LAST_SECOND - SECONDS_PER_DAY) { - moved = calendarCycles(approximate - firstOrdinary, CALENDAR_CYCLE_SECONDS) * CALENDAR_CYCLE_SECONDS; + if (approximate < firstOrdinary || approximate > HOST_LAST_SECOND - SECONDS_PER_DAY) + moved = calendarCycles(approximate - firstOrdinary, CALENDAR_CYCLE_SECONDS) * CALENDAR_CYCLE_SECONDS; ``` An in-range calendar is then rebuilt from its normalized UTC fields with `moved = 0`. UCRT gets ordinary fields, which is the point of this PR, and nothing gets moved across zone history. On macOS with this change: - `guest_mktime` (head test) passes. - 0 rows differ from `main` in Kiritimati, plus seeds 11/12. - The only rows that differ from `main` in New York (8), London (5) and Lord Howe (3) are all cases where `main` was wrong and the oracle agrees with the change. These are `tm_isdst = -1` calendars whose out-of-range fields land on a DST transition, which macOS `mktime` resolves differently. - With `moved` left out on Windows the early-1970 cases go through the same path as head, but I couldn't run that. Please rerun your 20,015-calendar comparison with the suggested change. I'd also add a test that exercises this: one non-normalized calendar in a far-future year in a zone whose pre-1970 offsets differ from its current ones, checking that it matches the normalized form. The current zones (`UTC0`, `UTC-2`, `UTC5`) have no history, so this path can't show up in them. **Gates.** `check_conventions --base upstream/main` passes and `git merge-tree` against `upstream/main` `319621ba2e` is clean.
adriadam10 commented 2026-10-28 19:55:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-28T19:55:45Z.

Review: CHANGES_REQUESTED


Thanks, the early-1970 Windows case is real and the one-line approach is right. Two things to fix:

  • core/libs/prx/libc/src/Time.cpp:571-572: !ordinary now sends in-range calendars (with out-of-range fields) into the block that computes moved as whole 400-year cycles. firstOrdinary is 1900-01-02 on macOS, so a year-3520 calendar is moved into ~1920 and converted with that zone's historical rules. @rooklz measured it on macOS against zoneinfo (40,000 random calendars): 0 changes in UTC0/UTC-2/UTC5, but regressions in Pacific/Kiritimati, Australia/Lord_Howe, America/New_York and Europe/London, all in years ≥ 2300. Minimal pair: {1620, 9, 22, 18:22:37} and {1620, 21, -343, 18:22:37} name the same instant but head returns different times for the second. The same window shift applies on Windows for years past firstOrdinary + 400 years. Fix: keep the new entry condition and only compute moved when approximate < firstOrdinary || approximate > HOST_LAST_SECOND - SECONDS_PER_DAY; otherwise moved = 0. @rooklz reports this removes the differences on macOS. Please rerun your 20,015-calendar Windows comparison with it.
  • core/libs/tests/GuestMktime.cpp:61: the zones the test runs (UTC0, UTC-2, UTC5) have no history, so this path can't fail there. Add a case with a far-future non-normalized calendar in a zone whose old offsets differ from its current ones (for example Pacific/Kiritimati or America/New_York), checking it equals the normalized form's result.
  • Overlap with #10409: both change Time.cpp and GuestMktime.cpp and the combined merge conflicts. Please agree the order with its author and declare it under Depends on.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5688849788 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12549#pullrequestreview-5688849788). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-28T19:55:45Z. **Review:** CHANGES_REQUESTED --- Thanks, the early-1970 Windows case is real and the one-line approach is right. Two things to fix: - `core/libs/prx/libc/src/Time.cpp:571-572`: `!ordinary` now sends in-range calendars (with out-of-range fields) into the block that computes `moved` as whole 400-year cycles. `firstOrdinary` is 1900-01-02 on macOS, so a year-3520 calendar is moved into ~1920 and converted with that zone's historical rules. @rooklz measured it on macOS against `zoneinfo` (40,000 random calendars): 0 changes in `UTC0`/`UTC-2`/`UTC5`, but regressions in `Pacific/Kiritimati`, `Australia/Lord_Howe`, `America/New_York` and `Europe/London`, all in years ≥ 2300. Minimal pair: `{1620, 9, 22, 18:22:37}` and `{1620, 21, -343, 18:22:37}` name the same instant but head returns different times for the second. The same window shift applies on Windows for years past `firstOrdinary` + 400 years. Fix: keep the new entry condition and only compute `moved` when `approximate < firstOrdinary || approximate > HOST_LAST_SECOND - SECONDS_PER_DAY`; otherwise `moved = 0`. @rooklz reports this removes the differences on macOS. Please rerun your 20,015-calendar Windows comparison with it. - `core/libs/tests/GuestMktime.cpp:61`: the zones the test runs (`UTC0`, `UTC-2`, `UTC5`) have no history, so this path can't fail there. Add a case with a far-future non-normalized calendar in a zone whose old offsets differ from its current ones (for example `Pacific/Kiritimati` or `America/New_York`), checking it equals the normalized form's result. - Overlap with #10409: both change `Time.cpp` and `GuestMktime.cpp` and the combined merge conflicts. Please agree the order with its author and declare it under `Depends on`.
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!12549
No description provided.