Fix sceRtcConvertLocalTimeToUtc failing on non-UTC hosts (#210)

The guest local tick was decoded into a DateTimeKind.Utc DateTime and then
passed to TimeZoneInfo.ConvertTimeToUtc together with TimeZoneInfo.Local.
That overload throws ArgumentException when a Utc-kind value is paired with a
source zone other than UTC, so on any machine whose local zone is not UTC the
export caught the exception and always returned INVALID_ARGUMENT.

Re-tag the decoded value as DateTimeKind.Unspecified so it is interpreted as
local wall-clock time and converted correctly. The reverse direction
(sceRtcConvertUtcToLocalTime) was already correct because ConvertTimeFromUtc
accepts a Utc-kind input.

Add a RtcExports unit-test suite covering the tick/calendar conversions, DOS
time packing, Win32 file time, leap-year and validation error codes, and a
regression test that round-trips a UTC tick through local time and back.
This commit is contained in:
can
2026-07-16 00:04:35 +03:00
committed by GitHub
parent 320dbcacba
commit 341c2a0cb6
2 changed files with 337 additions and 0 deletions
+6
View File
@@ -84,6 +84,12 @@ public static class RtcExports
return (int)OrbisGen2Result.ORBIS_GEN2_ERROR_INVALID_ARGUMENT;
}
// TryConvertTickToDateTime yields a Utc-kind DateTime, but here the tick is a local
// wall-clock time. ConvertTimeToUtc throws ArgumentException when a Utc-kind value is
// paired with a non-UTC source zone, so on any host not set to UTC this would always
// fail. Re-tag as Unspecified so the value is interpreted as local time and converted.
localDateTime = DateTime.SpecifyKind(localDateTime, DateTimeKind.Unspecified);
DateTime utcDateTime;
try
{