Browse Source

[mscorlib/Android] TimeZoneInfo.Local.Id should be "Local".

On Mono/.NET, TimeZoneInfo.Local has a TimeZoneInfo.Id value of
"Local" and a TimeZoneInfo.DisplayName value of "Local":

	$ csharp
	csharp> TimeZoneInfo.Local.Id;
	"Local"
	csharp> TimeZoneInfo.Local.DisplayName;
	"Local"

That isn't the case on Xamarin.Android, which returns the timezoneinfo
ID value from both DisplayName and Id, e.g. TimeZoneInfo.Local could
have Id and DisplayName values of "Australia/Sydney".

Rework things so that the TimeZoneInfo.Id and TimeZoneInfo.DisplayName
properties return "Local" on Xamarin.Android for the instance returned
from TimeZoneInfo.Local, just like normal Mono/.NET does.
Jonathan Pryor 11 years ago
parent
commit
f7fd52ad18

+ 13 - 13
mcs/class/System.Core/System/TimeZoneInfo.Android.cs

@@ -453,29 +453,29 @@ namespace System {
 					: db.GetAvailableIds ();
 			}
 
-			static TimeZoneInfo _GetTimeZone (string name)
+			static TimeZoneInfo _GetTimeZone (string id, string name)
 			{
 				if (db == null)
 					return null;
 				byte[] buffer = db.GetTimeZoneData (name);
 				if (buffer == null)
 					return null;
-				return TimeZoneInfo.ParseTZBuffer (name, buffer, buffer.Length);
+				return TimeZoneInfo.ParseTZBuffer (id, buffer, buffer.Length);
 			}
 
-			internal static TimeZoneInfo GetTimeZone (string id)
+			internal static TimeZoneInfo GetTimeZone (string id, string name)
 			{
-				if (id != null) {
-					if (id == "GMT" || id == "UTC")
-						return new TimeZoneInfo (id, TimeSpan.FromSeconds (0), id, id, id, null, true);
-					if (id.StartsWith ("GMT"))
+				if (name != null) {
+					if (name == "GMT" || name == "UTC")
+						return new TimeZoneInfo (id, TimeSpan.FromSeconds (0), id, name, name, null, disableDaylightSavingTime:true);
+					if (name.StartsWith ("GMT"))
 						return new TimeZoneInfo (id,
-								TimeSpan.FromSeconds (ParseNumericZone (id)),
-								id, id, id, null, true);
+								TimeSpan.FromSeconds (ParseNumericZone (name)),
+								id, name, name, null, disableDaylightSavingTime:true);
 				}
 
 				try {
-					return _GetTimeZone (id);
+					return _GetTimeZone (id, name);
 				} catch (Exception) {
 					return null;
 				}
@@ -533,12 +533,12 @@ namespace System {
 			static readonly object _lock = new object ();
 
 			static TimeZoneInfo defaultZone;
-			internal static TimeZoneInfo Default {
+			internal static TimeZoneInfo Local {
 				get {
 					lock (_lock) {
 						if (defaultZone != null)
 							return defaultZone;
-						return defaultZone = GetTimeZone (GetDefaultTimeZoneName ());
+						return defaultZone = GetTimeZone ("Local", GetDefaultTimeZoneName ());
 					}
 				}
 			}
@@ -617,7 +617,7 @@ namespace System {
 				foreach (var id in GetAvailableIds ()) {
 					Console.Write ("name={0,-40}", id);
 					try {
-						TimeZoneInfo zone = _GetTimeZone (id);
+						TimeZoneInfo zone = _GetTimeZone (id, id);
 						if (zone != null) {
 							Console.Write (" {0,-40}", zone);
 							if (offset.HasValue) {

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

@@ -103,7 +103,7 @@ namespace System
 		static TimeZoneInfo CreateLocal ()
 		{
 #if MONODROID
-			return AndroidTimeZones.Default;
+			return AndroidTimeZones.Local;
 #elif MONOTOUCH
 			using (Stream stream = GetMonoTouchData (null)) {
 				return BuildFromStream ("Local", stream);
@@ -415,7 +415,7 @@ namespace System
 			}
 #endif
 #if MONODROID
-			var timeZoneInfo = AndroidTimeZones.GetTimeZone (id);
+			var timeZoneInfo = AndroidTimeZones.GetTimeZone (id, id);
 			if (timeZoneInfo == null)
 				throw new TimeZoneNotFoundException ();
 			return timeZoneInfo;
@@ -644,7 +644,7 @@ namespace System
 #endif
 #if MONODROID
 			foreach (string id in AndroidTimeZones.GetAvailableIds ()) {
-				var tz = AndroidTimeZones.GetTimeZone (id);
+				var tz = AndroidTimeZones.GetTimeZone (id, id);
 				if (tz != null)
 					systemTimeZones.Add (tz);
 			}