Merge pull request #498 from Unroll-Me/master
[mono.git] / mcs / class / System.Core / System / TimeZoneInfo.cs
index 5e7953b85a5f3b2b8a6757bd0fd7ff6afc3cc6db..e60f85882967096f0351dfc12463c881127a9ae5 100644 (file)
@@ -89,7 +89,7 @@ namespace System
                                        local = ZoneInfoDB.Default;
 #elif MONOTOUCH
                                        using (Stream stream = GetMonoTouchDefault ()) {
-                                               return BuildFromStream ("Local", stream);
+                                               local = BuildFromStream ("Local", stream);
                                        }
 #elif LIBC
                                        try {
@@ -136,7 +136,7 @@ namespace System
                        }
                }
 #if LIBC
-               static string timeZoneDirectory = null;
+               static string timeZoneDirectory;
                static string TimeZoneDirectory {
                        get {
                                if (timeZoneDirectory == null)
@@ -176,7 +176,7 @@ namespace System
                        return str.Substring (Istart, Iend-Istart+1);
                }
                
-               static RegistryKey timeZoneKey = null;
+               static RegistryKey timeZoneKey;
                static RegistryKey TimeZoneKey {
                        get {
                                if (timeZoneKey != null)
@@ -190,7 +190,7 @@ namespace System
                        }
                }
                
-               static RegistryKey localZoneKey = null;
+               static RegistryKey localZoneKey;
                static RegistryKey LocalZoneKey {
                        get {
                                if (localZoneKey != null)
@@ -220,10 +220,10 @@ namespace System
                public static DateTime ConvertTime (DateTime dateTime, TimeZoneInfo sourceTimeZone, TimeZoneInfo destinationTimeZone)
                {
                        if (dateTime.Kind == DateTimeKind.Local && sourceTimeZone != TimeZoneInfo.Local)
-                               throw new ArgumentException ("Kind propery of dateTime is Local but the sourceTimeZone does not equal TimeZoneInfo.Local");
+                               throw new ArgumentException ("Kind property of dateTime is Local but the sourceTimeZone does not equal TimeZoneInfo.Local");
 
                        if (dateTime.Kind == DateTimeKind.Utc && sourceTimeZone != TimeZoneInfo.Utc)
-                               throw new ArgumentException ("Kind propery of dateTime is Utc but the sourceTimeZone does not equal TimeZoneInfo.Utc");
+                               throw new ArgumentException ("Kind property of dateTime is Utc but the sourceTimeZone does not equal TimeZoneInfo.Utc");
 
                        if (sourceTimeZone.IsInvalidTime (dateTime))
                                throw new ArgumentException ("dateTime parameter is an invalid time");
@@ -309,10 +309,10 @@ namespace System
                                throw new ArgumentNullException ("sourceTimeZone");
 
                        if (dateTime.Kind == DateTimeKind.Utc && sourceTimeZone != TimeZoneInfo.Utc)
-                               throw new ArgumentException ("Kind propery of dateTime is Utc but the sourceTimeZone does not equal TimeZoneInfo.Utc");
+                               throw new ArgumentException ("Kind property of dateTime is Utc but the sourceTimeZone does not equal TimeZoneInfo.Utc");
 
                        if (dateTime.Kind == DateTimeKind.Local && sourceTimeZone != TimeZoneInfo.Local)
-                               throw new ArgumentException ("Kind propery of dateTime is Local but the sourceTimeZone does not equal TimeZoneInfo.Local");
+                               throw new ArgumentException ("Kind property of dateTime is Local but the sourceTimeZone does not equal TimeZoneInfo.Local");
 
                        if (sourceTimeZone.IsInvalidTime (dateTime))
                                throw new ArgumentException ("dateTime parameter is an invalid time");
@@ -382,7 +382,10 @@ namespace System
                        }
 #endif
 #if MONODROID
-                       return ZoneInfoDB.GetTimeZone (id);
+                       var timeZoneInfo = ZoneInfoDB.GetTimeZone (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")
@@ -587,7 +590,7 @@ namespace System
                }
 
                //FIXME: change this to a generic Dictionary and allow caching for FindSystemTimeZoneById
-               private static List<TimeZoneInfo> systemTimeZones = null;
+               private static List<TimeZoneInfo> systemTimeZones;
                public static ReadOnlyCollection<TimeZoneInfo> GetSystemTimeZones ()
                {
                        if (systemTimeZones == null) {
@@ -605,7 +608,9 @@ namespace System
 #endif
 #if MONODROID
                        foreach (string id in ZoneInfoDB.GetAvailableIds ()) {
-                               systemTimeZones.Add (ZoneInfoDB.GetTimeZone (id));
+                               var tz = ZoneInfoDB.GetTimeZone (id);
+                               if (tz != null)
+                                       systemTimeZones.Add (tz);
                        }
 #elif MONOTOUCH
                                if (systemTimeZones.Count == 0) {