瀏覽代碼

Don't throw TimeZoneNotFoundExceptions when iOS gives us invalid data.

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.
Rolf Bjarne Kvinge 11 年之前
父節點
當前提交
550d314e51

+ 6 - 3
mcs/class/System.Core/System/TimeZoneInfo.MonoTouch.cs

@@ -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);

+ 3 - 1
mcs/class/System.Core/System/TimeZoneInfo.cs

@@ -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));
 						}
 					}