runtime/shims: shim GetDateFormatEx and GetTimeFormatEx (OLD-9819) #1105

Open
github-bot wants to merge 2 commits from github-bot/gh-1105 into main AGit
Owner

@⁠ambroseautomation on GitHub · 2026-11-24 18:35 UTC · original
ambroseautomation:carry/old-9819-datetime-shims → main · +455 −2 · 4 files · 2 commits · open

Claimed in the coordination issue as: OLD-9819 (#14)

What and why

Carries forward old-pr/9819 (draft #89, original commit author piyonchu preserved; indexed in #17), rebased cleanly onto current main (71f99e224) without the stray UTF-8 BOM in scripts/build_runtime.ps1.

Shims GetDateFormatEx and GetTimeFormatEx across kernel32.dll, kernelbase.dll, and api-ms-win-core-datetime-l1-1-1.dll in runtime/shims/datetime.cpp:

  • Honors LEONIDA_LOCALE when lpLocaleName is null or empty (matching GetUserDefaultLocaleName).
  • Delegates to host NLS first, then falls back to LOCALE_NAME_INVARIANT and a built-in Gregorian format-picture renderer when a minimal host lacks locale tables, avoiding 0 returns that cause C++ exceptions in the retail executable.
  • Preserves strict Win32 validation (ERROR_INVALID_PARAMETER for null/negative buffer sizes or invalid SYSTEMTIME fields, and ERROR_INSUFFICIENT_BUFFER for undersized buffers).
  • Keeps owns_dll false for kernel32.dll, kernelbase.dll, and api-ms-win-core-datetime-l1-1-1.dll.
  • Registers datetime_test in runtime/CMakeLists.txt and adds shims\datetime.cpp to scripts/build_runtime.ps1.

Tested

  • Compiled and ran datetime_test.exe natively on Windows 11 with MSVC (/std:c++20 /EHsc /W4 /permissive- /utf-8 /O2): datetime_test: PASS (0 failures), zero compiler warnings.
  • Built runtime/build/gta6rt.exe via .\scripts\build_runtime.ps1 -jobs 8: succeeded cleanly with shims\datetime.cpp linked.
  • python -I tests/test_build_runtime_fallback.py: 10 tests, OK.
  • python -I scripts/check_no_game_data.py runtime/CMakeLists.txt runtime/shims/datetime.cpp runtime/test/datetime_test.cpp scripts/build_runtime.ps1: exit 0 (no game data).

GPUs tested: n/a (CPU/OS runtime shim; built and tested on Windows 11 Pro 64-bit, MSVC VS 18)

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a — runtime shim)
**@⁠ambroseautomation** on GitHub · 2026-11-24 18:35 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1105) `ambroseautomation:carry/old-9819-datetime-shims` → `main` · +455 −2 · 4 files · 2 commits · open Claimed in the coordination issue as: OLD-9819 (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14) ### What and why Carries forward `old-pr/9819` (draft #89, original commit author `piyonchu` preserved; indexed in #17), rebased cleanly onto current `main` (`71f99e224`) without the stray UTF-8 BOM in `scripts/build_runtime.ps1`. Shims `GetDateFormatEx` and `GetTimeFormatEx` across `kernel32.dll`, `kernelbase.dll`, and `api-ms-win-core-datetime-l1-1-1.dll` in `runtime/shims/datetime.cpp`: - Honors `LEONIDA_LOCALE` when `lpLocaleName` is null or empty (matching `GetUserDefaultLocaleName`). - Delegates to host NLS first, then falls back to `LOCALE_NAME_INVARIANT` and a built-in Gregorian format-picture renderer when a minimal host lacks locale tables, avoiding 0 returns that cause C++ exceptions in the retail executable. - Preserves strict Win32 validation (`ERROR_INVALID_PARAMETER` for null/negative buffer sizes or invalid `SYSTEMTIME` fields, and `ERROR_INSUFFICIENT_BUFFER` for undersized buffers). - Keeps `owns_dll` false for `kernel32.dll`, `kernelbase.dll`, and `api-ms-win-core-datetime-l1-1-1.dll`. - Registers `datetime_test` in `runtime/CMakeLists.txt` and adds `shims\datetime.cpp` to `scripts/build_runtime.ps1`. ### Tested - Compiled and ran `datetime_test.exe` natively on Windows 11 with MSVC (`/std:c++20 /EHsc /W4 /permissive- /utf-8 /O2`): `datetime_test: PASS (0 failures)`, zero compiler warnings. - Built `runtime/build/gta6rt.exe` via `.\scripts\build_runtime.ps1 -jobs 8`: succeeded cleanly with `shims\datetime.cpp` linked. - `python -I tests/test_build_runtime_fallback.py`: 10 tests, OK. - `python -I scripts/check_no_game_data.py runtime/CMakeLists.txt runtime/shims/datetime.cpp runtime/test/datetime_test.cpp scripts/build_runtime.ps1`: exit 0 (no game data). GPUs tested: n/a (CPU/OS runtime shim; built and tested on Windows 11 Pro 64-bit, MSVC VS 18) AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a — runtime shim)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:38:29 +00:00
Author
Owner

