From 537fc4b60d0783dc260b4b26b64d1fd03db52cc8 Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Thu, 11 Jul 2019 17:45:03 -0400 Subject: [PATCH] [ios] Ensure Local TimeZone Id is Set For TimeZoneInfo.Local (#15667) * Fixes https://github.com/mono/mono/issues/14839 The local timezone name was not known and defaulted to "Local". This change adds an sdk function that returns the local name. --- mcs/class/corlib/System/TimeZoneInfo.MonoTouch.cs | 7 +++++-- mcs/class/corlib/Test/System/TimeZoneInfoTest.cs | 6 +++--- sdks/ios/runtime/runtime.m | 16 ++++++++++++++++ 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/mcs/class/corlib/System/TimeZoneInfo.MonoTouch.cs b/mcs/class/corlib/System/TimeZoneInfo.MonoTouch.cs index ba161b3f2e2..49b682b8a9b 100644 --- a/mcs/class/corlib/System/TimeZoneInfo.MonoTouch.cs +++ b/mcs/class/corlib/System/TimeZoneInfo.MonoTouch.cs @@ -44,10 +44,13 @@ namespace System { public partial class TimeZoneInfo { + [DllImport ("__Internal")] + extern static string xamarin_timezone_get_local_name (); + static TimeZoneInfo CreateLocal () { using (Stream stream = GetMonoTouchData (null)) { - return BuildFromStream ("Local", stream); + return BuildFromStream (xamarin_timezone_get_local_name (), stream); } } @@ -68,7 +71,7 @@ namespace System { } } } - + [DllImport ("__Internal")] extern static IntPtr xamarin_timezone_get_names (ref int count); diff --git a/mcs/class/corlib/Test/System/TimeZoneInfoTest.cs b/mcs/class/corlib/Test/System/TimeZoneInfoTest.cs index 9f7340d3d15..9f14e72e712 100644 --- a/mcs/class/corlib/Test/System/TimeZoneInfoTest.cs +++ b/mcs/class/corlib/Test/System/TimeZoneInfoTest.cs @@ -121,6 +121,7 @@ namespace MonoTests.System [Test] // Covers #24958 public void LocalId () { +#if !MONOTOUCH && !XAMMAC byte[] buf = new byte [512]; var path = "/etc/localtime"; @@ -131,10 +132,9 @@ namespace MonoTests.System } catch (DllNotFoundException e) { return; } -#if !MONOTOUCH && !XAMMAC - // this assumption is incorrect for the TimeZoneInfo.MonoTouch.cs implementation (iOS, tvOS, watchOS and XamMac Modern) - Assert.IsTrue (TimeZoneInfo.Local.Id != "Local", "Local timezone id should not be \"Local\""); #endif + + Assert.IsTrue (TimeZoneInfo.Local.Id != "Local", "Local timezone id should not be \"Local\""); } } diff --git a/sdks/ios/runtime/runtime.m b/sdks/ios/runtime/runtime.m index 16770da5da5..76c7377745f 100644 --- a/sdks/ios/runtime/runtime.m +++ b/sdks/ios/runtime/runtime.m @@ -337,6 +337,10 @@ mono_ios_runtime_init (void) // // ICALLS used by the mobile profile of mscorlib // +// NOTE: The timezone functions are duplicated in XI, so if you're going to modify here, you have to +// modify there. +// +// See in XI runtime/xamarin-support.m void* xamarin_timezone_get_data (const char *name, int *size) @@ -355,6 +359,18 @@ xamarin_timezone_get_data (const char *name, int *size) return result; } +// +// Returns the geopolitical region ID of the local timezone. + +const char * +xamarin_timezone_get_local_name () +{ + NSTimeZone *tz = nil; + tz = [NSTimeZone localTimeZone]; + NSString *name = [tz name]; + return strdup ([name UTF8String]); +} + char** xamarin_timezone_get_names (int *count) { -- 2.11.4.GIT