fix(rtc): parse RFC 2822, RFC 850 and asctime text like the console #1399

Merged
hugodearaujo merged 3 commits from upstream-pr/1399 into main 2026-10-08 13:05:42 +00:00
hugodearaujo commented 2026-10-08 02:12:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hugodearaujo on 2026-10-08T02:12:09Z.


What

Stacked on #1398, which is itself stacked on #1397: this branch also carries their commits, and only the last commit is new here.

In #816 the open question was which shapes the console's sceRtcParseDateTime accepts, so returning SCE_RTC_ERROR_BAD_PARSE for anything else was left for hardware evidence. This PR is that evidence. I measured 1174 inputs on a PS5 (firmware 13.60) by calling the real libSceRtc.sprx export through dlopen from a homebrew payload, with the tick preset to 0xdeadbeefcafebabe. The table and the probe source are in the comments on #1397. With this branch, a host harness gets the same return code and tick as the console for all 1174. 400 of them were random mutations of valid strings that I measured only after the implementation was frozen, and all 400 matched with no changes.

Grammar measured after leading spaces and tabs (a digit there goes to the RFC 3339 path from #1398):

  • Weekday is required. It can be the full name or three letters, in any case, and it is never checked against the date. An optional , must follow it directly (Thu , and Thu,, are BAD_PARSE), then any number of spaces and tabs. A digit next means RFC 2822/850; a letter means asctime.
  • RFC 2822 / RFC 850: the day has 1–2 digits. Then ' ' or '-', a month (full name or three letters, any case, nothing else: Sept, Jun., Janu are BAD_PARSE), ' ' or '-' again, and a year of exactly 2 or 4 digits (00–49 → 20xx, 50–99 → 19xx). Then one space and H:M[:S] with 1–2 digit fields; an hour above 25 is BAD_PARSE.
    • After the seconds, one space starts a zone. Two spaces, a tab, or other text means the zone is ignored, and so is the rest of the string. Without seconds the zone is ignored too (12:34 EST is 12:34 UTC).
    • Zone: +/- followed by four digits is applied as HHMM with no range check (+9999, -12345 → 99:99, 12:34). Anything shorter (+01:30, +1, +) gives offset 0.
    • A name is matched case-insensitively against the console's table, as a prefix (ESTERN = EST, PST8PDT = PST). Before that check, the console takes the zone as UT whenever the first character is an upper-case U or the second is an upper-case T (ET, xT, Ux → 0, while ut is the military letter u, −7h).
    • Any other letter uses the console's military table, which is off by one hour against RFC 822: A–I = 0…+8, K–M = +10…+12, N–Y = 0…−11, Z = 0, J = BAD_PARSE. A name that is not in the table uses its first letter (HST = H = +7h, MSK = M).
    • Any other character in the zone position is BAD_PARSE.
  • asctime: a month (full name or three letters), one space, a day as D, D or DD, one space, then H:M:S (all three required), one space, and exactly four year digits. Anything after that, including a zone, is ignored.
  • Results: text that does not fit this grammar is BAD_PARSE, and the tick is left untouched. A date or time that parses but is out of range (30 Feb, 25:00, 12:99, year 0) returns 0 without writing the tick, but the offset is still subtracted from the old tick, exactly like the 60th second in sceRtcParseRFC3339 (#1397). Both go through storeParsedTick.

The zone table holds the 47 names that the console mapped to their own offset among the 284 distinct zone tokens I measured. Its values are the console's, even where they differ from the real zones: NST is −2:30, FWT is +2. The TechnicalDebt entry now records only what is still unknown: a name that I did not measure could be in the console's table, and it would get its first letter's offset here instead.

The part of the reviewer's notes on #816 that the console contradicts: it does apply +9999, and it accepts 29 Feb 2024 ... only with a weekday.

Title evidence, stated plainly: the only evidence for this function is #516's statement that The Last of Us Part I needs sceRtcParseDateTime. #516 was merged on that statement alone, with no title ID and no log line. The Propagation: Paradise Hotel dump (PPSA15878) that backs #1397 does not use this function, only sceRtcParseRFC3339. The "title ID and the log line where it stops on main" bar was set for new library functions, and this PR corrects one that is already merged. It may still apply, so I'm flagging it here.

Tested

  • PS5 firmware 13.60: 1174 inputs, all with the same return code and tick on this branch as on the console, for both sceRtcParseDateTime and sceRtcParseRFC3339. Every string the test uses was also run on the console.
  • Linux: build, libs, full CTest 408/408.
  • Windows Server 2025 VM, WinLibs GCC 15.2, CI configure flags: build, libs, CTest 0 failed of 404 (GPU execution tests skipped, the VM has no GPU).
  • Mutation check: 27 mutations of the grammar each make guest_rtc fail. They cover the weekday and month name forms, the comma and whitespace rules, the separators, the year digit count and the 2-digit pivot, the hour limit, the zone and seconds rules, the UT check, the military formula, table entries, and the asctime day and year rules.

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 in TechnicalDebt
  • 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: #1398
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4780850252 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1399). Originally posted by [hugodearaujo](https://github.com/hugodearaujo) on 2026-10-08T02:12:09Z. --- ### What Stacked on #1398, which is itself stacked on #1397: this branch also carries their commits, and only the last commit is new here. In #816 the open question was which shapes the console's `sceRtcParseDateTime` accepts, so returning `SCE_RTC_ERROR_BAD_PARSE` for anything else was left for hardware evidence. This PR is that evidence. I measured 1174 inputs on a PS5 (firmware 13.60) by calling the real `libSceRtc.sprx` export through `dlopen` from a homebrew payload, with the tick preset to `0xdeadbeefcafebabe`. The table and the probe source are in the comments on #1397. With this branch, a host harness gets the same return code and tick as the console for all 1174. 400 of them were random mutations of valid strings that I measured only after the implementation was frozen, and all 400 matched with no changes. Grammar measured after leading spaces and tabs (a digit there goes to the RFC 3339 path from #1398): - **Weekday** is required. It can be the full name or three letters, in any case, and it is never checked against the date. An optional `,` must follow it directly (`Thu ,` and `Thu,,` are BAD_PARSE), then any number of spaces and tabs. A digit next means RFC 2822/850; a letter means asctime. - **RFC 2822 / RFC 850**: the day has 1–2 digits. Then `' '` or `'-'`, a month (full name or three letters, any case, nothing else: `Sept`, `Jun.`, `Janu` are BAD_PARSE), `' '` or `'-'` again, and a year of exactly 2 or 4 digits (00–49 → 20xx, 50–99 → 19xx). Then one space and `H:M[:S]` with 1–2 digit fields; an hour above 25 is BAD_PARSE. - After the seconds, one space starts a zone. Two spaces, a tab, or other text means the zone is ignored, and so is the rest of the string. Without seconds the zone is ignored too (`12:34 EST` is 12:34 UTC). - Zone: `+`/`-` followed by four digits is applied as `HHMM` with no range check (`+9999`, `-12345` → 99:99, 12:34). Anything shorter (`+01:30`, `+1`, `+`) gives offset 0. - A name is matched case-insensitively against the console's table, as a prefix (`ESTERN` = EST, `PST8PDT` = PST). Before that check, the console takes the zone as UT whenever the first character is an upper-case `U` **or** the second is an upper-case `T` (`ET`, `xT`, `Ux` → 0, while `ut` is the military letter u, −7h). - Any other letter uses the console's military table, which is off by one hour against RFC 822: A–I = 0…+8, K–M = +10…+12, N–Y = 0…−11, Z = 0, J = BAD_PARSE. A name that is not in the table uses its first letter (`HST` = H = +7h, `MSK` = M). - Any other character in the zone position is BAD_PARSE. - **asctime**: a month (full name or three letters), one space, a day as `D`, ` D` or `DD`, one space, then `H:M:S` (all three required), one space, and exactly four year digits. Anything after that, including a zone, is ignored. - **Results**: text that does not fit this grammar is BAD_PARSE, and the tick is left untouched. A date or time that parses but is out of range (`30 Feb`, `25:00`, `12:99`, year 0) returns **0 without writing the tick**, but the offset is still subtracted from the old tick, exactly like the 60th second in `sceRtcParseRFC3339` (#1397). Both go through `storeParsedTick`. The zone table holds the 47 names that the console mapped to their own offset among the 284 distinct zone tokens I measured. Its values are the console's, even where they differ from the real zones: `NST` is −2:30, `FWT` is +2. The TechnicalDebt entry now records only what is still unknown: a name that I did not measure could be in the console's table, and it would get its first letter's offset here instead. The part of the reviewer's notes on #816 that the console contradicts: it does apply `+9999`, and it accepts `29 Feb 2024 ...` only with a weekday. **Title evidence, stated plainly:** the only evidence for this function is #516's statement that The Last of Us Part I needs `sceRtcParseDateTime`. #516 was merged on that statement alone, with no title ID and no log line. The Propagation: Paradise Hotel dump (PPSA15878) that backs #1397 does not use this function, only `sceRtcParseRFC3339`. The "title ID and the log line where it stops on main" bar was set for new library functions, and this PR corrects one that is already merged. It may still apply, so I'm flagging it here. ### Tested - PS5 firmware 13.60: 1174 inputs, all with the same return code and tick on this branch as on the console, for both `sceRtcParseDateTime` and `sceRtcParseRFC3339`. Every string the test uses was also run on the console. - Linux: build, `libs`, full CTest 408/408. - Windows Server 2025 VM, WinLibs GCC 15.2, CI configure flags: build, `libs`, CTest 0 failed of 404 (GPU execution tests skipped, the VM has no GPU). - Mutation check: 27 mutations of the grammar each make `guest_rtc` fail. They cover the weekday and month name forms, the comma and whitespace rules, the separators, the year digit count and the 2-digit pivot, the hour limit, the zone and seconds rules, the UT check, the military formula, table entries, and the asctime day and year rules. ### 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 in TechnicalDebt - [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: #1398 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-08 02:12:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-08T02:12:31Z.


Progress report (df16c4c → a156104)

📈 System libraries: 86.18% (+0.04%, +1 implemented functions)

✅ 1 implemented
Library Name
libSceRtc sceRtcParseDateTime
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6050762129 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1399#issuecomment-6050762129). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-08T02:12:31Z. --- <!-- progress-report --> ### Progress report (df16c4c → a156104) 📈 **System libraries**: 86.18% (+0.04%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libSceRtc | `sceRtcParseDateTime` | </details>
hugodearaujo commented 2026-10-08 02:47:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hugodearaujo on 2026-10-08T02:47:55Z.


About the overlap report: #1253, #1306 and #1314 are not dependencies. Each of them inserts a TechnicalDebt line right after s_setkill, which is directly above the sceRtcParseDateTime entry, and this PR has to rewrite that entry (it still says that ISO text without a zone is read as UTC). Git treats the two edits as a conflict only because the lines are adjacent. Code and tests do not overlap. Whichever lands first, I'll rebase the other side. The three shader PRs also overlap with each other at the same spot.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6051142089 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1399#issuecomment-6051142089). Originally posted by [hugodearaujo](https://github.com/hugodearaujo) on 2026-10-08T02:47:55Z. --- About the overlap report: #1253, #1306 and #1314 are not dependencies. Each of them inserts a TechnicalDebt line right after `s_setkill`, which is directly above the `sceRtcParseDateTime` entry, and this PR has to rewrite that entry (it still says that ISO text without a zone is read as UTC). Git treats the two edits as a conflict only because the lines are adjacent. Code and tests do not overlap. Whichever lands first, I'll rebase the other side. The three shader PRs also overlap with each other at the same spot.
adriadam10 commented 2026-10-08 13:05:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T13:05:38Z.


Replayed the 1174 console inputs from the #1397 tables (sceRtcParseDateTime columns) against the parser code from this branch: same return code and tick for all of them. guest_rtc fails with the Export.cpp change reverted, full ctest 455/455 green, CI green (linux, windows, conventions). TechnicalDebt entry is in "Unknown function info" and states what is still unmeasured; merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6060522421 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1399#issuecomment-6060522421). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-08T13:05:38Z. --- Replayed the 1174 console inputs from the #1397 tables (`sceRtcParseDateTime` columns) against the parser code from this branch: same return code and tick for all of them. `guest_rtc` fails with the `Export.cpp` change reverted, full ctest 455/455 green, CI green (linux, windows, conventions). TechnicalDebt entry is in "Unknown function info" and states what is still unmeasured; merging.
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!1399
No description provided.