Don't throw TimeZoneNotFoundExceptions when iOS gives us invalid data.
authorRolf Bjarne Kvinge <rolf@xamarin.com>
Thu, 11 Sep 2014 16:52:43 +0000 (18:52 +0200)
committerRolf Bjarne Kvinge <rolf@xamarin.com>
Thu, 11 Sep 2014 17:04:00 +0000 (19:04 +0200)
iOS 8 GM lists "Asia/Chita" among its time zones, but when requesting
the time zone data for that time zone, no data is returned.

With this change we ignore time zones without any data when fetching
all the timezones on the system.

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

index b0b5faa8af25d4c4b0e3ac8d35308755338fbe3b..70b077de98cd3e1fcf086531ef763ca45f64e486 100644 (file)
@@ -64,12 +64,15 @@ namespace System {
                [DllImport ("__Internal")]
                extern static IntPtr monotouch_timezone_get_data (string name, ref int size);
 
-               static Stream GetMonoTouchData (string name)
+               static Stream GetMonoTouchData (string name, bool throw_on_error = true)
                {
                        int size = 0;
                        IntPtr data = monotouch_timezone_get_data (name, ref size);
-                       if (size <= 0)
-                               throw new TimeZoneNotFoundException ();
+                       if (size <= 0) {
+                               if (throw_on_error)
+                                       throw new TimeZoneNotFoundException ();
+                               return null;
+                       }
 
                        unsafe {
                                var s = new UnmanagedMemoryStream ((byte*) data, size);
index f9422ca9b83b50f6764a53d90aba571650e9f79a..aead18c764f230a9889dc542459b921994681f3a 100644 (file)
@@ -651,7 +651,9 @@ namespace System
 #elif MONOTOUCH
                                if (systemTimeZones.Count == 0) {
                                        foreach (string name in GetMonoTouchNames ()) {
-                                               using (Stream stream = GetMonoTouchData (name)) {
+                                               using (Stream stream = GetMonoTouchData (name, false)) {
+                                                       if (stream == null)
+                                                               continue;
                                                        systemTimeZones.Add (BuildFromStream (name, stream));
                                                }
                                        }