Skip to content

Commit

Permalink
Don't throw TimeZoneNotFoundExceptions when iOS gives us invalid data.
Browse files Browse the repository at this point in the history
iOS 8 GM lists "Asia/Chita" among its time zones, but when requesting
the time zone data for that time zone, no data is returned.

With this change we ignore time zones without any data when fetching
all the timezones on the system.
  • Loading branch information
rolfbjarne committed Sep 11, 2014
1 parent 0083728 commit 550d314
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 6 additions & 3 deletions mcs/class/System.Core/System/TimeZoneInfo.MonoTouch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,15 @@ static ReadOnlyCollection<string> GetMonoTouchNames ()
[DllImport ("__Internal")]
extern static IntPtr monotouch_timezone_get_data (string name, ref int size);

static Stream GetMonoTouchData (string name)
static Stream GetMonoTouchData (string name, bool throw_on_error = true)
{
int size = 0;
IntPtr data = monotouch_timezone_get_data (name, ref size);
if (size <= 0)
throw new TimeZoneNotFoundException ();
if (size <= 0) {
if (throw_on_error)
throw new TimeZoneNotFoundException ();
return null;
}

unsafe {
var s = new UnmanagedMemoryStream ((byte*) data, size);
Expand Down
4 changes: 3 additions & 1 deletion mcs/class/System.Core/System/TimeZoneInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,9 @@ public static ReadOnlyCollection<TimeZoneInfo> GetSystemTimeZones ()
#elif MONOTOUCH
if (systemTimeZones.Count == 0) {
foreach (string name in GetMonoTouchNames ()) {
using (Stream stream = GetMonoTouchData (name)) {
using (Stream stream = GetMonoTouchData (name, false)) {
if (stream == null)
continue;
systemTimeZones.Add (BuildFromStream (name, stream));
}
}
Expand Down

0 comments on commit 550d314

Please sign in to comment.