[mscorlib/Android] Support TimeZoneInfo.FindSystemTimeZoneById("Local")
authorJonathan Pryor <jonpryor@vt.edu>
Wed, 3 Dec 2014 16:15:41 +0000 (11:15 -0500)
committerJonathan Pryor <jonpryor@vt.edu>
Wed, 3 Dec 2014 16:25:29 +0000 (11:25 -0500)
Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=24741

Xamarin.Android didn't previously support
TimeZoneInfo.FindSystemTimeZoneById("Local") because of oversight (and
overly nested #if conditionals).

Compare `id` against "Local" *before* doing platform-specific
codepaths so that finding the "Local" TimeZone works as expected on
Xamarin.Android, and merge the `#if MONODROID` with the existing code.

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

index 9e169efc579d5157f5e27c62284137072d99aacc..2b36c15e30f42f69854085c2aff296cf21bd0974 100644 (file)
@@ -424,12 +424,6 @@ namespace System
                                return FromRegistryKey(id, key);
                        }
 #endif
-#if MONODROID
-                       var timeZoneInfo = AndroidTimeZones.GetTimeZone (id, id);
-                       if (timeZoneInfo == null)
-                               throw new TimeZoneNotFoundException ();
-                       return timeZoneInfo;
-#else
                        // Local requires special logic that already exists in the Local property (bug #326)
                        if (id == "Local")
                                return Local;
@@ -437,12 +431,16 @@ namespace System
                        using (Stream stream = GetMonoTouchData (id)) {
                                return BuildFromStream (id, stream);
                        }
+#elif MONODROID
+                       var timeZoneInfo = AndroidTimeZones.GetTimeZone (id, id);
+                       if (timeZoneInfo == null)
+                               throw new TimeZoneNotFoundException ();
+                       return timeZoneInfo;
 #elif LIBC
                        string filepath = Path.Combine (TimeZoneDirectory, id);
                        return FindSystemTimeZoneByFileName (id, filepath);
 #else
                        throw new NotImplementedException ();
-#endif
 #endif
                }