Merge pull request #2003 from esdrubal/seq_test_fix2
[mono.git] / mcs / class / corlib / System / TimeZoneInfo.MonoTouch.cs
index 626136bb45ab36f27c25b5aa0e3eed11a4e92ac0..ba161b3f2e2f37856954f3f1be325ab10f286ee3 100644 (file)
@@ -32,7 +32,7 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-#if MONOTOUCH
+#if MONOTOUCH || XAMMAC
 
 using System;
 using System.Collections.Generic;
@@ -43,14 +43,39 @@ using System.Runtime.InteropServices;
 namespace System {
 
        public partial class TimeZoneInfo {
+
+               static TimeZoneInfo CreateLocal ()
+               {
+                       using (Stream stream = GetMonoTouchData (null)) {
+                               return BuildFromStream ("Local", stream);
+                       }
+               }
+
+               static TimeZoneInfo FindSystemTimeZoneByIdCore (string id)
+               {
+                       using (Stream stream = GetMonoTouchData (id)) {
+                               return BuildFromStream (id, stream);
+                       }
+               }
+
+               static void GetSystemTimeZonesCore (List<TimeZoneInfo> systemTimeZones)
+               {
+                       foreach (string name in GetMonoTouchNames ()) {
+                               using (Stream stream = GetMonoTouchData (name, false)) {
+                                       if (stream == null)
+                                               continue;
+                                       systemTimeZones.Add (BuildFromStream (name, stream));
+                               }
+                       }
+               }
                
                [DllImport ("__Internal")]
-               extern static IntPtr monotouch_timezone_get_names (ref int count);
+               extern static IntPtr xamarin_timezone_get_names (ref int count);
 
                static ReadOnlyCollection<string> GetMonoTouchNames ()
                {
                        int count = 0;
-                       IntPtr array = monotouch_timezone_get_names (ref count);
+                       IntPtr array = xamarin_timezone_get_names (ref count);
                        string [] names = new string [count];
                        for (int i = 0, offset = 0; i < count; i++, offset += IntPtr.Size) {
                                IntPtr p = Marshal.ReadIntPtr (array, offset);
@@ -62,24 +87,20 @@ namespace System {
                }
 
                [DllImport ("__Internal")]
-               extern static IntPtr monotouch_timezone_get_data (string name, ref int size);
+               extern static IntPtr xamarin_timezone_get_data (string name, ref int size);
 
                static Stream GetMonoTouchData (string name, bool throw_on_error = true)
                {
                        int size = 0;
-                       IntPtr data = monotouch_timezone_get_data (name, ref size);
+                       IntPtr data = xamarin_timezone_get_data (name, ref size);
                        if (size <= 0) {
                                if (throw_on_error)
-                                       throw new TimeZoneNotFoundException ();
+                                       throw new TimeZoneNotFoundException (name);
                                return null;
                        }
 
                        unsafe {
-                               var s = new UnmanagedMemoryStream ((byte*) data, size);
-                               s.Closed += delegate {
-                                       Marshal.FreeHGlobal (data);
-                               };
-                               return s;
+                               return new HGlobalUnmanagedMemoryStream ((byte*) data, size, data);
                        }
                }
        }