[mscorlib/Android] TimeZoneInfo.Local.Id should be "Local".
authorJonathan Pryor <jonpryor@vt.edu>
Fri, 24 Oct 2014 19:41:20 +0000 (15:41 -0400)
committerJonathan Pryor <jonpryor@vt.edu>
Fri, 24 Oct 2014 19:56:13 +0000 (15:56 -0400)
On Mono/.NET, TimeZoneInfo.Local has a TimeZoneInfo.Id value of
"Local" and a TimeZoneInfo.DisplayName value of "Local":

$ csharp
csharp> TimeZoneInfo.Local.Id;
"Local"
csharp> TimeZoneInfo.Local.DisplayName;
"Local"

That isn't the case on Xamarin.Android, which returns the timezoneinfo
ID value from both DisplayName and Id, e.g. TimeZoneInfo.Local could
have Id and DisplayName values of "Australia/Sydney".

Rework things so that the TimeZoneInfo.Id and TimeZoneInfo.DisplayName
properties return "Local" on Xamarin.Android for the instance returned
from TimeZoneInfo.Local, just like normal Mono/.NET does.

mcs/class/System.Core/System/TimeZoneInfo.Android.cs
mcs/class/System.Core/System/TimeZoneInfo.cs

index bd35e657343646b39de3a0cda9448ba17d45297e..079af3722d6cc9b4882304c15ee1a750aad7bc31 100644 (file)
@@ -453,29 +453,29 @@ namespace System {
                                        : db.GetAvailableIds ();
                        }
 
-                       static TimeZoneInfo _GetTimeZone (string name)
+                       static TimeZoneInfo _GetTimeZone (string id, string name)
                        {
                                if (db == null)
                                        return null;
                                byte[] buffer = db.GetTimeZoneData (name);
                                if (buffer == null)
                                        return null;
-                               return TimeZoneInfo.ParseTZBuffer (name, buffer, buffer.Length);
+                               return TimeZoneInfo.ParseTZBuffer (id, buffer, buffer.Length);
                        }
 
-                       internal static TimeZoneInfo GetTimeZone (string id)
+                       internal static TimeZoneInfo GetTimeZone (string id, string name)
                        {
-                               if (id != null) {
-                                       if (id == "GMT" || id == "UTC")
-                                               return new TimeZoneInfo (id, TimeSpan.FromSeconds (0), id, id, id, null, true);
-                                       if (id.StartsWith ("GMT"))
+                               if (name != null) {
+                                       if (name == "GMT" || name == "UTC")
+                                               return new TimeZoneInfo (id, TimeSpan.FromSeconds (0), id, name, name, null, disableDaylightSavingTime:true);
+                                       if (name.StartsWith ("GMT"))
                                                return new TimeZoneInfo (id,
-                                                               TimeSpan.FromSeconds (ParseNumericZone (id)),
-                                                               id, id, id, null, true);
+                                                               TimeSpan.FromSeconds (ParseNumericZone (name)),
+                                                               id, name, name, null, disableDaylightSavingTime:true);
                                }
 
                                try {
-                                       return _GetTimeZone (id);
+                                       return _GetTimeZone (id, name);
                                } catch (Exception) {
                                        return null;
                                }
@@ -533,12 +533,12 @@ namespace System {
                        static readonly object _lock = new object ();
 
                        static TimeZoneInfo defaultZone;
-                       internal static TimeZoneInfo Default {
+                       internal static TimeZoneInfo Local {
                                get {
                                        lock (_lock) {
                                                if (defaultZone != null)
                                                        return defaultZone;
-                                               return defaultZone = GetTimeZone (GetDefaultTimeZoneName ());
+                                               return defaultZone = GetTimeZone ("Local", GetDefaultTimeZoneName ());
                                        }
                                }
                        }
@@ -617,7 +617,7 @@ namespace System {
                                foreach (var id in GetAvailableIds ()) {
                                        Console.Write ("name={0,-40}", id);
                                        try {
-                                               TimeZoneInfo zone = _GetTimeZone (id);
+                                               TimeZoneInfo zone = _GetTimeZone (id, id);
                                                if (zone != null) {
                                                        Console.Write (" {0,-40}", zone);
                                                        if (offset.HasValue) {
index aead18c764f230a9889dc542459b921994681f3a..9994b125c79a47e7e8d4b501a477817cad94d4e7 100644 (file)
@@ -103,7 +103,7 @@ namespace System
                static TimeZoneInfo CreateLocal ()
                {
 #if MONODROID
-                       return AndroidTimeZones.Default;
+                       return AndroidTimeZones.Local;
 #elif MONOTOUCH
                        using (Stream stream = GetMonoTouchData (null)) {
                                return BuildFromStream ("Local", stream);
@@ -415,7 +415,7 @@ namespace System
                        }
 #endif
 #if MONODROID
-                       var timeZoneInfo = AndroidTimeZones.GetTimeZone (id);
+                       var timeZoneInfo = AndroidTimeZones.GetTimeZone (id, id);
                        if (timeZoneInfo == null)
                                throw new TimeZoneNotFoundException ();
                        return timeZoneInfo;
@@ -644,7 +644,7 @@ namespace System
 #endif
 #if MONODROID
                        foreach (string id in AndroidTimeZones.GetAvailableIds ()) {
-                               var tz = AndroidTimeZones.GetTimeZone (id);
+                               var tz = AndroidTimeZones.GetTimeZone (id, id);
                                if (tz != null)
                                        systemTimeZones.Add (tz);
                        }