Skip to content

Commit

Permalink
Use GetTimeZoneInformation to find the current timezone.
Browse files Browse the repository at this point in the history
For wine bug 37760.
  • Loading branch information
Vincent Povirk committed Feb 27, 2015
1 parent fd4d69f commit 8a91a10
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions mcs/class/System.Core/System/TimeZoneInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;

#if !INSIDE_CORLIB && NET_4_0
Expand Down Expand Up @@ -108,6 +109,34 @@ sealed partial class TimeZoneInfo : IEquatable<TimeZoneInfo>, ISerializable, IDe
*/
private List<KeyValuePair<DateTime, TimeType>> transitions;

[StructLayout(LayoutKind.Sequential)]
private struct SYSTEMTIME {
short wYear;
short wMonth;
short wDayOfWeek;
short wDay;
short wHour;
short wMinute;
short wSecond;
short wMilliseconds;
}

[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
private struct TIME_ZONE_INFORMATION {
internal int Bias;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=32)]
internal string StandardName;
internal SYSTEMTIME StandardDate;
internal int StandardBias;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=32)]
internal string DaylightName;
internal SYSTEMTIME DaylightDate;
internal int DaylightBias;
}

[DllImport ("kernel32.dll", CallingConvention=CallingConvention.StdCall)]
private extern static uint GetTimeZoneInformation(out TIME_ZONE_INFORMATION tzi);

static TimeZoneInfo CreateLocal ()
{
#if MONODROID
Expand All @@ -118,10 +147,17 @@ static TimeZoneInfo CreateLocal ()
}
#else
if (IsWindows && LocalZoneKey != null) {
/* Wine Mono hack: Wine doesn't set TimeZoneKeyName, so use
GetTimeZoneInformation to get the name. This may not quite be
correct because StandardName isn't the same as TimeZoneKeyName,
but it is for all builtin Wine timezones at least.
string name = (string)LocalZoneKey.GetValue ("TimeZoneKeyName");
name = TrimSpecial (name);
if (name != null)
return TimeZoneInfo.FindSystemTimeZoneById (name);
if (name != null) */
TIME_ZONE_INFORMATION tzi;
if (GetTimeZoneInformation(out tzi) <= 2)
return TimeZoneInfo.FindSystemTimeZoneById (tzi.StandardName);
}

var tz = Environment.GetEnvironmentVariable ("TZ");
Expand Down

0 comments on commit 8a91a10

Please sign in to comment.