Skip to content

Commit

Permalink
[System.Core/Android] Use correct comparison for timezone ids.
Browse files Browse the repository at this point in the history
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=7953

The names within zoneinfo.idx are sorted ordinally, which is not the
default string comparison that Array.BinarySearch() uses.
Consequently, many timezones would not be found even though they were
present, including "Pacific/Auckland".

Use the correct string comparison so that names can be found.
  • Loading branch information
jonpryor committed Jun 25, 2013
1 parent e1a6e61 commit ac11abe
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion mcs/class/System.Core/System/TimeZoneInfo.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ static FileStream GetTimeZoneData (string name, out int start, out int length)

start = length = 0;

int i = Array.BinarySearch (names, name);
int i = Array.BinarySearch (names, name, StringComparer.Ordinal);
if (i < 0)
return null;

Expand Down Expand Up @@ -291,6 +291,40 @@ static string GetDefaultTimeZoneName ()
return buf.ToString ();
return null;
}

#if SELF_TEST
/*
* Compile:
* mcs /out:tzi.exe "/d:INSIDE_CORLIB;MONODROID;NET_4_0;LIBC;SELF_TEST" System/TimeZone*.cs ../../build/common/Consts.cs
* Prep:
* mkdir -p usr/share/zoneinfo
* android_root=`adb shell echo '$ANDROID_ROOT' | tr -d "\r"`
* adb pull $android_root/usr/share/zoneinfo usr/share/zoneinfo
* Run:
* ANDROID_ROOT=`pwd` mono tzi.exe
*/
static void Main (string[] args)
{
Console.WriteLine ("Version: {0}", version);
for (int i = 0; i < names.Length; ++i) {
Console.Write ("{0,3}\tname={1,-40} start={2,-10} length={3,-4} offset=0x{4,8}",
i, names [i], starts [i], lengths [i], offsets [i].ToString ("x8"));
try {
TimeZoneInfo zone = _GetTimeZone (names [i]);
if (zone != null)
Console.Write (" {0}", zone);
else {
Console.Write (" ERROR:null Index? {0}",
Array.BinarySearch (names, names [i], StringComparer.Ordinal));
}
} catch (Exception e) {
Console.WriteLine ();
Console.Write ("ERROR: {0}", e);
}
Console.WriteLine ();
}
}
#endif
}
}
}
Expand Down

0 comments on commit ac11abe

Please sign in to comment.