public static TimeZoneInfo FindSystemTimeZoneById(string id) { //FIXME: this method should check for cached values in systemTimeZones if (id == null) { throw new ArgumentNullException("id"); } #if !NET_2_1 if (TimeZoneKey != null) { RegistryKey key = TimeZoneKey.OpenSubKey(id, false); if (key == null) { throw new TimeZoneNotFoundException(); } return(FromRegistryKey(id, key)); } #endif #if MONODROID return(ZoneInfoDB.GetTimeZone(id)); #elif LIBC string filepath = Path.Combine(TimeZoneDirectory, id); return(FindSystemTimeZoneByFileName(id, filepath)); #else throw new NotImplementedException(); #endif }
public static ReadOnlyCollection <TimeZoneInfo> GetSystemTimeZones() { if (systemTimeZones == null) { systemTimeZones = new List <TimeZoneInfo> (); #if !NET_2_1 if (TimeZoneKey != null) { foreach (string id in TimeZoneKey.GetSubKeyNames()) { try { systemTimeZones.Add(FindSystemTimeZoneById(id)); } catch {} } return(new ReadOnlyCollection <TimeZoneInfo> (systemTimeZones)); } #endif #if MONODROID foreach (string id in ZoneInfoDB.GetAvailableIds()) { systemTimeZones.Add(ZoneInfoDB.GetTimeZone(id)); } #elif MONOTOUCH if (systemTimeZones.Count == 0) { foreach (string name in GetMonoTouchNames()) { using (Stream stream = GetMonoTouchData(name)) { systemTimeZones.Add(BuildFromStream(name, stream)); } } } #elif LIBC string[] continents = new string [] { "Africa", "America", "Antarctica", "Arctic", "Asia", "Atlantic", "Brazil", "Canada", "Chile", "Europe", "Indian", "Mexico", "Mideast", "Pacific", "US" }; foreach (string continent in continents) { try { foreach (string zonepath in Directory.GetFiles(Path.Combine(TimeZoneDirectory, continent))) { try { string id = String.Format("{0}/{1}", continent, Path.GetFileName(zonepath)); systemTimeZones.Add(FindSystemTimeZoneById(id)); } catch (ArgumentNullException) { } catch (TimeZoneNotFoundException) { } catch (InvalidTimeZoneException) { } catch (Exception) { throw; } } } catch {} } #else throw new NotImplementedException("This method is not implemented for this platform"); #endif } return(new ReadOnlyCollection <TimeZoneInfo> (systemTimeZones)); }
public static TimeZoneInfo FindSystemTimeZoneById(string id) { //FIXME: this method should check for cached values in systemTimeZones if (id == null) { throw new ArgumentNullException("id"); } #if !NET_2_1 if (TimeZoneKey != null) { RegistryKey key = TimeZoneKey.OpenSubKey(id, false); if (key == null) { throw new TimeZoneNotFoundException(); } return(FromRegistryKey(id, key)); } #endif #if MONODROID var timeZoneInfo = ZoneInfoDB.GetTimeZone(id); if (timeZoneInfo == null) { throw new TimeZoneNotFoundException(); } return(timeZoneInfo); #else // Local requires special logic that already exists in the Local property (bug #326) if (id == "Local") { return(Local); } #if MONOTOUCH using (Stream stream = GetMonoTouchData(id)) { return(BuildFromStream(id, stream)); } #elif LIBC string filepath = Path.Combine(TimeZoneDirectory, id); return(FindSystemTimeZoneByFileName(id, filepath)); #else throw new NotImplementedException(); #endif #endif }