Skip to content

Commit

Permalink
[mscorlib/Android] TimeZoneInfo.Local.Id should be "Local".
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jonpryor committed Oct 24, 2014
1 parent 84472a3 commit f7fd52a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
26 changes: 13 additions & 13 deletions mcs/class/System.Core/System/TimeZoneInfo.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -453,29 +453,29 @@ internal static IEnumerable<string> GetAvailableIds ()
: 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;
}
Expand Down Expand Up @@ -533,12 +533,12 @@ static int ParseNumericZone (string name)
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 ());
}
}
}
Expand Down Expand Up @@ -617,7 +617,7 @@ static void Main (string[] args)
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) {
Expand Down
6 changes: 3 additions & 3 deletions mcs/class/System.Core/System/TimeZoneInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static TimeZoneInfo Local {
static TimeZoneInfo CreateLocal ()
{
#if MONODROID
return AndroidTimeZones.Default;
return AndroidTimeZones.Local;
#elif MONOTOUCH
using (Stream stream = GetMonoTouchData (null)) {
return BuildFromStream ("Local", stream);
Expand Down Expand Up @@ -415,7 +415,7 @@ public static TimeZoneInfo FindSystemTimeZoneById (string id)
}
#endif
#if MONODROID
var timeZoneInfo = AndroidTimeZones.GetTimeZone (id);
var timeZoneInfo = AndroidTimeZones.GetTimeZone (id, id);
if (timeZoneInfo == null)
throw new TimeZoneNotFoundException ();
return timeZoneInfo;
Expand Down Expand Up @@ -644,7 +644,7 @@ public static ReadOnlyCollection<TimeZoneInfo> GetSystemTimeZones ()
#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);
}
Expand Down

0 comments on commit f7fd52a

Please sign in to comment.