Skip to content

Commit 7998c18

Browse files
authored
Merge pull request #1118 from Unity-Technologies/unity-master-fix-win32-timezone
Attempt to use Win32 APIs first to retreive current timezone (case 1076679)
2 parents cd56f3c + 2a5df50 commit 7998c18

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

mcs/class/corlib/System/TimeZoneInfo.WinRT.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ internal struct DYNAMIC_TIME_ZONE_INFORMATION
6666
internal extern static uint EnumDynamicTimeZoneInformation (uint dwIndex, out DYNAMIC_TIME_ZONE_INFORMATION lpTimeZoneInformation);
6767
[DllImport ("api-ms-win-core-timezone-l1-1-0.dll")]
6868
internal extern static uint GetDynamicTimeZoneInformation (out DYNAMIC_TIME_ZONE_INFORMATION pTimeZoneInformation);
69+
[DllImport ("kernel32.dll", EntryPoint="GetDynamicTimeZoneInformation")]
70+
internal extern static uint GetDynamicTimeZoneInformationWin32 (out DYNAMIC_TIME_ZONE_INFORMATION pTimeZoneInformation);
6971
[DllImport ("api-ms-win-core-timezone-l1-1-0.dll")]
7072
internal extern static uint GetDynamicTimeZoneInformationEffectiveYears(ref DYNAMIC_TIME_ZONE_INFORMATION lpTimeZoneInformation, out uint FirstYear, out uint LastYear);
7173
[DllImport ("api-ms-win-core-timezone-l1-1-0.dll")]
@@ -310,6 +312,24 @@ internal static TimeZoneInfo GetLocalTimeZoneInfoWinRTFallback ()
310312
return timeZoneInfo != null ? timeZoneInfo : Utc;
311313
} catch {
312314
return Utc;
315+
316+
}
317+
}
318+
319+
internal static string GetLocalTimeZoneKeyNameWin32Fallback ()
320+
{
321+
try {
322+
DYNAMIC_TIME_ZONE_INFORMATION dtzi;
323+
var result = GetDynamicTimeZoneInformationWin32 (out dtzi);
324+
if (result == TIME_ZONE_ID_INVALID)
325+
return null;
326+
if (!string.IsNullOrEmpty(dtzi.TimeZoneKeyName))
327+
return dtzi.TimeZoneKeyName;
328+
else if (!string.IsNullOrEmpty(dtzi.TZI.StandardName))
329+
return dtzi.TZI.StandardName;
330+
return null;
331+
} catch {
332+
return null;
313333
}
314334
}
315335

mcs/class/corlib/System/TimeZoneInfo.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ static TimeZoneInfo CreateLocal ()
162162
if (name == null)
163163
name = (string)LocalZoneKey.GetValue ("StandardName"); // windows xp
164164
name = TrimSpecial (name);
165+
if (string.IsNullOrEmpty(name))
166+
name = GetLocalTimeZoneKeyNameWin32Fallback();
165167
if (name != null)
166168
return TimeZoneInfo.FindSystemTimeZoneById (name);
167169
} else if (IsWindows) {

0 commit comments

Comments
 (0)