fix(libkernel): convert local time with the host time zone #5096
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5096"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by sguckiran on 2026-10-13T11:32:29Z.
What
Fixes #5067.
sceKernelConvertUtcToLocaltimeandsceKernelConvertLocaltimeToUtcreturned the time unchanged, while libclocaltimefollows the host zone. PPSA99203 (PS5SX2) draws its on-screen clock and its settings log times fromsceKernelConvertUtcToLocaltimefollowed bygmtime_r(source). Because of that, it showed UTC as local time in #5067.tzsetfollowed bylocaltime_r/tm_gmtoff, withtimezonefor the standard part. On Windows it is_tzsetfollowed bylocaltime_s, with_get_timezone/_get_dstbias. These are the sources libclocaltime_suses. Windows times outside the CRT range move by whole 400-year cycles, as libc does.KernelTimesec.west_secholds the standard offset in seconds east of UTC, despite its name, anddst_secholds the daylight saving seconds in effect. This follows PS5SX2's own notes from a console, where the call wrote 7200 and 3600, and shadPS4, which also stores seconds east. Whetherwest_secincludes daylight saving is not settled, and the open question is recorded indocs/dev/debt/libkernel.md.localtime_sdoes (recorded as debt).sceKernelConvertLocaltimeToUtcfinds the offset in two passes. In a skipped or repeated local hour it takes the offset in effect one standard offset earlier (recorded as debt).sceKernelGettimezoneand thegettimeofdaytime zone are unchanged (no offset, no daylight saving) and recorded as debt. #5084 makes the matching change forsceSystemServiceParamGetInt.Tested
Ubuntu 24.04, GCC 13.3, Release.
guest_freebsd_clockspasses. It now pinsTZand checks both directions forUTC0,IST-5:30(+5:30),BRT+3(-3:00) andEST5EDTin January (-5:00) and July (-4:00 with 3600 s of daylight saving), including theKernelTimesecfields. It also passes with no zoneinfo files (TZDIR=/nonexistent) and with a hostTZ=America/Toronto. The new checks abort on the previousTime.cpp. The existing identity and guard checks run underUTC0. Relinker-only build: all tests pass. Not tested on Windows or with a title.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by sguckiran on 2026-10-13T11:43:16Z.
fixed conflict.
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T11:44:55Z.
Review note (static, nothing built): (1) The description says
west_secis the "standard offset in seconds west of UTC", but the code stores the standard offset in seconds EAST of UTC in that field (ZoneStateis called withzone.standardEast; the test expectswest_sec == east - daylight, so IST +5:30 gives 19800), and the debt entry says the same ("holds the standard-time offset in seconds east of UTC, despite its name"). The description and the code/debt disagree on the sign; please align the description. (2)HostZoneAton POSIX uses::timezoneto split the offset into standard and daylight parts. POSIX does not requirelocaltime_rto settimezone(onlytzset/localtimedo), so atzset()call before reading it would make that independent of earlier calls. (3) The Windows branch reads the current_get_timezone/_get_dstbias, so instants under historical rules use today standard offset, which matches how libclocaltime_sbehaves here; worth a debt sentence. (4) The author did not test on Windows; the newRequireZonecases passTZstrings likeIST-5:30andEST5EDTthrough_putenv_s, which we can run on Windows 10 withguest_freebsd_clocksif that helps.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by sguckiran on 2026-10-13T11:49:52Z.
Please check updated description. Thanks.
Imported from boykopovar/AnyPS5. Originally posted by 0xRickx on 2026-10-13T12:08:55Z.
These are notes on how the PS5
libc.prxthat homebrew bundles insce_moduleuses these two calls. I read Prospero Explorer's (PPSA99109); offsets are in its text segment. One of them affects*dst_seconds.localtime(0x70c60) andlocaltime_r(0x71130) callsceKernelConvertUtcToLocaltime(t, &local, ×ec, NULL)and fail on a negative return. They build thetmfromlocalwithtm_isdst = (timesec.dst_sec != 0). They never readtimesec.torwest_sec.mktime(0x70d20) callssceKernelConvertLocaltimeToUtc(local, tm->tm_isdst, &utc, ×ec, &dst_seconds). The second argument,reservedhere, is the caller'stm_isdst.utcback withsceKernelConvertUtcToLocaltimeand compares the twowest_secvalues for equality only. It recomputes when they differ.tm_isdst > 0and the returnedtimesec.dst_secis 0, it subtractsdst_secondsfrom bothutcand the local time and setstm_isdst = 0(0x70ebb-0x70ee5). That branch exists to read a summer-time wall clock given outside summer time, so it only does something ifdst_secondsis the zone's summer-time amount (3600) even when summer time is not in effect.dst_secondsis 0 outside summer time. Somktimeof a winter date withtm_isdst = 1keeps the hour instead of moving it back by one, unlike what that branch is written for.So I think
*dst_secondsfromsceKernelConvertLocaltimeToUtcshould be the zone's daylight saving amount whether or not it is in effect at that time, whiletimesec.dst_secstays the amount in effect. Thetm_isdstargument could also resolve the repeated hour.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by sguckiran on 2026-10-13T12:20:57Z.
Thanks, this is really useful. You’re right: with dst_seconds at 0 outside summer time, that mktime branch never fires. Fixed in
15969f2: sceKernelConvertLocaltimeToUtc now writes the zone’s daylight saving amount to *dst_seconds whether or not it’s in effect (found by checking the host zone over the surrounding year, so it works in both hemispheres, and 0 for zones without DST), while timesec.dst_sec stays the amount in effect for localtime’s tm_isdst. The test now expects 3600 for EST5EDT in January as well as July, and the debt entry cites your PPSA99109 offsets (0x70ebb-0x70ee5).I left reserved/tm_isdst unused for now: I can’t check how the console uses it to pick the hour when the clock goes back, so it’s recorded as debt rather than guessed. Happy to add it in this PR or a follow-up if you’ve seen how the kernel side uses it.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-14T05:18:05Z.
Rebase handoff — rebased onto current
main(both commits), authorship unchanged.Conflicts resolved across the two commits: main's settime-validation tests (
SettimeValidatesLikeFreebsdand its helpers) and this PR's zone-conversion tests (RequireZone, now in its 5-parameter form from the second commit) are both kept, with main's<cstring>and this PR's<ctime>includes together.Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV):tools/check_conventions.py --base origin/mainpassesmainregression (agc_driver_tessellationsegfault, #4727); this PR's own clock tests pass (2/2)To pick it up:
Head is
59e30690f.Imported from boykopovar/AnyPS5. Originally posted by sguckiran on 2026-10-14T06:59:31Z.
Status update — all review points so far are addressed (head
bb5f7d7):west_secnow holds the standard offset in seconds east of UTC, matching PS5SX2's console observation and shadPS4 (ae7f5e3).tzset()/_tzset()is called before reading the host zone offsets; the Windows debt note about current-rule offsets is added (1614d82).sceKernelConvertLocaltimeToUtcreports the zone's daylight saving amount in*dst_secondseven outside summer time, so the bundled libcmktime(PPSA99109, 0x70ebb–0x70ee5) can shift atm_isdstgiven in winter;timesec.dst_secstays the amount in effect (15969f2). Thetm_isdstpassed as the second argument is still ignored and recorded as debt.main; theGuestFreebsdClocks.cppconflict keeps main's settime tests and the zone tests (bb5f7d7).Tested on Ubuntu 24.04 / GCC 13.3:
guest_freebsd_clockspasses, including without zoneinfo files and with a non-UTC host zone; conventions check passes. Thanks @blawesom for the full-suite run (1099/1100, only the known #4727 tessellation failure).Still untested on Windows. Could a maintainer start the full Build for this PR when convenient?
Imported from boykopovar/AnyPS5. Originally posted by orishamir on 2026-10-14T16:49:28Z.
Windows run, since the description says Windows wasn't tested. Windows 11, RTX 4080, WinLibs GCC 15.2.0 r7, Release, this head (
f5d856d85) merged ontomaine34c47921. The host zone is Israel Standard Time (UTC+3 with summer time today), so_get_dstbiasis -3600 and the Windows summer time path runs.guest_freebsd_clockspasses 5 of 5. The fullctesthas 0 failures out of 1198; the 14 skips come from the tests' own checks.core/libs/prx/libkernel/Time/Time.cpptaken back tomain,guest_freebsd_clocksaborts (exit 0xC0000409).TZvariable set, so the C runtime reads the system zone. Onmainits clock shows 16:44 at 16:44 UTC. With this PR it shows 19:47 at 16:47 UTC, which is the local time. Otherwise the two runs match: 16 dumped frames each and no new stderr line.Not covered: a Windows system zone without summer time, like a UTC CI runner. I didn't change this machine's zone.
AI-assisted: yes (Claude Code Opus 5.5)
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T17:40:55Z.
Checked on Linux: the build and the libkernel ctest scope pass (
guest_freebsd_clocksincluded, and it aborts without theTime.cppchange). Also reviewed the sign handling oftm_gmtoff/timezonefor the standard and daylight parts, the two-pass UTC lookup, and the debt entry. The Windows run by @orishamir covers the_get_timezone/_get_dstbiaspath. Merging once CI is green.