}
}
#if LIBC
- static string timeZoneDirectory = null;
+ static string timeZoneDirectory;
static string TimeZoneDirectory {
get {
if (timeZoneDirectory == null)
return str.Substring (Istart, Iend-Istart+1);
}
- static RegistryKey timeZoneKey = null;
+ static RegistryKey timeZoneKey;
static RegistryKey TimeZoneKey {
get {
if (timeZoneKey != null)
}
}
- static RegistryKey localZoneKey = null;
+ static RegistryKey localZoneKey;
static RegistryKey LocalZoneKey {
get {
if (localZoneKey != null)
}
- public static DateTimeOffset ConvertTime (DateTimeOffset dateTimeOffset, TimeZoneInfo destinationTimeZone)
+ public static DateTimeOffset ConvertTime(DateTimeOffset dateTimeOffset, TimeZoneInfo destinationTimeZone)
{
- throw new NotImplementedException ();
+ if (destinationTimeZone == null)
+ throw new ArgumentNullException("destinationTimeZone");
+
+ var utcDateTime = dateTimeOffset.UtcDateTime;
+ AdjustmentRule rule = GetApplicableRule (utcDateTime);
+
+ if (rule != null && destinationTimeZone.IsDaylightSavingTime(utcDateTime)) {
+ var offset = destinationTimeZone.BaseUtcOffset + rule.DaylightDelta;
+ return new DateTimeOffset(DateTime.SpecifyKind(utcDateTime, DateTimeKind.Unspecified) + offset, offset);
+ }
+ else {
+ return new DateTimeOffset(DateTime.SpecifyKind(utcDateTime, DateTimeKind.Unspecified) + destinationTimeZone.BaseUtcOffset, destinationTimeZone.BaseUtcOffset);
+ }
}
public static DateTime ConvertTimeBySystemTimeZoneId (DateTime dateTime, string destinationTimeZoneId)
}
#endif
#if MONODROID
- return ZoneInfoDB.GetTimeZone (id);
+ 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")
}
//FIXME: change this to a generic Dictionary and allow caching for FindSystemTimeZoneById
- private static List<TimeZoneInfo> systemTimeZones = null;
+ private static List<TimeZoneInfo> systemTimeZones;
public static ReadOnlyCollection<TimeZoneInfo> GetSystemTimeZones ()
{
if (systemTimeZones == null) {