17 [TypeForwardedFrom(
"System.Core, Version=3.5.0.0, Culture=Neutral, PublicKeyToken=b77a5c561934e089")]
18 [__DynamicallyInvokable]
22 private enum TimeZoneInfoResult
30 private class CachedData
40 public bool m_allSystemTimeZonesRead;
42 private volatile OffsetAndRule m_oneYearLocalFromUtc;
49 if (timeZoneInfo ==
null)
51 timeZoneInfo = CreateLocal();
62 if (timeZoneInfo ==
null)
64 timeZoneInfo = CreateUtc();
75 if (timeZoneInfo ==
null)
77 timeZoneInfo = GetLocalTimeZone(
this);
78 timeZoneInfo = (m_localTimeZone =
new TimeZoneInfo(timeZoneInfo.m_id, timeZoneInfo.m_baseUtcOffset, timeZoneInfo.m_displayName, timeZoneInfo.m_standardDisplayName, timeZoneInfo.m_daylightDisplayName, timeZoneInfo.m_adjustmentRules, disableDaylightSavingTime:
false));
89 if (timeZoneInfo ==
null)
99 if (timeZone == m_utcTimeZone)
103 if (timeZone == m_localTimeZone)
110 [SecuritySafeCritical]
113 Win32Native.TimeZoneInformation lpTimeZoneInformation =
default(Win32Native.TimeZoneInformation);
114 long num = UnsafeNativeMethods.GetTimeZoneInformation(out lpTimeZoneInformation);
119 return GetLocalTimeZoneFromWin32Data(lpTimeZoneInformation, dstDisabled:
false);
122 public OffsetAndRule GetOneYearLocalFromUtc(
int year)
124 OffsetAndRule offsetAndRule = m_oneYearLocalFromUtc;
125 if (offsetAndRule ==
null || offsetAndRule.year != year)
127 TimeZoneInfo currentOneYearLocal = GetCurrentOneYearLocal();
128 AdjustmentRule rule = (currentOneYearLocal.m_adjustmentRules ==
null) ?
null : currentOneYearLocal.m_adjustmentRules[0];
129 offsetAndRule = (m_oneYearLocalFromUtc =
new OffsetAndRule(year, currentOneYearLocal.
BaseUtcOffset, rule));
131 return offsetAndRule;
135 private class OffsetAndRule
146 this.offset = offset;
153 [TypeForwardedFrom(
"System.Core, Version=3.5.0.0, Culture=Neutral, PublicKeyToken=b77a5c561934e089")]
167 private TimeSpan m_baseUtcOffsetDelta;
189 internal TimeSpan BaseUtcOffsetDelta => m_baseUtcOffsetDelta;
191 internal bool HasDaylightSaving
209 return other !=
null && m_dateStart == other.m_dateStart && m_dateEnd == other.m_dateEnd && m_daylightDelta == other.m_daylightDelta && m_baseUtcOffsetDelta == other.m_baseUtcOffsetDelta && m_daylightTransitionEnd.
Equals(other.m_daylightTransitionEnd) && m_daylightTransitionStart.
Equals(other.m_daylightTransitionStart);
216 return m_dateStart.GetHashCode();
236 ValidateAdjustmentRule(dateStart, dateEnd, daylightDelta, daylightTransitionStart, daylightTransitionEnd);
238 adjustmentRule.m_dateStart = dateStart;
239 adjustmentRule.m_dateEnd = dateEnd;
240 adjustmentRule.m_daylightDelta = daylightDelta;
241 adjustmentRule.m_daylightTransitionStart = daylightTransitionStart;
242 adjustmentRule.m_daylightTransitionEnd = daylightTransitionEnd;
244 return adjustmentRule;
250 adjustmentRule.m_baseUtcOffsetDelta = baseUtcOffsetDelta;
251 return adjustmentRule;
254 internal bool IsStartDateMarkerForBeginningOfYear()
258 return m_dateStart.Year == m_dateEnd.
Year;
263 internal bool IsEndDateMarkerForEndOfYear()
267 return m_dateStart.Year == m_dateEnd.
Year;
272 private static void ValidateAdjustmentRule(
DateTime dateStart,
DateTime dateEnd, TimeSpan daylightDelta, TransitionTime daylightTransitionStart, TransitionTime daylightTransitionEnd)
274 if (dateStart.Kind != 0)
276 throw new ArgumentException(Environment.GetResourceString(
"Argument_DateTimeKindMustBeUnspecified"),
"dateStart");
278 if (dateEnd.Kind != 0)
280 throw new ArgumentException(Environment.GetResourceString(
"Argument_DateTimeKindMustBeUnspecified"),
"dateEnd");
282 if (daylightTransitionStart.Equals(daylightTransitionEnd))
284 throw new ArgumentException(Environment.GetResourceString(
"Argument_TransitionTimesAreIdentical"),
"daylightTransitionEnd");
286 if (dateStart > dateEnd)
288 throw new ArgumentException(Environment.GetResourceString(
"Argument_OutOfOrderDateTimes"),
"dateStart");
290 if (UtcOffsetOutOfRange(daylightDelta))
292 throw new ArgumentOutOfRangeException(
"daylightDelta", daylightDelta, Environment.GetResourceString(
"ArgumentOutOfRange_UtcOffset"));
294 if (daylightDelta.Ticks % 600000000 != 0
L)
296 throw new ArgumentException(Environment.GetResourceString(
"Argument_TimeSpanHasSeconds"),
"daylightDelta");
298 if (dateStart.TimeOfDay != TimeSpan.Zero)
300 throw new ArgumentException(Environment.GetResourceString(
"Argument_DateTimeHasTimeOfDay"),
"dateStart");
302 if (dateEnd.TimeOfDay != TimeSpan.Zero)
304 throw new ArgumentException(Environment.GetResourceString(
"Argument_DateTimeHasTimeOfDay"),
"dateEnd");
314 ValidateAdjustmentRule(m_dateStart, m_dateEnd, m_daylightDelta, m_daylightTransitionStart, m_daylightTransitionEnd);
316 catch (ArgumentException innerException)
318 throw new SerializationException(Environment.GetResourceString(
"Serialization_InvalidData"), innerException);
330 throw new ArgumentNullException(
"info");
332 info.AddValue(
"DateStart", m_dateStart);
333 info.AddValue(
"DateEnd", m_dateEnd);
334 info.AddValue(
"DaylightDelta", m_daylightDelta);
335 info.AddValue(
"DaylightTransitionStart", m_daylightTransitionStart);
336 info.AddValue(
"DaylightTransitionEnd", m_daylightTransitionEnd);
337 info.AddValue(
"BaseUtcOffsetDelta", m_baseUtcOffsetDelta);
344 throw new ArgumentNullException(
"info");
348 m_daylightDelta = (TimeSpan)info.GetValue(
"DaylightDelta", typeof(TimeSpan));
349 m_daylightTransitionStart = (TransitionTime)info.GetValue(
"DaylightTransitionStart", typeof(TransitionTime));
350 m_daylightTransitionEnd = (TransitionTime)info.GetValue(
"DaylightTransitionEnd", typeof(TransitionTime));
351 object valueNoThrow = info.GetValueNoThrow(
"BaseUtcOffsetDelta", typeof(TimeSpan));
352 if (valueNoThrow !=
null)
354 m_baseUtcOffsetDelta = (TimeSpan)valueNoThrow;
361 [TypeForwardedFrom(
"System.Core, Version=3.5.0.0, Culture=Neutral, PublicKeyToken=b77a5c561934e089")]
362 [HostProtection(
SecurityAction.LinkDemand, MayLeakOnAbort =
true)]
367 private byte m_month;
375 private bool m_isFixedDateRule;
441 bool flag = m_isFixedDateRule == other.m_isFixedDateRule && m_timeOfDay == other.m_timeOfDay && m_month == other.m_month;
444 flag = ((!other.m_isFixedDateRule) ? (m_week == other.m_week && m_dayOfWeek == other.m_dayOfWeek) : (m_day == other.m_day));
453 return m_month ^ (m_week << 8);
465 return CreateTransitionTime(timeOfDay, month, 1, day,
DayOfWeek.Sunday, isFixedDateRule:
true);
480 return CreateTransitionTime(timeOfDay, month, week, 1, dayOfWeek, isFixedDateRule:
false);
485 ValidateTransitionTime(timeOfDay, month, week, day, dayOfWeek);
487 result.m_isFixedDateRule = isFixedDateRule;
488 result.m_timeOfDay = timeOfDay;
489 result.m_dayOfWeek = dayOfWeek;
490 result.m_day = (byte)day;
491 result.m_week = (byte)week;
492 result.m_month = (byte)month;
496 private static void ValidateTransitionTime(
DateTime timeOfDay,
int month,
int week,
int day,
DayOfWeek dayOfWeek)
498 if (timeOfDay.
Kind != 0)
502 if (month < 1 || month > 12)
504 throw new ArgumentOutOfRangeException(
"month", Environment.GetResourceString(
"ArgumentOutOfRange_MonthParam"));
506 if (day < 1 || day > 31)
508 throw new ArgumentOutOfRangeException(
"day", Environment.GetResourceString(
"ArgumentOutOfRange_DayParam"));
510 if (week < 1 || week > 5)
512 throw new ArgumentOutOfRangeException(
"week", Environment.GetResourceString(
"ArgumentOutOfRange_Week"));
514 if (dayOfWeek < DayOfWeek.Sunday || dayOfWeek >
DayOfWeek.Saturday)
516 throw new ArgumentOutOfRangeException(
"dayOfWeek", Environment.GetResourceString(
"ArgumentOutOfRange_DayOfWeek"));
518 if (timeOfDay.
Year != 1 || timeOfDay.
Month != 1 || timeOfDay.
Day != 1 || timeOfDay.
Ticks % 10000 != 0
L)
520 throw new ArgumentException(Environment.GetResourceString(
"Argument_DateTimeHasTicks"),
"timeOfDay");
530 ValidateTransitionTime(m_timeOfDay, m_month, m_week, m_day, m_dayOfWeek);
548 info.AddValue(
"TimeOfDay", m_timeOfDay);
549 info.AddValue(
"Month", m_month);
550 info.AddValue(
"Week", m_week);
551 info.AddValue(
"Day", m_day);
552 info.AddValue(
"DayOfWeek", m_dayOfWeek);
553 info.AddValue(
"IsFixedDateRule", m_isFixedDateRule);
563 m_month = (byte)info.GetValue(
"Month", typeof(
byte));
564 m_week = (byte)info.GetValue(
"Week", typeof(
byte));
565 m_day = (byte)info.GetValue(
"Day", typeof(
byte));
567 m_isFixedDateRule = (bool)info.GetValue(
"IsFixedDateRule", typeof(
bool));
571 private sealed
class StringSerializer
581 private string m_serializedText;
583 private int m_currentTokenStartIndex;
585 private State m_state;
587 private const int initialCapacityForString = 64;
589 private const char esc =
'\\';
591 private const char sep =
';';
593 private const char lhs =
'[';
595 private const char rhs =
']';
597 private const string escString =
"\\";
599 private const string sepString =
";";
601 private const string lhsString =
"[";
603 private const string rhsString =
"]";
605 private const string escapedEsc =
"\\\\";
607 private const string escapedSep =
"\\;";
609 private const string escapedLhs =
"\\[";
611 private const string escapedRhs =
"\\]";
613 private const string dateTimeFormat =
"MM:dd:yyyy";
615 private const string timeOfDayFormat =
"HH:mm:ss.FFF";
617 public static string GetSerializedString(TimeZoneInfo zone)
620 stringBuilder.
Append(SerializeSubstitute(zone.Id));
621 stringBuilder.
Append(
';');
623 stringBuilder.
Append(
';');
624 stringBuilder.
Append(SerializeSubstitute(zone.DisplayName));
625 stringBuilder.
Append(
';');
626 stringBuilder.
Append(SerializeSubstitute(zone.StandardName));
627 stringBuilder.
Append(
';');
628 stringBuilder.
Append(SerializeSubstitute(zone.DaylightName));
629 stringBuilder.
Append(
';');
630 AdjustmentRule[] adjustmentRules = zone.GetAdjustmentRules();
631 if (adjustmentRules !=
null && adjustmentRules.Length != 0)
633 foreach (AdjustmentRule adjustmentRule
in adjustmentRules)
635 stringBuilder.
Append(
'[');
637 stringBuilder.
Append(
';');
639 stringBuilder.
Append(
';');
641 stringBuilder.
Append(
';');
642 SerializeTransitionTime(adjustmentRule.DaylightTransitionStart, stringBuilder);
643 stringBuilder.
Append(
';');
644 SerializeTransitionTime(adjustmentRule.DaylightTransitionEnd, stringBuilder);
645 stringBuilder.
Append(
';');
646 if (adjustmentRule.BaseUtcOffsetDelta != TimeSpan.Zero)
649 stringBuilder.
Append(
';');
651 stringBuilder.
Append(
']');
654 stringBuilder.
Append(
';');
655 return StringBuilderCache.GetStringAndRelease(stringBuilder);
658 public static TimeZoneInfo GetDeserializedTimeZoneInfo(
string source)
660 StringSerializer stringSerializer =
new StringSerializer(source);
661 string nextStringValue = stringSerializer.GetNextStringValue(canEndWithoutSeparator:
false);
662 TimeSpan nextTimeSpanValue = stringSerializer.GetNextTimeSpanValue(canEndWithoutSeparator:
false);
663 string nextStringValue2 = stringSerializer.GetNextStringValue(canEndWithoutSeparator:
false);
664 string nextStringValue3 = stringSerializer.GetNextStringValue(canEndWithoutSeparator:
false);
665 string nextStringValue4 = stringSerializer.GetNextStringValue(canEndWithoutSeparator:
false);
666 AdjustmentRule[] nextAdjustmentRuleArrayValue = stringSerializer.GetNextAdjustmentRuleArrayValue(canEndWithoutSeparator:
false);
669 return CreateCustomTimeZone(nextStringValue, nextTimeSpanValue, nextStringValue2, nextStringValue3, nextStringValue4, nextAdjustmentRuleArrayValue);
671 catch (ArgumentException innerException)
673 throw new SerializationException(Environment.GetResourceString(
"Serialization_InvalidData"), innerException);
675 catch (InvalidTimeZoneException innerException2)
677 throw new SerializationException(Environment.GetResourceString(
"Serialization_InvalidData"), innerException2);
681 private StringSerializer(
string str)
683 m_serializedText = str;
684 m_state = State.StartOfToken;
687 private static string SerializeSubstitute(
string text)
689 text = text.Replace(
"\\",
"\\\\");
690 text = text.Replace(
"[",
"\\[");
691 text = text.Replace(
"]",
"\\]");
692 return text.Replace(
";",
"\\;");
695 private static void SerializeTransitionTime(TransitionTime time,
StringBuilder serializedText)
697 serializedText.
Append(
'[');
699 serializedText.
Append(
';');
700 if (time.IsFixedDateRule)
703 serializedText.
Append(
';');
705 serializedText.
Append(
';');
707 serializedText.
Append(
';');
712 serializedText.
Append(
';');
714 serializedText.
Append(
';');
716 serializedText.
Append(
';');
718 serializedText.
Append(
';');
720 serializedText.
Append(
']');
723 private static void VerifyIsEscapableCharacter(
char c)
725 if (c !=
'\\' && c !=
';' && c !=
'[' && c !=
']')
727 throw new SerializationException(Environment.GetResourceString(
"Serialization_InvalidEscapeSequence", c));
731 private void SkipVersionNextDataFields(
int depth)
733 if (m_currentTokenStartIndex < 0 || m_currentTokenStartIndex >= m_serializedText.Length)
737 State state = State.NotEscaped;
738 for (
int i = m_currentTokenStartIndex; i < m_serializedText.Length; i++)
743 VerifyIsEscapableCharacter(m_serializedText[i]);
744 state = State.NotEscaped;
746 case State.NotEscaped:
747 switch (m_serializedText[i])
750 state = State.Escaped;
759 m_currentTokenStartIndex = i + 1;
760 if (m_currentTokenStartIndex >= m_serializedText.Length)
762 m_state = State.EndOfLine;
766 m_state = State.StartOfToken;
780 private string GetNextStringValue(
bool canEndWithoutSeparator)
782 if (m_state == State.EndOfLine)
784 if (canEndWithoutSeparator)
790 if (m_currentTokenStartIndex < 0 || m_currentTokenStartIndex >= m_serializedText.Length)
794 State state = State.NotEscaped;
795 StringBuilder stringBuilder = StringBuilderCache.Acquire(64);
796 for (
int i = m_currentTokenStartIndex; i < m_serializedText.Length; i++)
801 VerifyIsEscapableCharacter(m_serializedText[i]);
802 stringBuilder.
Append(m_serializedText[i]);
803 state = State.NotEscaped;
805 case State.NotEscaped:
806 switch (m_serializedText[i])
809 state = State.Escaped;
814 if (canEndWithoutSeparator)
816 m_currentTokenStartIndex = i;
817 m_state = State.StartOfToken;
822 m_currentTokenStartIndex = i + 1;
823 if (m_currentTokenStartIndex >= m_serializedText.Length)
825 m_state = State.EndOfLine;
829 m_state = State.StartOfToken;
831 return StringBuilderCache.GetStringAndRelease(stringBuilder);
835 stringBuilder.
Append(m_serializedText[i]);
841 if (state == State.Escaped)
843 throw new SerializationException(Environment.GetResourceString(
"Serialization_InvalidEscapeSequence",
string.Empty));
845 if (!canEndWithoutSeparator)
849 m_currentTokenStartIndex = m_serializedText.Length;
850 m_state = State.EndOfLine;
851 return StringBuilderCache.GetStringAndRelease(stringBuilder);
854 private DateTime GetNextDateTimeValue(
bool canEndWithoutSeparator,
string format)
856 string nextStringValue = GetNextStringValue(canEndWithoutSeparator);
864 private TimeSpan GetNextTimeSpanValue(
bool canEndWithoutSeparator)
866 int nextInt32Value = GetNextInt32Value(canEndWithoutSeparator);
869 return new TimeSpan(0, nextInt32Value, 0);
871 catch (ArgumentOutOfRangeException innerException)
873 throw new SerializationException(Environment.GetResourceString(
"Serialization_InvalidData"), innerException);
877 private int GetNextInt32Value(
bool canEndWithoutSeparator)
879 string nextStringValue = GetNextStringValue(canEndWithoutSeparator);
887 private AdjustmentRule[] GetNextAdjustmentRuleArrayValue(
bool canEndWithoutSeparator)
891 for (AdjustmentRule nextAdjustmentRuleValue = GetNextAdjustmentRuleValue(canEndWithoutSeparator:
true); nextAdjustmentRuleValue !=
null; nextAdjustmentRuleValue = GetNextAdjustmentRuleValue(canEndWithoutSeparator:
true))
893 list.Add(nextAdjustmentRuleValue);
896 if (!canEndWithoutSeparator)
898 if (m_state == State.EndOfLine)
902 if (m_currentTokenStartIndex < 0 || m_currentTokenStartIndex >= m_serializedText.Length)
911 return list.ToArray();
914 private AdjustmentRule GetNextAdjustmentRuleValue(
bool canEndWithoutSeparator)
916 if (m_state == State.EndOfLine)
918 if (canEndWithoutSeparator)
924 if (m_currentTokenStartIndex < 0 || m_currentTokenStartIndex >= m_serializedText.Length)
928 if (m_serializedText[m_currentTokenStartIndex] ==
';')
932 if (m_serializedText[m_currentTokenStartIndex] !=
'[')
936 m_currentTokenStartIndex++;
937 DateTime nextDateTimeValue = GetNextDateTimeValue(canEndWithoutSeparator:
false,
"MM:dd:yyyy");
938 DateTime nextDateTimeValue2 = GetNextDateTimeValue(canEndWithoutSeparator:
false,
"MM:dd:yyyy");
939 TimeSpan nextTimeSpanValue = GetNextTimeSpanValue(canEndWithoutSeparator:
false);
940 TransitionTime nextTransitionTimeValue = GetNextTransitionTimeValue(canEndWithoutSeparator:
false);
941 TransitionTime nextTransitionTimeValue2 = GetNextTransitionTimeValue(canEndWithoutSeparator:
false);
942 TimeSpan baseUtcOffsetDelta = TimeSpan.Zero;
943 if (m_state == State.EndOfLine || m_currentTokenStartIndex >= m_serializedText.Length)
947 if ((m_serializedText[m_currentTokenStartIndex] >=
'0' && m_serializedText[m_currentTokenStartIndex] <=
'9') || m_serializedText[m_currentTokenStartIndex] ==
'-' || m_serializedText[m_currentTokenStartIndex] ==
'+')
949 baseUtcOffsetDelta = GetNextTimeSpanValue(canEndWithoutSeparator:
false);
951 if (m_state == State.EndOfLine || m_currentTokenStartIndex >= m_serializedText.Length)
955 if (m_serializedText[m_currentTokenStartIndex] !=
']')
957 SkipVersionNextDataFields(1);
961 m_currentTokenStartIndex++;
963 AdjustmentRule result;
966 result = AdjustmentRule.CreateAdjustmentRule(nextDateTimeValue, nextDateTimeValue2, nextTimeSpanValue, nextTransitionTimeValue, nextTransitionTimeValue2, baseUtcOffsetDelta);
968 catch (ArgumentException innerException)
970 throw new SerializationException(Environment.GetResourceString(
"Serialization_InvalidData"), innerException);
972 if (m_currentTokenStartIndex >= m_serializedText.Length)
974 m_state = State.EndOfLine;
978 m_state = State.StartOfToken;
983 private TransitionTime GetNextTransitionTimeValue(
bool canEndWithoutSeparator)
985 if (m_state == State.EndOfLine || (m_currentTokenStartIndex < m_serializedText.Length && m_serializedText[m_currentTokenStartIndex] ==
']'))
989 if (m_currentTokenStartIndex < 0 || m_currentTokenStartIndex >= m_serializedText.Length)
993 if (m_serializedText[m_currentTokenStartIndex] !=
'[')
997 m_currentTokenStartIndex++;
998 int nextInt32Value = GetNextInt32Value(canEndWithoutSeparator:
false);
999 if (nextInt32Value != 0 && nextInt32Value != 1)
1003 DateTime nextDateTimeValue = GetNextDateTimeValue(canEndWithoutSeparator:
false,
"HH:mm:ss.FFF");
1004 nextDateTimeValue =
new DateTime(1, 1, 1, nextDateTimeValue.Hour, nextDateTimeValue.Minute, nextDateTimeValue.Second, nextDateTimeValue.Millisecond);
1005 int nextInt32Value2 = GetNextInt32Value(canEndWithoutSeparator:
false);
1006 TransitionTime result;
1007 if (nextInt32Value == 1)
1009 int nextInt32Value3 = GetNextInt32Value(canEndWithoutSeparator:
false);
1012 result = TransitionTime.CreateFixedDateRule(nextDateTimeValue, nextInt32Value2, nextInt32Value3);
1014 catch (ArgumentException innerException)
1016 throw new SerializationException(Environment.GetResourceString(
"Serialization_InvalidData"), innerException);
1021 int nextInt32Value4 = GetNextInt32Value(canEndWithoutSeparator:
false);
1022 int nextInt32Value5 = GetNextInt32Value(canEndWithoutSeparator:
false);
1025 result = TransitionTime.CreateFloatingDateRule(nextDateTimeValue, nextInt32Value2, nextInt32Value4, (
DayOfWeek)nextInt32Value5);
1027 catch (ArgumentException innerException2)
1029 throw new SerializationException(Environment.GetResourceString(
"Serialization_InvalidData"), innerException2);
1032 if (m_state == State.EndOfLine || m_currentTokenStartIndex >= m_serializedText.Length)
1036 if (m_serializedText[m_currentTokenStartIndex] !=
']')
1038 SkipVersionNextDataFields(1);
1042 m_currentTokenStartIndex++;
1045 if (m_currentTokenStartIndex < m_serializedText.Length && m_serializedText[m_currentTokenStartIndex] ==
';')
1047 m_currentTokenStartIndex++;
1050 if (!flag && !canEndWithoutSeparator)
1054 if (m_currentTokenStartIndex >= m_serializedText.Length)
1056 m_state = State.EndOfLine;
1060 m_state = State.StartOfToken;
1066 private class TimeZoneInfoComparer :
IComparer<TimeZoneInfo>
1070 int num = x.BaseUtcOffset.CompareTo(y.BaseUtcOffset);
1075 return string.Compare(x.DisplayName, y.DisplayName,
StringComparison.Ordinal);
1079 private string m_id;
1081 private string m_displayName;
1083 private string m_standardDisplayName;
1085 private string m_daylightDisplayName;
1087 private TimeSpan m_baseUtcOffset;
1089 private bool m_supportsDaylightSavingTime;
1091 private AdjustmentRule[] m_adjustmentRules;
1093 private const string c_timeZonesRegistryHive =
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones";
1095 private const string c_timeZonesRegistryHivePermissionList =
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones";
1097 private const string c_displayValue =
"Display";
1099 private const string c_daylightValue =
"Dlt";
1101 private const string c_standardValue =
"Std";
1103 private const string c_muiDisplayValue =
"MUI_Display";
1105 private const string c_muiDaylightValue =
"MUI_Dlt";
1107 private const string c_muiStandardValue =
"MUI_Std";
1109 private const string c_timeZoneInfoValue =
"TZI";
1111 private const string c_firstEntryValue =
"FirstEntry";
1113 private const string c_lastEntryValue =
"LastEntry";
1115 private const string c_utcId =
"UTC";
1117 private const string c_localId =
"Local";
1119 private const int c_maxKeyLength = 255;
1121 private const int c_regByteLength = 44;
1123 private const long c_ticksPerMillisecond = 10000
L;
1125 private const long c_ticksPerSecond = 10000000
L;
1127 private const long c_ticksPerMinute = 600000000
L;
1129 private const long c_ticksPerHour = 36000000000
L;
1131 private const long c_ticksPerDay = 864000000000
L;
1133 private const long c_ticksPerDayRange = 863999990000
L;
1135 private static CachedData s_cachedData =
new CachedData();
1143 [__DynamicallyInvokable]
1146 [__DynamicallyInvokable]
1155 [__DynamicallyInvokable]
1158 [__DynamicallyInvokable]
1161 if (m_displayName !=
null)
1163 return m_displayName;
1165 return string.Empty;
1171 [__DynamicallyInvokable]
1174 [__DynamicallyInvokable]
1177 if (m_standardDisplayName !=
null)
1179 return m_standardDisplayName;
1181 return string.Empty;
1187 [__DynamicallyInvokable]
1190 [__DynamicallyInvokable]
1193 if (m_daylightDisplayName !=
null)
1195 return m_daylightDisplayName;
1197 return string.Empty;
1203 [__DynamicallyInvokable]
1206 [__DynamicallyInvokable]
1209 return m_baseUtcOffset;
1216 [__DynamicallyInvokable]
1219 [__DynamicallyInvokable]
1222 return m_supportsDaylightSavingTime;
1228 [__DynamicallyInvokable]
1231 [__DynamicallyInvokable]
1234 return s_cachedData.Local;
1240 [__DynamicallyInvokable]
1243 [__DynamicallyInvokable]
1246 return s_cachedData.Utc;
1255 if (m_adjustmentRules ==
null)
1267 [__DynamicallyInvokable]
1276 AdjustmentRule adjustmentRuleForTime = GetAdjustmentRuleForTime(dateTime);
1277 if (adjustmentRuleForTime !=
null && adjustmentRuleForTime.HasDaylightSaving)
1279 DaylightTime daylightTime = GetDaylightTime(dateTime.
Year, adjustmentRuleForTime);
1280 flag = GetIsAmbiguousTime(dateTime, adjustmentRuleForTime, daylightTime);
1287 TimeSpan timeSpan = m_baseUtcOffset + adjustmentRuleForTime.BaseUtcOffsetDelta;
1290 array[0] = timeSpan;
1296 array[1] = timeSpan;
1306 [__DynamicallyInvokable]
1316 CachedData cachedData = s_cachedData;
1317 dateTime2 =
ConvertTime(dateTime, cachedData.Local,
this, TimeZoneInfoOptions.None, cachedData);
1321 CachedData cachedData2 = s_cachedData;
1322 dateTime2 =
ConvertTime(dateTime, cachedData2.Utc,
this, TimeZoneInfoOptions.None, cachedData2);
1326 dateTime2 = dateTime;
1329 AdjustmentRule adjustmentRuleForTime = GetAdjustmentRuleForTime(dateTime2);
1330 if (adjustmentRuleForTime !=
null && adjustmentRuleForTime.HasDaylightSaving)
1332 DaylightTime daylightTime = GetDaylightTime(dateTime2.
Year, adjustmentRuleForTime);
1333 flag = GetIsAmbiguousTime(dateTime2, adjustmentRuleForTime, daylightTime);
1340 TimeSpan timeSpan = m_baseUtcOffset + adjustmentRuleForTime.BaseUtcOffsetDelta;
1343 array[0] = timeSpan;
1349 array[1] = timeSpan;
1357 [__DynamicallyInvokable]
1360 return GetUtcOffsetFromUtc(dateTimeOffset.
UtcDateTime,
this);
1366 [__DynamicallyInvokable]
1369 return GetUtcOffset(dateTime, TimeZoneInfoOptions.NoThrowOnInvalidTime, s_cachedData);
1372 internal static TimeSpan GetLocalUtcOffset(
DateTime dateTime, TimeZoneInfoOptions flags)
1374 CachedData cachedData = s_cachedData;
1375 return cachedData.Local.GetUtcOffset(dateTime, flags, cachedData);
1383 private TimeSpan
GetUtcOffset(
DateTime dateTime, TimeZoneInfoOptions flags, CachedData cachedData)
1387 if (cachedData.GetCorrespondingKind(
this) !=
DateTimeKind.Local)
1390 return GetUtcOffsetFromUtc(time,
this);
1395 if (cachedData.GetCorrespondingKind(
this) ==
DateTimeKind.Utc)
1397 return m_baseUtcOffset;
1399 return GetUtcOffsetFromUtc(dateTime,
this);
1408 [__DynamicallyInvokable]
1411 if (!m_supportsDaylightSavingTime)
1423 [__DynamicallyInvokable]
1426 return IsAmbiguousTime(dateTime, TimeZoneInfoOptions.NoThrowOnInvalidTime);
1431 if (!m_supportsDaylightSavingTime)
1438 CachedData cachedData = s_cachedData;
1439 dateTime2 =
ConvertTime(dateTime, cachedData.Local,
this, flags, cachedData);
1443 CachedData cachedData2 = s_cachedData;
1444 dateTime2 =
ConvertTime(dateTime, cachedData2.Utc,
this, flags, cachedData2);
1448 dateTime2 = dateTime;
1450 AdjustmentRule adjustmentRuleForTime = GetAdjustmentRuleForTime(dateTime2);
1451 if (adjustmentRuleForTime !=
null && adjustmentRuleForTime.HasDaylightSaving)
1453 DaylightTime daylightTime = GetDaylightTime(dateTime2.Year, adjustmentRuleForTime);
1454 return GetIsAmbiguousTime(dateTime2, adjustmentRuleForTime, daylightTime);
1463 [__DynamicallyInvokable]
1466 GetUtcOffsetFromUtc(dateTimeOffset.
UtcDateTime,
this, out
bool isDaylightSavings);
1467 return isDaylightSavings;
1475 [__DynamicallyInvokable]
1488 if (!m_supportsDaylightSavingTime || m_adjustmentRules ==
null)
1495 dateTime2 =
ConvertTime(dateTime, cachedData.Local,
this, flags, cachedData);
1501 if (cachedData.GetCorrespondingKind(
this) ==
DateTimeKind.Utc)
1505 GetUtcOffsetFromUtc(dateTime,
this, out
bool isDaylightSavings);
1506 return isDaylightSavings;
1508 dateTime2 = dateTime;
1510 AdjustmentRule adjustmentRuleForTime = GetAdjustmentRuleForTime(dateTime2);
1511 if (adjustmentRuleForTime !=
null && adjustmentRuleForTime.HasDaylightSaving)
1513 DaylightTime daylightTime = GetDaylightTime(dateTime2.Year, adjustmentRuleForTime);
1514 return GetIsDaylightSavings(dateTime2, adjustmentRuleForTime, daylightTime, flags);
1523 [__DynamicallyInvokable]
1526 bool result =
false;
1529 AdjustmentRule adjustmentRuleForTime = GetAdjustmentRuleForTime(dateTime);
1530 if (adjustmentRuleForTime !=
null && adjustmentRuleForTime.HasDaylightSaving)
1532 DaylightTime daylightTime = GetDaylightTime(dateTime.
Year, adjustmentRuleForTime);
1533 result = GetIsInvalidTime(dateTime, adjustmentRuleForTime, daylightTime);
1546 s_cachedData =
new CachedData();
1595 CachedData cachedData = s_cachedData;
1600 CachedData cachedData2 = s_cachedData;
1611 [__DynamicallyInvokable]
1614 if (destinationTimeZone ==
null)
1619 TimeSpan utcOffsetFromUtc = GetUtcOffsetFromUtc(utcDateTime, destinationTimeZone);
1620 long num = utcDateTime.
Ticks + utcOffsetFromUtc.
Ticks;
1638 [__DynamicallyInvokable]
1641 if (destinationTimeZone ==
null)
1645 if (dateTime.
Ticks == 0
L)
1649 CachedData cachedData = s_cachedData;
1652 return ConvertTime(dateTime, cachedData.Utc, destinationTimeZone, TimeZoneInfoOptions.None, cachedData);
1654 return ConvertTime(dateTime, cachedData.Local, destinationTimeZone, TimeZoneInfoOptions.None, cachedData);
1664 [__DynamicallyInvokable]
1667 return ConvertTime(dateTime, sourceTimeZone, destinationTimeZone, TimeZoneInfoOptions.None, s_cachedData);
1672 return ConvertTime(dateTime, sourceTimeZone, destinationTimeZone, flags, s_cachedData);
1675 private static DateTime ConvertTime(
DateTime dateTime, TimeZoneInfo sourceTimeZone, TimeZoneInfo destinationTimeZone, TimeZoneInfoOptions flags, CachedData cachedData)
1677 if (sourceTimeZone ==
null)
1679 throw new ArgumentNullException(
"sourceTimeZone");
1681 if (destinationTimeZone ==
null)
1683 throw new ArgumentNullException(
"destinationTimeZone");
1685 DateTimeKind correspondingKind = cachedData.GetCorrespondingKind(sourceTimeZone);
1686 if ((flags & TimeZoneInfoOptions.NoThrowOnInvalidTime) == (TimeZoneInfoOptions)0 && dateTime.Kind != 0 && dateTime.Kind != correspondingKind)
1688 throw new ArgumentException(Environment.GetResourceString(
"Argument_ConvertMismatch"),
"sourceTimeZone");
1690 AdjustmentRule adjustmentRuleForTime = sourceTimeZone.GetAdjustmentRuleForTime(dateTime);
1691 TimeSpan t = sourceTimeZone.BaseUtcOffset;
1692 if (adjustmentRuleForTime !=
null)
1694 t += adjustmentRuleForTime.BaseUtcOffsetDelta;
1695 if (adjustmentRuleForTime.HasDaylightSaving)
1698 DaylightTime daylightTime = GetDaylightTime(dateTime.Year, adjustmentRuleForTime);
1699 if ((flags & TimeZoneInfoOptions.NoThrowOnInvalidTime) == (TimeZoneInfoOptions)0 && GetIsInvalidTime(dateTime, adjustmentRuleForTime, daylightTime))
1701 throw new ArgumentException(Environment.GetResourceString(
"Argument_DateTimeIsInvalid"),
"dateTime");
1703 flag = GetIsDaylightSavings(dateTime, adjustmentRuleForTime, daylightTime, flags);
1704 t += (flag ? adjustmentRuleForTime.DaylightDelta : TimeSpan.Zero);
1707 DateTimeKind correspondingKind2 = cachedData.GetCorrespondingKind(destinationTimeZone);
1708 if (dateTime.Kind != 0 && correspondingKind != 0 && correspondingKind == correspondingKind2)
1712 long ticks = dateTime.Ticks - t.Ticks;
1713 bool isAmbiguousLocalDst =
false;
1714 DateTime dateTime2 = ConvertUtcToTimeZone(ticks, destinationTimeZone, out isAmbiguousLocalDst);
1719 return new DateTime(dateTime2.Ticks, correspondingKind2);
1731 CachedData cachedData = s_cachedData;
1732 return ConvertTime(dateTime, cachedData.Utc, destinationTimeZone, TimeZoneInfoOptions.None, cachedData);
1748 CachedData cachedData = s_cachedData;
1749 return ConvertTime(dateTime, cachedData.Local, cachedData.Utc, TimeZoneInfoOptions.None, cachedData);
1758 CachedData cachedData = s_cachedData;
1759 return ConvertTime(dateTime, cachedData.Local, cachedData.Utc, flags, cachedData);
1779 CachedData cachedData = s_cachedData;
1780 return ConvertTime(dateTime, sourceTimeZone, cachedData.Utc, TimeZoneInfoOptions.None, cachedData);
1787 [__DynamicallyInvokable]
1790 if (other !=
null &&
string.Compare(m_id, other.m_id,
StringComparison.OrdinalIgnoreCase) == 0)
1804 if (timeZoneInfo ==
null)
1808 return Equals(timeZoneInfo);
1823 if (source.Length == 0)
1827 return StringSerializer.GetDeserializedTimeZoneInfo(source);
1832 [__DynamicallyInvokable]
1842 [SecuritySafeCritical]
1843 [__DynamicallyInvokable]
1846 CachedData cachedData = s_cachedData;
1849 if (cachedData.m_readOnlySystemTimeZones ==
null)
1854 using (
RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones", RegistryKeyPermissionCheck.Default,
RegistryRights.ExecuteKey))
1856 if (registryKey !=
null)
1858 string[] subKeyNames = registryKey.GetSubKeyNames();
1859 foreach (
string id in subKeyNames)
1864 cachedData.m_allSystemTimeZonesRead =
true;
1867 list.Sort(
new TimeZoneInfoComparer());
1871 return cachedData.m_readOnlySystemTimeZones;
1885 if (m_baseUtcOffset != other.m_baseUtcOffset || m_supportsDaylightSavingTime != other.m_supportsDaylightSavingTime)
1891 bool flag = (adjustmentRules ==
null && adjustmentRules2 ==
null) || (adjustmentRules !=
null && adjustmentRules2 !=
null);
1896 if (adjustmentRules !=
null)
1898 if (adjustmentRules.Length != adjustmentRules2.Length)
1902 for (
int i = 0; i < adjustmentRules.Length; i++)
1904 if (!adjustmentRules[i].
Equals(adjustmentRules2[i]))
1917 return StringSerializer.GetSerializedString(
this);
1922 [__DynamicallyInvokable]
1929 private TimeZoneInfo(Win32Native.TimeZoneInformation zone,
bool dstDisabled)
1931 if (
string.IsNullOrEmpty(zone.StandardName))
1939 m_baseUtcOffset =
new TimeSpan(0, -zone.Bias, 0);
1942 Win32Native.RegistryTimeZoneInformation timeZoneInformation =
new Win32Native.RegistryTimeZoneInformation(zone);
1943 AdjustmentRule adjustmentRule = CreateAdjustmentRuleFromTimeZoneInformation(timeZoneInformation,
DateTime.MinValue.Date,
DateTime.MaxValue.Date, zone.Bias);
1944 if (adjustmentRule !=
null)
1946 m_adjustmentRules =
new AdjustmentRule[1];
1947 m_adjustmentRules[0] = adjustmentRule;
1950 ValidateTimeZoneInfo(m_id, m_baseUtcOffset, m_adjustmentRules, out m_supportsDaylightSavingTime);
1951 m_displayName = zone.StandardName;
1952 m_standardDisplayName = zone.StandardName;
1953 m_daylightDisplayName = zone.DaylightName;
1956 private TimeZoneInfo(
string id, TimeSpan baseUtcOffset,
string displayName,
string standardDisplayName,
string daylightDisplayName, AdjustmentRule[] adjustmentRules,
bool disableDaylightSavingTime)
1958 ValidateTimeZoneInfo(
id, baseUtcOffset, adjustmentRules, out
bool adjustmentRulesSupportDst);
1959 if (!disableDaylightSavingTime && adjustmentRules !=
null && adjustmentRules.Length != 0)
1961 m_adjustmentRules = (AdjustmentRule[])adjustmentRules.Clone();
1964 m_baseUtcOffset = baseUtcOffset;
1965 m_displayName = displayName;
1966 m_standardDisplayName = standardDisplayName;
1967 m_daylightDisplayName = (disableDaylightSavingTime ? null : daylightDisplayName);
1968 m_supportsDaylightSavingTime = (adjustmentRulesSupportDst && !disableDaylightSavingTime);
1982 return new TimeZoneInfo(
id, baseUtcOffset, displayName, standardDisplayName, standardDisplayName,
null, disableDaylightSavingTime:
false);
1999 return new TimeZoneInfo(
id, baseUtcOffset, displayName, standardDisplayName, daylightDisplayName, adjustmentRules, disableDaylightSavingTime:
false);
2018 return new TimeZoneInfo(
id, baseUtcOffset, displayName, standardDisplayName, daylightDisplayName, adjustmentRules, disableDaylightSavingTime);
2028 ValidateTimeZoneInfo(m_id, m_baseUtcOffset, m_adjustmentRules, out
bool adjustmentRulesSupportDst);
2029 if (adjustmentRulesSupportDst != m_supportsDaylightSavingTime)
2034 catch (ArgumentException innerException)
2036 throw new SerializationException(Environment.GetResourceString(
"Serialization_InvalidData"), innerException);
2038 catch (InvalidTimeZoneException innerException2)
2040 throw new SerializationException(Environment.GetResourceString(
"Serialization_InvalidData"), innerException2);
2053 throw new ArgumentNullException(
"info");
2055 info.AddValue(
"Id", m_id);
2056 info.AddValue(
"DisplayName", m_displayName);
2057 info.AddValue(
"StandardName", m_standardDisplayName);
2058 info.AddValue(
"DaylightName", m_daylightDisplayName);
2059 info.AddValue(
"BaseUtcOffset", m_baseUtcOffset);
2060 info.AddValue(
"AdjustmentRules", m_adjustmentRules);
2061 info.AddValue(
"SupportsDaylightSavingTime", m_supportsDaylightSavingTime);
2068 throw new ArgumentNullException(
"info");
2070 m_id = (string)info.GetValue(
"Id", typeof(
string));
2071 m_displayName = (string)info.GetValue(
"DisplayName", typeof(
string));
2072 m_standardDisplayName = (string)info.GetValue(
"StandardName", typeof(
string));
2073 m_daylightDisplayName = (string)info.GetValue(
"DaylightName", typeof(
string));
2074 m_baseUtcOffset = (TimeSpan)info.GetValue(
"BaseUtcOffset", typeof(TimeSpan));
2075 m_adjustmentRules = (AdjustmentRule[])info.GetValue(
"AdjustmentRules", typeof(AdjustmentRule[]));
2076 m_supportsDaylightSavingTime = (bool)info.GetValue(
"SupportsDaylightSavingTime", typeof(
bool));
2079 private AdjustmentRule GetAdjustmentRuleForTime(
DateTime dateTime)
2081 if (m_adjustmentRules ==
null || m_adjustmentRules.Length == 0)
2086 for (
int i = 0; i < m_adjustmentRules.Length; i++)
2088 if (m_adjustmentRules[i].DateStart <= date && m_adjustmentRules[i].DateEnd >= date)
2090 return m_adjustmentRules[i];
2097 private static bool CheckDaylightSavingTimeNotSupported(Win32Native.TimeZoneInformation timeZone)
2099 if (timeZone.DaylightDate.Year == timeZone.StandardDate.Year && timeZone.DaylightDate.Month == timeZone.StandardDate.Month && timeZone.DaylightDate.DayOfWeek == timeZone.StandardDate.DayOfWeek && timeZone.DaylightDate.Day == timeZone.StandardDate.Day && timeZone.DaylightDate.Hour == timeZone.StandardDate.Hour && timeZone.DaylightDate.Minute == timeZone.StandardDate.Minute && timeZone.DaylightDate.Second == timeZone.StandardDate.Second)
2101 return timeZone.DaylightDate.Milliseconds == timeZone.StandardDate.Milliseconds;
2106 private static DateTime ConvertUtcToTimeZone(
long ticks, TimeZoneInfo destinationTimeZone, out
bool isAmbiguousLocalDst)
2109 ticks += GetUtcOffsetFromUtc(time, destinationTimeZone, out isAmbiguousLocalDst).
Ticks;
2110 if (ticks >
DateTime.MaxValue.Ticks)
2114 if (ticks <
DateTime.MinValue.Ticks)
2122 private static AdjustmentRule CreateAdjustmentRuleFromTimeZoneInformation(Win32Native.RegistryTimeZoneInformation timeZoneInformation,
DateTime startDate,
DateTime endDate,
int defaultBaseUtcOffset)
2124 if (timeZoneInformation.StandardDate.Month == 0)
2126 if (timeZoneInformation.Bias == defaultBaseUtcOffset)
2130 AdjustmentRule adjustmentRule;
2131 return adjustmentRule = AdjustmentRule.CreateAdjustmentRule(startDate, endDate, TimeSpan.Zero, TransitionTime.CreateFixedDateRule(
DateTime.MinValue, 1, 1), TransitionTime.CreateFixedDateRule(
DateTime.MinValue.AddMilliseconds(1.0), 1, 1),
new TimeSpan(0, defaultBaseUtcOffset - timeZoneInformation.Bias, 0));
2133 if (!TransitionTimeFromTimeZoneInformation(timeZoneInformation, out TransitionTime transitionTime, readStartDate:
true))
2137 if (!TransitionTimeFromTimeZoneInformation(timeZoneInformation, out TransitionTime transitionTime2, readStartDate:
false))
2141 if (transitionTime.Equals(transitionTime2))
2145 return AdjustmentRule.CreateAdjustmentRule(startDate, endDate,
new TimeSpan(0, -timeZoneInformation.DaylightBias, 0), transitionTime, transitionTime2,
new TimeSpan(0, defaultBaseUtcOffset - timeZoneInformation.Bias, 0));
2148 [SecuritySafeCritical]
2149 private static string FindIdFromTimeZoneInformation(Win32Native.TimeZoneInformation timeZone, out
bool dstDisabled)
2151 dstDisabled =
false;
2157 using (
RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones", RegistryKeyPermissionCheck.Default,
RegistryRights.ExecuteKey))
2159 if (registryKey ==
null)
2163 string[] subKeyNames = registryKey.GetSubKeyNames();
2164 foreach (
string text
in subKeyNames)
2166 if (TryCompareTimeZoneInformationToRegistry(timeZone, text, out dstDisabled))
2180 private static DaylightTime GetDaylightTime(
int year, AdjustmentRule rule)
2182 TimeSpan daylightDelta = rule.DaylightDelta;
2183 DateTime start = TransitionTimeToDateTime(year, rule.DaylightTransitionStart);
2184 DateTime end = TransitionTimeToDateTime(year, rule.DaylightTransitionEnd);
2188 private static bool GetIsDaylightSavings(
DateTime time, AdjustmentRule rule,
DaylightTime daylightTime, TimeZoneInfoOptions flags)
2198 startTime = (rule.IsStartDateMarkerForBeginningOfYear() ?
new DateTime(daylightTime.
Start.
Year, 1, 1, 0, 0, 0) : (daylightTime.
Start + daylightTime.Delta));
2199 endTime = (rule.IsEndDateMarkerForEndOfYear() ?
new DateTime(daylightTime.
End.
Year + 1, 1, 1, 0, 0, 0).AddTicks(-1
L) : daylightTime.
End);
2203 bool flag = rule.DaylightDelta > TimeSpan.Zero;
2204 startTime = (rule.IsStartDateMarkerForBeginningOfYear() ?
new DateTime(daylightTime.
Start.
Year, 1, 1, 0, 0, 0) : (daylightTime.
Start + (flag ? rule.DaylightDelta : TimeSpan.Zero)));
2205 endTime = (rule.IsEndDateMarkerForEndOfYear() ?
new DateTime(daylightTime.
End.
Year + 1, 1, 1, 0, 0, 0).AddTicks(-1
L) : (daylightTime.
End + (flag ? (-rule.DaylightDelta) : TimeSpan.Zero)));
2207 bool flag2 = CheckIsDst(startTime, time, endTime, ignoreYearAdjustment:
false);
2208 if (flag2 && time.Kind ==
DateTimeKind.Local && GetIsAmbiguousTime(time, rule, daylightTime))
2210 flag2 = time.IsAmbiguousDaylightSavingTime();
2215 private static bool GetIsDaylightSavingsFromUtc(
DateTime time,
int Year, TimeSpan utc, AdjustmentRule rule, out
bool isAmbiguousLocalDst, TimeZoneInfo zone)
2217 isAmbiguousLocalDst =
false;
2222 TimeSpan t = utc + rule.BaseUtcOffsetDelta;
2223 DaylightTime daylightTime = GetDaylightTime(Year, rule);
2224 bool ignoreYearAdjustment =
false;
2226 if (rule.IsStartDateMarkerForBeginningOfYear() && daylightTime.
Start.
Year >
DateTime.MinValue.Year)
2228 AdjustmentRule adjustmentRuleForTime = zone.GetAdjustmentRuleForTime(
new DateTime(daylightTime.
Start.
Year - 1, 12, 31));
2229 if (adjustmentRuleForTime !=
null && adjustmentRuleForTime.IsEndDateMarkerForEndOfYear())
2232 dateTime = daylightTime2.
Start - utc - adjustmentRuleForTime.BaseUtcOffsetDelta;
2233 ignoreYearAdjustment =
true;
2242 dateTime = daylightTime.
Start - t;
2245 if (rule.IsEndDateMarkerForEndOfYear() && daylightTime.
End.
Year <
DateTime.MaxValue.Year)
2247 AdjustmentRule adjustmentRuleForTime2 = zone.GetAdjustmentRuleForTime(
new DateTime(daylightTime.
End.
Year + 1, 1, 1));
2248 if (adjustmentRuleForTime2 !=
null && adjustmentRuleForTime2.IsStartDateMarkerForBeginningOfYear())
2250 if (adjustmentRuleForTime2.IsEndDateMarkerForEndOfYear())
2252 dateTime2 =
new DateTime(daylightTime.
End.
Year + 1, 12, 31) - utc - adjustmentRuleForTime2.BaseUtcOffsetDelta - adjustmentRuleForTime2.DaylightDelta;
2256 DaylightTime daylightTime3 = GetDaylightTime(daylightTime.
End.
Year + 1, adjustmentRuleForTime2);
2257 dateTime2 = daylightTime3.
End - utc - adjustmentRuleForTime2.BaseUtcOffsetDelta - adjustmentRuleForTime2.DaylightDelta;
2259 ignoreYearAdjustment =
true;
2263 dateTime2 =
new DateTime(daylightTime.
End.
Year + 1, 1, 1, 0, 0, 0).AddTicks(-1
L) - t - rule.DaylightDelta;
2268 dateTime2 = daylightTime.
End - t - rule.DaylightDelta;
2274 t2 = dateTime2 - daylightTime.
Delta;
2280 t3 = dateTime - daylightTime.
Delta;
2282 bool flag = CheckIsDst(dateTime, time, dateTime2, ignoreYearAdjustment);
2285 isAmbiguousLocalDst = (time >= t2 && time < t3);
2286 if (!isAmbiguousLocalDst && t2.Year != t3.Year)
2290 DateTime dateTime3 = t2.AddYears(1);
2291 DateTime dateTime4 = t3.AddYears(1);
2292 isAmbiguousLocalDst = (time >= t2 && time < t3);
2294 catch (ArgumentOutOfRangeException)
2297 if (!isAmbiguousLocalDst)
2301 DateTime dateTime3 = t2.AddYears(-1);
2302 DateTime dateTime4 = t3.AddYears(-1);
2303 isAmbiguousLocalDst = (time >= t2 && time < t3);
2306 catch (ArgumentOutOfRangeException)
2318 if (!ignoreYearAdjustment)
2320 int year = startTime.Year;
2321 int year2 = endTime.Year;
2324 endTime = endTime.AddYears(year - year2);
2326 int year3 = time.Year;
2329 time = time.AddYears(year - year3);
2332 if (startTime > endTime)
2334 return time < endTime || time >= startTime;
2336 return time >= startTime && time < endTime;
2339 private static bool GetIsAmbiguousTime(
DateTime time, AdjustmentRule rule,
DaylightTime daylightTime)
2341 bool result =
false;
2342 if (rule ==
null || rule.DaylightDelta == TimeSpan.Zero)
2348 if (rule.DaylightDelta > TimeSpan.Zero)
2350 if (rule.IsEndDateMarkerForEndOfYear())
2354 t = daylightTime.
End;
2355 t2 = daylightTime.
End - rule.DaylightDelta;
2359 if (rule.IsStartDateMarkerForBeginningOfYear())
2363 t = daylightTime.
Start;
2364 t2 = daylightTime.
Start + rule.DaylightDelta;
2366 result = (time >= t2 && time < t);
2367 if (!result && t.Year != t2.Year)
2373 result = (time >= t4 && time < t3);
2375 catch (ArgumentOutOfRangeException)
2384 result = (time >= t4 && time < t3);
2387 catch (ArgumentOutOfRangeException)
2396 private static bool GetIsInvalidTime(
DateTime time, AdjustmentRule rule,
DaylightTime daylightTime)
2398 bool result =
false;
2399 if (rule ==
null || rule.DaylightDelta == TimeSpan.Zero)
2405 if (rule.DaylightDelta < TimeSpan.Zero)
2407 if (rule.IsEndDateMarkerForEndOfYear())
2411 t = daylightTime.
End;
2412 t2 = daylightTime.
End - rule.DaylightDelta;
2416 if (rule.IsStartDateMarkerForBeginningOfYear())
2420 t = daylightTime.
Start;
2421 t2 = daylightTime.
Start + rule.DaylightDelta;
2423 result = (time >= t && time < t2);
2424 if (!result && t.Year != t2.Year)
2430 result = (time >= t3 && time < t4);
2432 catch (ArgumentOutOfRangeException)
2441 result = (time >= t3 && time < t4);
2444 catch (ArgumentOutOfRangeException)
2453 [SecuritySafeCritical]
2454 private static TimeZoneInfo GetLocalTimeZone(CachedData cachedData)
2457 Win32Native.DynamicTimeZoneInformation lpDynamicTimeZoneInformation =
default(Win32Native.DynamicTimeZoneInformation);
2458 long num = UnsafeNativeMethods.GetDynamicTimeZoneInformation(out lpDynamicTimeZoneInformation);
2463 Win32Native.TimeZoneInformation timeZoneInformation =
new Win32Native.TimeZoneInformation(lpDynamicTimeZoneInformation);
2464 bool dstDisabled = lpDynamicTimeZoneInformation.DynamicDaylightTimeDisabled;
2465 if (!
string.IsNullOrEmpty(lpDynamicTimeZoneInformation.TimeZoneKeyName) && TryGetTimeZone(lpDynamicTimeZoneInformation.TimeZoneKeyName, dstDisabled, out TimeZoneInfo value, out Exception _, cachedData) == TimeZoneInfoResult.Success)
2469 text = FindIdFromTimeZoneInformation(timeZoneInformation, out dstDisabled);
2470 if (text !=
null && TryGetTimeZone(text, dstDisabled, out TimeZoneInfo value2, out Exception _, cachedData) == TimeZoneInfoResult.Success)
2474 return GetLocalTimeZoneFromWin32Data(timeZoneInformation, dstDisabled);
2478 private static TimeZoneInfo GetLocalTimeZoneFromWin32Data(Win32Native.TimeZoneInformation timeZoneInformation,
bool dstDisabled)
2482 return new TimeZoneInfo(timeZoneInformation, dstDisabled);
2484 catch (ArgumentException)
2487 catch (InvalidTimeZoneException)
2494 return new TimeZoneInfo(timeZoneInformation, dstDisabled:
true);
2496 catch (ArgumentException)
2499 catch (InvalidTimeZoneException)
2514 [__DynamicallyInvokable]
2525 if (
id.Length == 0 ||
id.Length > 255 ||
id.Contains(
"\0"))
2529 CachedData cachedData = s_cachedData;
2530 TimeZoneInfoResult timeZoneInfoResult;
2535 timeZoneInfoResult = TryGetTimeZone(
id, dstDisabled:
false, out value, out e, cachedData);
2537 switch (timeZoneInfoResult)
2539 case TimeZoneInfoResult.Success:
2541 case TimeZoneInfoResult.InvalidTimeZoneException:
2543 case TimeZoneInfoResult.SecurityException:
2553 AdjustmentRule adjustmentRuleForTime = zone.GetAdjustmentRuleForTime(time);
2554 if (adjustmentRuleForTime !=
null)
2556 timeSpan += adjustmentRuleForTime.BaseUtcOffsetDelta;
2557 if (adjustmentRuleForTime.HasDaylightSaving)
2559 DaylightTime daylightTime = GetDaylightTime(time.
Year, adjustmentRuleForTime);
2560 bool isDaylightSavings = GetIsDaylightSavings(time, adjustmentRuleForTime, daylightTime, flags);
2561 timeSpan += (isDaylightSavings ? adjustmentRuleForTime.DaylightDelta :
TimeSpan.
Zero);
2567 private static TimeSpan GetUtcOffsetFromUtc(
DateTime time, TimeZoneInfo zone)
2569 bool isDaylightSavings;
2570 return GetUtcOffsetFromUtc(time, zone, out isDaylightSavings);
2573 private static TimeSpan GetUtcOffsetFromUtc(
DateTime time, TimeZoneInfo zone, out
bool isDaylightSavings)
2575 bool isAmbiguousLocalDst;
2576 return GetUtcOffsetFromUtc(time, zone, out isDaylightSavings, out isAmbiguousLocalDst);
2579 internal static TimeSpan GetDateTimeNowUtcOffsetFromUtc(
DateTime time, out
bool isAmbiguousLocalDst)
2582 isAmbiguousLocalDst =
false;
2583 int year = time.Year;
2584 OffsetAndRule oneYearLocalFromUtc = s_cachedData.GetOneYearLocalFromUtc(year);
2585 TimeSpan timeSpan = oneYearLocalFromUtc.offset;
2586 if (oneYearLocalFromUtc.rule !=
null)
2588 timeSpan += oneYearLocalFromUtc.rule.BaseUtcOffsetDelta;
2589 if (oneYearLocalFromUtc.rule.HasDaylightSaving)
2591 flag = GetIsDaylightSavingsFromUtc(time, year, oneYearLocalFromUtc.offset, oneYearLocalFromUtc.rule, out isAmbiguousLocalDst,
Local);
2592 timeSpan += (flag ? oneYearLocalFromUtc.rule.DaylightDelta : TimeSpan.Zero);
2598 internal static TimeSpan GetUtcOffsetFromUtc(
DateTime time, TimeZoneInfo zone, out
bool isDaylightSavings, out
bool isAmbiguousLocalDst)
2600 isDaylightSavings =
false;
2601 isAmbiguousLocalDst =
false;
2602 TimeSpan timeSpan = zone.BaseUtcOffset;
2603 AdjustmentRule adjustmentRuleForTime;
2605 if (time > s_maxDateOnly)
2607 adjustmentRuleForTime = zone.GetAdjustmentRuleForTime(
DateTime.MaxValue);
2610 else if (time < s_minDateOnly)
2612 adjustmentRuleForTime = zone.GetAdjustmentRuleForTime(
DateTime.MinValue);
2617 DateTime dateTime = time + timeSpan;
2618 year = dateTime.Year;
2619 adjustmentRuleForTime = zone.GetAdjustmentRuleForTime(dateTime);
2621 if (adjustmentRuleForTime !=
null)
2623 timeSpan += adjustmentRuleForTime.BaseUtcOffsetDelta;
2624 if (adjustmentRuleForTime.HasDaylightSaving)
2626 isDaylightSavings = GetIsDaylightSavingsFromUtc(time, year, zone.m_baseUtcOffset, adjustmentRuleForTime, out isAmbiguousLocalDst, zone);
2627 timeSpan += (isDaylightSavings ? adjustmentRuleForTime.DaylightDelta : TimeSpan.Zero);
2634 private static bool TransitionTimeFromTimeZoneInformation(Win32Native.RegistryTimeZoneInformation timeZoneInformation, out TransitionTime transitionTime,
bool readStartDate)
2636 if (timeZoneInformation.StandardDate.Month == 0)
2638 transitionTime =
default(TransitionTime);
2643 if (timeZoneInformation.DaylightDate.Year == 0)
2645 transitionTime = TransitionTime.CreateFloatingDateRule(
new DateTime(1, 1, 1, timeZoneInformation.DaylightDate.Hour, timeZoneInformation.DaylightDate.Minute, timeZoneInformation.DaylightDate.Second, timeZoneInformation.DaylightDate.Milliseconds), timeZoneInformation.DaylightDate.Month, timeZoneInformation.DaylightDate.Day, (
DayOfWeek)timeZoneInformation.DaylightDate.DayOfWeek);
2649 transitionTime = TransitionTime.CreateFixedDateRule(
new DateTime(1, 1, 1, timeZoneInformation.DaylightDate.Hour, timeZoneInformation.DaylightDate.Minute, timeZoneInformation.DaylightDate.Second, timeZoneInformation.DaylightDate.Milliseconds), timeZoneInformation.DaylightDate.Month, timeZoneInformation.DaylightDate.Day);
2652 else if (timeZoneInformation.StandardDate.Year == 0)
2654 transitionTime = TransitionTime.CreateFloatingDateRule(
new DateTime(1, 1, 1, timeZoneInformation.StandardDate.Hour, timeZoneInformation.StandardDate.Minute, timeZoneInformation.StandardDate.Second, timeZoneInformation.StandardDate.Milliseconds), timeZoneInformation.StandardDate.Month, timeZoneInformation.StandardDate.Day, (
DayOfWeek)timeZoneInformation.StandardDate.DayOfWeek);
2658 transitionTime = TransitionTime.CreateFixedDateRule(
new DateTime(1, 1, 1, timeZoneInformation.StandardDate.Hour, timeZoneInformation.StandardDate.Minute, timeZoneInformation.StandardDate.Second, timeZoneInformation.StandardDate.Milliseconds), timeZoneInformation.StandardDate.Month, timeZoneInformation.StandardDate.Day);
2663 private static DateTime TransitionTimeToDateTime(
int year, TransitionTime transitionTime)
2667 if (transitionTime.IsFixedDateRule)
2669 int num =
DateTime.DaysInMonth(year, transitionTime.Month);
2670 result =
new DateTime(year, transitionTime.Month, (num < transitionTime.Day) ? num : transitionTime.Day, timeOfDay.Hour, timeOfDay.Minute, timeOfDay.Second, timeOfDay.Millisecond);
2672 else if (transitionTime.Week <= 4)
2674 result =
new DateTime(year, transitionTime.Month, 1, timeOfDay.Hour, timeOfDay.Minute, timeOfDay.Second, timeOfDay.Millisecond);
2675 int dayOfWeek = (int)result.DayOfWeek;
2676 int num2 = (
int)(transitionTime.DayOfWeek - dayOfWeek);
2681 num2 += 7 * (transitionTime.Week - 1);
2684 result = result.AddDays(num2);
2690 int day =
DateTime.DaysInMonth(year, transitionTime.Month);
2691 result =
new DateTime(year, transitionTime.Month, day, timeOfDay.Hour, timeOfDay.Minute, timeOfDay.Second, timeOfDay.Millisecond);
2692 int dayOfWeek2 = (int)result.DayOfWeek;
2693 int num3 = (
int)(dayOfWeek2 - transitionTime.DayOfWeek);
2700 result = result.AddDays(-num3);
2708 private static bool TryCreateAdjustmentRules(
string id, Win32Native.RegistryTimeZoneInformation defaultTimeZoneInformation, out AdjustmentRule[] rules, out Exception e,
int defaultBaseUtcOffset)
2713 using (
RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(
string.Format(
CultureInfo.
InvariantCulture,
"{0}\\{1}\\Dynamic DST",
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones",
id), RegistryKeyPermissionCheck.Default,
RegistryRights.ExecuteKey))
2715 if (registryKey ==
null)
2717 AdjustmentRule adjustmentRule = CreateAdjustmentRuleFromTimeZoneInformation(defaultTimeZoneInformation,
DateTime.MinValue.Date,
DateTime.MaxValue.Date, defaultBaseUtcOffset);
2718 if (adjustmentRule ==
null)
2724 rules =
new AdjustmentRule[1];
2725 rules[0] = adjustmentRule;
2729 int num = (int)registryKey.GetValue(
"FirstEntry", -1, RegistryValueOptions.None);
2730 int num2 = (int)registryKey.GetValue(
"LastEntry", -1, RegistryValueOptions.None);
2731 if (num == -1 || num2 == -1 || num > num2)
2737 if (array ==
null || array.Length != 44)
2742 Win32Native.RegistryTimeZoneInformation timeZoneInformation =
new Win32Native.RegistryTimeZoneInformation(array);
2745 AdjustmentRule adjustmentRule2 = CreateAdjustmentRuleFromTimeZoneInformation(timeZoneInformation,
DateTime.MinValue.Date,
DateTime.MaxValue.Date, defaultBaseUtcOffset);
2746 if (adjustmentRule2 ==
null)
2752 rules =
new AdjustmentRule[1];
2753 rules[0] = adjustmentRule2;
2758 AdjustmentRule adjustmentRule3 = CreateAdjustmentRuleFromTimeZoneInformation(timeZoneInformation,
DateTime.MinValue.Date,
new DateTime(num, 12, 31), defaultBaseUtcOffset);
2759 if (adjustmentRule3 !=
null)
2761 list.Add(adjustmentRule3);
2763 for (
int i = num + 1; i < num2; i++)
2766 if (array ==
null || array.Length != 44)
2771 timeZoneInformation =
new Win32Native.RegistryTimeZoneInformation(array);
2772 AdjustmentRule adjustmentRule4 = CreateAdjustmentRuleFromTimeZoneInformation(timeZoneInformation,
new DateTime(i, 1, 1),
new DateTime(i, 12, 31), defaultBaseUtcOffset);
2773 if (adjustmentRule4 !=
null)
2775 list.Add(adjustmentRule4);
2779 timeZoneInformation =
new Win32Native.RegistryTimeZoneInformation(array);
2780 if (array ==
null || array.Length != 44)
2785 AdjustmentRule adjustmentRule5 = CreateAdjustmentRuleFromTimeZoneInformation(timeZoneInformation,
new DateTime(num2, 1, 1),
DateTime.MaxValue.Date, defaultBaseUtcOffset);
2786 if (adjustmentRule5 !=
null)
2788 list.Add(adjustmentRule5);
2790 rules = list.ToArray();
2791 if (rules !=
null && rules.Length == 0)
2797 catch (InvalidCastException ex)
2803 catch (ArgumentOutOfRangeException ex2)
2809 catch (ArgumentException ex3)
2819 private static bool TryCompareStandardDate(Win32Native.TimeZoneInformation timeZone, Win32Native.RegistryTimeZoneInformation registryTimeZoneInfo)
2821 if (timeZone.Bias == registryTimeZoneInfo.Bias && timeZone.StandardBias == registryTimeZoneInfo.StandardBias && timeZone.StandardDate.Year == registryTimeZoneInfo.StandardDate.Year && timeZone.StandardDate.Month == registryTimeZoneInfo.StandardDate.Month && timeZone.StandardDate.DayOfWeek == registryTimeZoneInfo.StandardDate.DayOfWeek && timeZone.StandardDate.Day == registryTimeZoneInfo.StandardDate.Day && timeZone.StandardDate.Hour == registryTimeZoneInfo.StandardDate.Hour && timeZone.StandardDate.Minute == registryTimeZoneInfo.StandardDate.Minute && timeZone.StandardDate.Second == registryTimeZoneInfo.StandardDate.Second)
2823 return timeZone.StandardDate.Milliseconds == registryTimeZoneInfo.StandardDate.Milliseconds;
2828 [SecuritySafeCritical]
2829 private static bool TryCompareTimeZoneInformationToRegistry(Win32Native.TimeZoneInformation timeZone,
string id, out
bool dstDisabled)
2831 dstDisabled =
false;
2839 if (registryKey ==
null)
2843 byte[] array = (
byte[])registryKey.GetValue(
"TZI",
null, RegistryValueOptions.None);
2844 if (array ==
null || array.Length != 44)
2848 Win32Native.RegistryTimeZoneInformation registryTimeZoneInformation =
new Win32Native.RegistryTimeZoneInformation(array);
2849 if (!TryCompareStandardDate(timeZone, registryTimeZoneInformation))
2853 bool flag = dstDisabled || CheckDaylightSavingTimeNotSupported(timeZone) || (timeZone.DaylightBias == registryTimeZoneInformation.DaylightBias && timeZone.DaylightDate.Year == registryTimeZoneInformation.DaylightDate.Year && timeZone.DaylightDate.Month == registryTimeZoneInformation.DaylightDate.Month && timeZone.DaylightDate.DayOfWeek == registryTimeZoneInformation.DaylightDate.DayOfWeek && timeZone.DaylightDate.Day == registryTimeZoneInformation.DaylightDate.Day && timeZone.DaylightDate.Hour == registryTimeZoneInformation.DaylightDate.Hour && timeZone.DaylightDate.Minute == registryTimeZoneInformation.DaylightDate.Minute && timeZone.DaylightDate.Second == registryTimeZoneInformation.DaylightDate.Second && timeZone.DaylightDate.Milliseconds == registryTimeZoneInformation.DaylightDate.Milliseconds);
2856 string strA = registryKey.GetValue(
"Std",
string.Empty, RegistryValueOptions.None) as string;
2857 flag = (
string.Compare(strA, timeZone.StandardName,
StringComparison.Ordinal) == 0);
2868 [SecuritySafeCritical]
2870 private static string TryGetLocalizedNameByMuiNativeResource(
string resource)
2872 if (
string.IsNullOrEmpty(resource))
2874 return string.Empty;
2876 string[] array = resource.Split(
new char[1]
2880 if (array.Length != 2)
2882 return string.Empty;
2884 string path = Environment.UnsafeGetFolderPath(Environment.SpecialFolder.System);
2885 string path2 = array[0].TrimStart(
'@');
2891 catch (ArgumentException)
2893 return string.Empty;
2897 return string.Empty;
2902 StringBuilder stringBuilder = StringBuilderCache.Acquire(260);
2903 stringBuilder.
Length = 260;
2904 int fileMuiPathLength = 260;
2905 int languageLength = 0;
2906 long enumerator = 0
L;
2907 if (!UnsafeNativeMethods.GetFileMUIPath(16, filePath,
null, ref languageLength, stringBuilder, ref fileMuiPathLength, ref enumerator))
2909 StringBuilderCache.Release(stringBuilder);
2910 return string.Empty;
2912 return TryGetLocalizedNameByNativeResource(StringBuilderCache.GetStringAndRelease(stringBuilder), result);
2914 catch (EntryPointNotFoundException)
2916 return string.Empty;
2921 private static string TryGetLocalizedNameByNativeResource(
string filePath,
int resource)
2923 using (SafeLibraryHandle safeLibraryHandle = UnsafeNativeMethods.LoadLibraryEx(filePath, IntPtr.Zero, 2))
2925 if (!safeLibraryHandle.IsInvalid)
2927 StringBuilder stringBuilder = StringBuilderCache.Acquire(500);
2928 stringBuilder.
Length = 500;
2929 if (UnsafeNativeMethods.LoadString(safeLibraryHandle, resource, stringBuilder, stringBuilder.
Length) != 0)
2931 return StringBuilderCache.GetStringAndRelease(stringBuilder);
2935 return string.Empty;
2938 private static bool TryGetLocalizedNamesByRegistryKey(RegistryKey key, out
string displayName, out
string standardName, out
string daylightName)
2940 displayName =
string.Empty;
2941 standardName =
string.Empty;
2942 daylightName =
string.Empty;
2943 string text = key.GetValue(
"MUI_Display",
string.Empty, RegistryValueOptions.None) as string;
2944 string text2 = key.GetValue(
"MUI_Std",
string.Empty, RegistryValueOptions.None) as string;
2945 string text3 = key.GetValue(
"MUI_Dlt",
string.Empty, RegistryValueOptions.None) as string;
2946 if (!
string.IsNullOrEmpty(text))
2948 displayName = TryGetLocalizedNameByMuiNativeResource(text);
2950 if (!
string.IsNullOrEmpty(text2))
2952 standardName = TryGetLocalizedNameByMuiNativeResource(text2);
2954 if (!
string.IsNullOrEmpty(text3))
2956 daylightName = TryGetLocalizedNameByMuiNativeResource(text3);
2958 if (
string.IsNullOrEmpty(displayName))
2960 displayName = (key.GetValue(
"Display",
string.Empty, RegistryValueOptions.None) as string);
2962 if (
string.IsNullOrEmpty(standardName))
2964 standardName = (key.GetValue(
"Std",
string.Empty, RegistryValueOptions.None) as string);
2966 if (
string.IsNullOrEmpty(daylightName))
2968 daylightName = (key.GetValue(
"Dlt",
string.Empty, RegistryValueOptions.None) as string);
2973 [SecuritySafeCritical]
2974 private static TimeZoneInfoResult TryGetTimeZoneByRegistryKey(
string id, out TimeZoneInfo value, out Exception e)
2984 if (registryKey ==
null)
2987 return TimeZoneInfoResult.TimeZoneNotFoundException;
2989 byte[] array = registryKey.GetValue(
"TZI",
null, RegistryValueOptions.None) as
byte[];
2990 if (array ==
null || array.Length != 44)
2993 return TimeZoneInfoResult.InvalidTimeZoneException;
2995 Win32Native.RegistryTimeZoneInformation registryTimeZoneInformation =
new Win32Native.RegistryTimeZoneInformation(array);
2996 if (!TryCreateAdjustmentRules(
id, registryTimeZoneInformation, out AdjustmentRule[] rules, out e, registryTimeZoneInformation.Bias))
2999 return TimeZoneInfoResult.InvalidTimeZoneException;
3001 if (TryGetLocalizedNamesByRegistryKey(registryKey, out
string displayName, out
string standardName, out
string daylightName))
3005 value =
new TimeZoneInfo(
id,
new TimeSpan(0, -registryTimeZoneInformation.Bias, 0), displayName, standardName, daylightName, rules, disableDaylightSavingTime:
false);
3006 return TimeZoneInfoResult.Success;
3008 catch (ArgumentException ex)
3012 return TimeZoneInfoResult.InvalidTimeZoneException;
3014 catch (InvalidTimeZoneException ex2)
3018 return TimeZoneInfoResult.InvalidTimeZoneException;
3022 return TimeZoneInfoResult.InvalidTimeZoneException;
3031 private static TimeZoneInfoResult TryGetTimeZone(
string id,
bool dstDisabled, out TimeZoneInfo value, out Exception e, CachedData cachedData)
3033 TimeZoneInfoResult result = TimeZoneInfoResult.Success;
3035 TimeZoneInfo value2 =
null;
3036 if (cachedData.m_systemTimeZones !=
null && cachedData.m_systemTimeZones.TryGetValue(
id, out value2))
3038 if (dstDisabled && value2.m_supportsDaylightSavingTime)
3040 value =
CreateCustomTimeZone(value2.m_id, value2.m_baseUtcOffset, value2.m_displayName, value2.m_standardDisplayName);
3044 value =
new TimeZoneInfo(value2.m_id, value2.m_baseUtcOffset, value2.m_displayName, value2.m_standardDisplayName, value2.m_daylightDisplayName, value2.m_adjustmentRules, disableDaylightSavingTime:
false);
3048 if (!cachedData.m_allSystemTimeZonesRead)
3050 result = TryGetTimeZoneByRegistryKey(
id, out value2, out e);
3051 if (result == TimeZoneInfoResult.Success)
3053 if (cachedData.m_systemTimeZones ==
null)
3057 cachedData.m_systemTimeZones.Add(
id, value2);
3058 if (dstDisabled && value2.m_supportsDaylightSavingTime)
3060 value =
CreateCustomTimeZone(value2.m_id, value2.m_baseUtcOffset, value2.m_displayName, value2.m_standardDisplayName);
3064 value =
new TimeZoneInfo(value2.m_id, value2.m_baseUtcOffset, value2.m_displayName, value2.m_standardDisplayName, value2.m_daylightDisplayName, value2.m_adjustmentRules, disableDaylightSavingTime:
false);
3074 result = TimeZoneInfoResult.TimeZoneNotFoundException;
3080 internal static bool UtcOffsetOutOfRange(TimeSpan offset)
3082 if (!(offset.TotalHours < -14.0))
3084 return offset.TotalHours > 14.0;
3089 private static void ValidateTimeZoneInfo(
string id, TimeSpan baseUtcOffset, AdjustmentRule[] adjustmentRules, out
bool adjustmentRulesSupportDst)
3093 throw new ArgumentNullException(
"id");
3097 throw new ArgumentException(Environment.GetResourceString(
"Argument_InvalidId",
id),
"id");
3099 if (UtcOffsetOutOfRange(baseUtcOffset))
3101 throw new ArgumentOutOfRangeException(
"baseUtcOffset", Environment.GetResourceString(
"ArgumentOutOfRange_UtcOffset"));
3103 if (baseUtcOffset.Ticks % 600000000 != 0
L)
3105 throw new ArgumentException(Environment.GetResourceString(
"Argument_TimeSpanHasSeconds"),
"baseUtcOffset");
3107 adjustmentRulesSupportDst =
false;
3108 if (adjustmentRules ==
null || adjustmentRules.Length == 0)
3112 adjustmentRulesSupportDst =
true;
3113 AdjustmentRule adjustmentRule =
null;
3114 AdjustmentRule adjustmentRule2 =
null;
3118 if (num < adjustmentRules.Length)
3120 adjustmentRule = adjustmentRule2;
3121 adjustmentRule2 = adjustmentRules[num];
3122 if (adjustmentRule2 ==
null)
3124 throw new InvalidTimeZoneException(Environment.GetResourceString(
"Argument_AdjustmentRulesNoNulls"));
3126 if (UtcOffsetOutOfRange(baseUtcOffset + adjustmentRule2.DaylightDelta))
3128 throw new InvalidTimeZoneException(Environment.GetResourceString(
"ArgumentOutOfRange_UtcOffsetAndDaylightDelta"));
3130 if (adjustmentRule !=
null && adjustmentRule2.DateStart <= adjustmentRule.DateEnd)
3139 throw new InvalidTimeZoneException(Environment.GetResourceString(
"Argument_AdjustmentRulesOutOfOrder"));
Represents any time zone in the world.
static CultureInfo InvariantCulture
Gets the T:System.Globalization.CultureInfo object that is culture-independent (invariant).
TimeSpan [] GetAmbiguousTimeOffsets(DateTimeOffset dateTimeOffset)
Returns information about the possible dates and times that an ambiguous date and time can be mapped ...
override int GetHashCode()
Serves as a hash function for hashing algorithms and data structures such as hash tables.
DateTime DateEnd
Gets the date when the adjustment rule ceases to be in effect.
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
FileIOPermissionAccess
Specifies the type of file access requested.
DateTime DateStart
Gets the date when the adjustment rule takes effect.
int Month
Gets the month in which the time change occurs.
TimeSpan BaseUtcOffset
Gets the time difference between the current time zone's standard time and Coordinated Universal Time...
bool Equals(TimeZoneInfo other)
Determines whether the current T:System.TimeZoneInfo object and another T:System.TimeZoneInfo object ...
Represents a point in time, typically expressed as a date and time of day, relative to Coordinated Un...
unsafe override string ToString()
Converts the value of this instance to a T:System.String.
bool IsFixedDateRule
Gets a value indicating whether the time change occurs at a fixed date and time (such as November 1) ...
static DateTime ConvertTime(DateTime dateTime, TimeZoneInfo sourceTimeZone, TimeZoneInfo destinationTimeZone)
Converts a time from one time zone to another.
static string Combine(string path1, string path2)
Combines two strings into a path.
bool IsDaylightSavingTime(DateTimeOffset dateTimeOffset)
Indicates whether a specified date and time falls in the range of daylight saving time for the time z...
bool IsInvalidTime(DateTime dateTime)
Indicates whether a particular date and time is invalid.
static readonly DateTimeOffset MinValue
Represents the earliest possible T:System.DateTimeOffset value. This field is read-only.
Provides the base class for a generic read-only collection.
bool IsAmbiguousTime(DateTimeOffset dateTimeOffset)
Determines whether a particular date and time in a particular time zone is ambiguous and can be mappe...
StringComparison
Specifies the culture, case, and sort rules to be used by certain overloads of the M:System....
static readonly DateTime MinValue
Represents the smallest possible value of T:System.DateTime. This field is read-only.
static DateTime ConvertTimeBySystemTimeZoneId(DateTime dateTime, string destinationTimeZoneId)
Converts a time to the time in another time zone based on the time zone's identifier.
Controls the ability to access registry variables. This class cannot be inherited.
override int GetHashCode()
Serves as a hash function for hashing algorithms and data structures such as hash tables.
RegistryRights
Specifies the access control rights that can be applied to registry objects.
override bool Equals(object obj)
Determines whether the current T:System.TimeZoneInfo object and another object are equal.
override int GetHashCode()
Serves as a hash function for hashing algorithms and data structures such as hash tables.
Indicates that a class is to be notified when deserialization of the entire object graph has been com...
Might cause a resource leak on termination, if not protected by a safe handle or some other means of ...
string Id
Gets the time zone identifier.
int Day
Gets the day on which the time change occurs.
TimeSpan Delta
Gets the time interval that represents the difference between standard time and daylight saving time.
bool IsAmbiguousTime(DateTime dateTime)
Determines whether a particular date and time in a particular time zone is ambiguous and can be mappe...
TimeSpan TimeOfDay
Gets the time of day for this instance.
Represents an instant in time, typically expressed as a date and time of day. To browse the ....
static DateTime ConvertTimeBySystemTimeZoneId(DateTime dateTime, string sourceTimeZoneId, string destinationTimeZoneId)
Converts a time from one time zone to another based on time zone identifiers.
Defines a method that a type implements to compare two objects.
Describes the source and destination of a given serialized stream, and provides an additional caller-...
int Week
Gets the week of the month in which a time change occurs.
A type representing a date and time value.
IPermission AddPermission(IPermission perm)
Adds a specified permission to the T:System.Security.PermissionSet.
NumberStyles
Determines the styles permitted in numeric string arguments that are passed to the Parse and TryParse...
static TimeZoneInfo Utc
Gets a T:System.TimeZoneInfo object that represents the Coordinated Universal Time (UTC) zone.
int Second
Gets the seconds component of the date represented by this instance.
The exception that is thrown when a time zone cannot be found.
long Ticks
Gets the number of ticks that represents the date and time of the current T:System....
TimeSpan GetUtcOffset(DateTimeOffset dateTimeOffset)
Calculates the offset or difference between the time in this time zone and Coordinated Universal Time...
int Hour
Gets the hour component of the date represented by this instance.
long Ticks
Gets the number of ticks that represent the value of the current T:System.TimeSpan structure.
static bool operator==(TransitionTime t1, TransitionTime t2)
Determines whether two specified T:System.TimeZoneInfo.TransitionTime objects are equal.
SecurityAction
Specifies the security actions that can be performed using declarative security.
int Year
Gets the year component of the date represented by this instance.
Provides information about, and means to manipulate, the current environment and platform....
static DateTime ConvertTimeFromUtc(DateTime dateTime, TimeZoneInfo destinationTimeZone)
Converts a Coordinated Universal Time (UTC) to the time in a specified time zone.
int Compare(T x, T y)
Compares two objects and returns a value indicating whether one is less than, equal to,...
static TimeZoneInfo CreateCustomTimeZone(string id, TimeSpan baseUtcOffset, string displayName, string standardDisplayName, string daylightDisplayName, AdjustmentRule[] adjustmentRules, bool disableDaylightSavingTime)
Creates a custom time zone with a specified identifier, an offset from Coordinated Universal Time (UT...
StringBuilder Append(char value, int repeatCount)
Appends a specified number of copies of the string representation of a Unicode character to this inst...
DateTimeKind Kind
Gets a value that indicates whether the time represented by this instance is based on local time,...
Represents a collection that can contain many different types of permissions.
DateTime DateTime
Gets a T:System.DateTime value that represents the date and time of the current T:System....
DateTime End
Gets the object that represents the date and time when the daylight saving period ends.
static DateTimeOffset ConvertTime(DateTimeOffset dateTimeOffset, TimeZoneInfo destinationTimeZone)
Converts a time to the time in a particular time zone.
TimeSpan GetUtcOffset(DateTime dateTime)
Calculates the offset or difference between the time in this time zone and Coordinated Universal Time...
void OnDeserialization(object sender)
Runs when the entire object graph has been deserialized.
TransitionTime DaylightTransitionStart
Gets information about the annual transition from standard time to daylight saving time.
StringSplitOptions
Specifies whether applicable Overload:System.String.Split method overloads include or omit empty subs...
int Length
Gets or sets the length of the current T:System.Text.StringBuilder object.
TimeSpan DaylightDelta
Gets the amount of time that is required to form the time zone's daylight saving time....
int Minute
Gets the minute component of the date represented by this instance.
Provides information about a specific time change, such as the change from daylight saving time to st...
static TransitionTime CreateFloatingDateRule(DateTime timeOfDay, int month, int week, DayOfWeek dayOfWeek)
Defines a time change that uses a floating-date rule (that is, a time change that occurs on a specifi...
DayOfWeek DayOfWeek
Gets the day of the week on which the time change occurs.
The exception thrown when an error occurs during serialization or deserialization.
override string ToString()
Returns the current T:System.TimeZoneInfo object's display name.
static readonly TimeSpan Zero
Represents the zero T:System.TimeSpan value. This field is read-only.
static DateTime ConvertTimeToUtc(DateTime dateTime, TimeZoneInfo sourceTimeZone)
Converts the time in a specified time zone to Coordinated Universal Time (UTC).
int Day
Gets the day of the month represented by this instance.
DateTime Start
Gets the object that represents the date and time when the daylight saving period begins.
string DisplayName
Gets the general display name that represents the time zone.
Stores all the data needed to serialize or deserialize an object. This class cannot be inherited.
TimeSpan [] GetAmbiguousTimeOffsets(DateTime dateTime)
Returns information about the possible dates and times that an ambiguous date and time can be mapped ...
Represents a mutable string of characters. This class cannot be inherited.To browse the ....
static AdjustmentRule CreateAdjustmentRule(DateTime dateStart, DateTime dateEnd, TimeSpan daylightDelta, TransitionTime daylightTransitionStart, TransitionTime daylightTransitionEnd)
Creates a new adjustment rule for a particular time zone.
TransitionTime DaylightTransitionEnd
Gets information about the annual transition from daylight saving time back to standard time.
Represents a collection of keys and values.To browse the .NET Framework source code for this type,...
The exception that is thrown when one of the arguments provided to a method is not valid.
static TimeZoneInfo FromSerializedString(string source)
Deserializes a string to re-create an original serialized T:System.TimeZoneInfo object.
static TimeZoneInfo FindSystemTimeZoneById(string id)
Retrieves a T:System.TimeZoneInfo object from the registry based on its identifier.
override bool Equals(object obj)
Determines whether an object has identical values to the current T:System.TimeZoneInfo....
bool SupportsDaylightSavingTime
Gets a value indicating whether the time zone has any daylight saving time rules.
Allows an object to control its own serialization and deserialization.
DateTime AddMilliseconds(double value)
Returns a new T:System.DateTime that adds the specified number of milliseconds to the value of this i...
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
PermissionState
Specifies whether a permission should have all or no access to resources at creation.
Represents errors that occur during application execution.To browse the .NET Framework source code fo...
int Month
Gets the month component of the date represented by this instance.
Defines a generalized method that a value type or class implements to create a type-specific method f...
DateTimeKind
Specifies whether a T:System.DateTime object represents a local time, a Coordinated Universal Time (U...
static readonly DateTimeOffset MaxValue
Represents the greatest possible value of T:System.DateTimeOffset. This field is read-only.
bool Equals(TransitionTime other)
Determines whether the current T:System.TimeZoneInfo.TransitionTime object has identical values to a ...
static TransitionTime CreateFixedDateRule(DateTime timeOfDay, int month, int day)
Defines a time change that uses a fixed-date rule (that is, a time change that occurs on a specific d...
Represents a time interval.To browse the .NET Framework source code for this type,...
Specifies that the class can be serialized.
static TimeZoneInfo CreateCustomTimeZone(string id, TimeSpan baseUtcOffset, string displayName, string standardDisplayName)
Creates a custom time zone with a specified identifier, an offset from Coordinated Universal Time (UT...
static DateTimeOffset ConvertTimeBySystemTimeZoneId(DateTimeOffset dateTimeOffset, string destinationTimeZoneId)
Converts a time to the time in another time zone based on the time zone's identifier.
string ToSerializedString()
Converts the current T:System.TimeZoneInfo object to a serialized string.
static DateTime ConvertTime(DateTime dateTime, TimeZoneInfo destinationTimeZone)
Converts a time to the time in a particular time zone.
static DateTime ConvertTimeToUtc(DateTime dateTime)
Converts the specified date and time to Coordinated Universal Time (UTC).
void Assert()
Declares that the calling code can access the resource protected by a permission demand through the c...
Defines the period of daylight saving time.
static ReadOnlyCollection< TimeZoneInfo > GetSystemTimeZones()
Returns a sorted collection of all the time zones about which information is available on the local s...
static TimeZoneInfo CreateCustomTimeZone(string id, TimeSpan baseUtcOffset, string displayName, string standardDisplayName, string daylightDisplayName, AdjustmentRule[] adjustmentRules)
Creates a custom time zone with a specified identifier, an offset from Coordinated Universal Time (UT...
Provides information about a specific culture (called a locale for unmanaged code development)....
Controls the ability to access files and folders. This class cannot be inherited.
The exception that is thrown when time zone information is invalid.
static TimeZoneInfo Local
Gets a T:System.TimeZoneInfo object that represents the local time zone.
bool HasSameRules(TimeZoneInfo other)
Indicates whether the current object and another T:System.TimeZoneInfo object have the same adjustmen...
AdjustmentRule [] GetAdjustmentRules()
Retrieves an array of T:System.TimeZoneInfo.AdjustmentRule objects that apply to the current T:System...
static void RevertAssert()
Causes any previous M:System.Security.CodeAccessPermission.Assert for the current frame to be removed...
string DaylightName
Gets the display name for the current time zone's daylight saving time.
Provides information about a time zone adjustment, such as the transition to and from daylight saving...
DateTimeStyles
Defines the formatting options that customize string parsing for some date and time parsing methods.
bool Equals(AdjustmentRule other)
Determines whether the current T:System.TimeZoneInfo.AdjustmentRule object is equal to a second T:Sys...
void GetObjectData(SerializationInfo info, StreamingContext context)
Populates a T:System.Runtime.Serialization.SerializationInfo with the data needed to serialize the ta...
RegistryPermissionAccess
Specifies the permitted access to registry keys and values.
DateTime UtcDateTime
Gets a T:System.DateTime value that represents the Coordinated Universal Time (UTC) date and time of ...
The exception that is thrown when a security error is detected.
Performs operations on T:System.String instances that contain file or directory path information....
DayOfWeek
Specifies the day of the week.
DateTime TimeOfDay
Gets the hour, minute, and second at which the time change occurs.
bool IsDaylightSavingTime(DateTime dateTime)
Indicates whether a specified date and time falls in the range of daylight saving time for the time z...
static bool operator !=(TransitionTime t1, TransitionTime t2)
Determines whether two specified T:System.TimeZoneInfo.TransitionTime objects are not equal.
long Ticks
Gets the number of ticks that represent the date and time of this instance.
string StandardName
Gets the display name for the time zone's standard time.
static void ClearCachedData()
Clears cached time zone data.