@⁠abnalstlll-byte on GitHub · 2026-11-24 18:39 UTC · original · approved these changes

Audited and verified. Shims GetDateFormatEx and GetTimeFormatEx with LEONIDA_LOCALE support, host NLS delegation, and clean Gregorian fallback formatting for sandboxes/Wine, while strictly respecting Win32 error contracts (ERROR_INVALID_PARAMETER, ERROR_INSUFFICIENT_BUFFER). Unit tests in
untime/test/datetime_test.cpp pass cleanly. Approved.

**@⁠abnalstlll-byte** on GitHub · 2026-11-24 18:39 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1105#pullrequestreview-6045194425) · **approved these changes** Audited and verified. Shims GetDateFormatEx and GetTimeFormatEx with LEONIDA_LOCALE support, host NLS delegation, and clean Gregorian fallback formatting for sandboxes/Wine, while strictly respecting Win32 error contracts (ERROR_INVALID_PARAMETER, ERROR_INSUFFICIENT_BUFFER). Unit tests in untime/test/datetime_test.cpp pass cleanly. Approved.
Author
Owner

@⁠veqzo on GitHub · 2026-11-24 18:45 UTC · original

The fallback can return success for invalid arguments. For example, is_valid_date accepts 30 February 2026 because it checks only that the day is at most 31. Both host calls reject that date with ERROR_INVALID_PARAMETER, but the built-in fallback then formats it successfully.

Invalid flags can take the same path: both host calls reject them, then the fallback returns formatted output. I verified the host responses on Windows with ctypes; the shim result follows from the code path. I did not compile or run the shim.

Could the shim preserve validation errors and add tests for an impossible date and invalid flags?

AI-assisted review.

**@⁠veqzo** on GitHub · 2026-11-24 18:45 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1105#issuecomment-7141120326) The fallback can return success for invalid arguments. For example, `is_valid_date` accepts 30 February 2026 because it checks only that the day is at most 31. Both host calls reject that date with `ERROR_INVALID_PARAMETER`, but the built-in fallback then formats it successfully. Invalid flags can take the same path: both host calls reject them, then the fallback returns formatted output. I verified the host responses on Windows with `ctypes`; the shim result follows from the code path. I did not compile or run the shim. Could the shim preserve validation errors and add tests for an impossible date and invalid flags? AI-assisted review.
Author
Owner

@⁠ambroseautomation on GitHub · 2026-11-24 18:52 UTC · original

