[PR #1105] runtime/shims: shim GetDateFormatEx and GetTimeFormatEx (OLD-9819) #1142

Open
opened 2026-11-26 20:20:13 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1105
Author: @ambroseautomation
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: carry/old-9819-datetime-shims


📝 Commits (2)

  • 9577387 runtime/shims: shim GetDateFormatEx and GetTimeFormatEx
  • 92bfacd runtime/shims: reject impossible dates and preserve validation errors in datetime shims

📊 Changes

4 files changed (+455 additions, -2 deletions)

View changed files

📝 runtime/CMakeLists.txt (+14 -0)
➕ runtime/shims/datetime.cpp (+272 -0)
➕ runtime/test/datetime_test.cpp (+167 -0)
📝 scripts/build_runtime.ps1 (+2 -2)

📄 Description

Claimed in the coordination issue as: OLD-9819 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7140822595)

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)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1105 **Author:** [@ambroseautomation](https://github.com/ambroseautomation) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `carry/old-9819-datetime-shims` --- ### 📝 Commits (2) - [`9577387`](https://github.com/ubiquitarianism/leonida/commit/9577387df02d9be58bfde1ca0e7314a8f0a52f88) runtime/shims: shim GetDateFormatEx and GetTimeFormatEx - [`92bfacd`](https://github.com/ubiquitarianism/leonida/commit/92bfacde60fb509401bae4699f8fb94f1ae5d1c7) runtime/shims: reject impossible dates and preserve validation errors in datetime shims ### 📊 Changes **4 files changed** (+455 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `runtime/CMakeLists.txt` (+14 -0) ➕ `runtime/shims/datetime.cpp` (+272 -0) ➕ `runtime/test/datetime_test.cpp` (+167 -0) 📝 `scripts/build_runtime.ps1` (+2 -2) </details> ### 📄 Description Claimed in the coordination issue as: OLD-9819 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7140822595) ### 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) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#1142
No description provided.