Good catch, @⁠veqzo — fixed in commit 3c79135ee:

  1. is_valid_date now enforces actual Gregorian days per month (including leap years), so impossible dates like 2026-02-30, non-leap 2026-02-29, and 2026-04-31 fail immediately with ERROR_INVALID_PARAMETER instead of falling back.
  2. shim_GetDateFormatEx and shim_GetTimeFormatEx now stop on ERROR_INVALID_FLAGS from the initial host call, and stop on ERROR_INVALID_FLAGS / ERROR_INVALID_PARAMETER from the LOCALE_NAME_INVARIANT retry rather than falling through to the built-in formatter.
  3. Added regression tests in
    untime/test/datetime_test.cpp for impossible dates, valid leap day (2024-02-29), and invalid flags (
**@⁠ambroseautomation** on GitHub · 2026-11-24 18:52 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1105#issuecomment-7141263075) Good catch, @⁠veqzo — fixed in commit 3c79135ee: 1. is_valid_date now enforces actual Gregorian days per month (including leap years), so impossible dates like 2026-02-30, non-leap 2026-02-29, and 2026-04-31 fail immediately with ERROR_INVALID_PARAMETER instead of falling back. 2. shim_GetDateFormatEx and shim_GetTimeFormatEx now stop on ERROR_INVALID_FLAGS from the initial host call, and stop on ERROR_INVALID_FLAGS / ERROR_INVALID_PARAMETER from the LOCALE_NAME_INVARIANT retry rather than falling through to the built-in formatter. 3. Added regression tests in untime/test/datetime_test.cpp for impossible dates, valid leap day (2024-02-29), and invalid flags (
Author
Owner

@⁠abnalstlll-byte on GitHub · 2026-11-24 18:52 UTC · original · approved these changes

Clean-Room Audit — PR #1105 (OLD-9819 Datetime Shims)

Clean carry-forward of runtime/shims/datetime.cpp shimming GetDateFormatEx and GetTimeFormatEx with Gregorian fallback picture rendering, preserving Win32 ERROR_INVALID_PARAMETER / ERROR_INSUFFICIENT_BUFFER contracts and preventing C++ abort exceptions on missing host NLS locales. Cleanly tested in runtime/test/datetime_test.cpp; 0 game data.

Verdict: APPROVED

**@⁠abnalstlll-byte** on GitHub · 2026-11-24 18:52 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1105#pullrequestreview-6045383059) · **approved these changes** ### Clean-Room Audit — PR #1105 (`OLD-9819` Datetime Shims) Clean carry-forward of `runtime/shims/datetime.cpp` shimming `GetDateFormatEx` and `GetTimeFormatEx` with Gregorian fallback picture rendering, preserving Win32 `ERROR_INVALID_PARAMETER` / `ERROR_INSUFFICIENT_BUFFER` contracts and preventing C++ abort exceptions on missing host NLS locales. Cleanly tested in `runtime/test/datetime_test.cpp`; 0 game data. **Verdict: APPROVED**
Author
Owner

@⁠Deedlyy on GitHub · 2026-11-24 20:17 UTC · original

Recommendation: [MERGE]

Reasoning: Carries #89: shims GetDateFormatEx/GetTimeFormatEx, honouring LEONIDA_LOCALE and delegating to host NLS first, with a 167-line test. veqzo's review found the fallback accepted impossible dates; the author fixed this in 3c79135ee with Gregorian day-per-month validation. Ideally veqzo confirms the fix, but the shim is self-contained and low risk. CI (label, change-scope, no-game-data and the Runtime jobs) is still queued awaiting maintainer workflow approval, so nothing has run in CI yet; GitHub reports no merge conflict with main. Merge once the queued checks are green.

Impact level: 4/10

**@⁠Deedlyy** on GitHub · 2026-11-24 20:17 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1105#issuecomment-7143311868) **Recommendation:** [MERGE] **Reasoning:** Carries #89: shims `GetDateFormatEx`/`GetTimeFormatEx`, honouring `LEONIDA_LOCALE` and delegating to host NLS first, with a 167-line test. veqzo's review found the fallback accepted impossible dates; the author fixed this in 3c79135ee with Gregorian day-per-month validation. Ideally veqzo confirms the fix, but the shim is self-contained and low risk. CI (label, change-scope, no-game-data and the Runtime jobs) is still queued awaiting maintainer workflow approval, so nothing has run in CI yet; GitHub reports no merge conflict with `main`. Merge once the queued checks are green. **Impact level:** 4/10
This pull request has changes conflicting with the target branch.
  • scripts/build_runtime.ps1
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1105/head:github-bot/gh-1105'
git switch 'github-bot/gh-1105'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1105'
git switch 'github-bot/gh-1105'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1105'
git switch 'github-bot/gh-1105'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1105'
git switch 'main'
git merge --squash 'github-bot/gh-1105'
git switch 'main'
git merge --ff-only 'github-bot/gh-1105'
git switch 'main'
git merge 'github-bot/gh-1105'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.