mscorlib(4.0.0.0) API with additions
TimeZoneInfo.cs
1 using Microsoft.Win32;
5 using System.IO;
8 using System.Security;
11 using System.Text;
12 
13 namespace System
14 {
16  [Serializable]
17  [TypeForwardedFrom("System.Core, Version=3.5.0.0, Culture=Neutral, PublicKeyToken=b77a5c561934e089")]
18  [__DynamicallyInvokable]
19  [HostProtection(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
20  public sealed class TimeZoneInfo : IEquatable<TimeZoneInfo>, ISerializable, IDeserializationCallback
21  {
22  private enum TimeZoneInfoResult
23  {
24  Success,
28  }
29 
30  private class CachedData
31  {
32  private volatile TimeZoneInfo m_localTimeZone;
33 
34  private volatile TimeZoneInfo m_utcTimeZone;
35 
36  public Dictionary<string, TimeZoneInfo> m_systemTimeZones;
37 
38  public ReadOnlyCollection<TimeZoneInfo> m_readOnlySystemTimeZones;
39 
40  public bool m_allSystemTimeZonesRead;
41 
42  private volatile OffsetAndRule m_oneYearLocalFromUtc;
43 
44  public TimeZoneInfo Local
45  {
46  get
47  {
48  TimeZoneInfo timeZoneInfo = m_localTimeZone;
49  if (timeZoneInfo == null)
50  {
51  timeZoneInfo = CreateLocal();
52  }
53  return timeZoneInfo;
54  }
55  }
56 
57  public TimeZoneInfo Utc
58  {
59  get
60  {
61  TimeZoneInfo timeZoneInfo = m_utcTimeZone;
62  if (timeZoneInfo == null)
63  {
64  timeZoneInfo = CreateUtc();
65  }
66  return timeZoneInfo;
67  }
68  }
69 
70  private TimeZoneInfo CreateLocal()
71  {
72  lock (this)
73  {
74  TimeZoneInfo timeZoneInfo = m_localTimeZone;
75  if (timeZoneInfo == null)
76  {
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));
79  }
80  return timeZoneInfo;
81  }
82  }
83 
84  private TimeZoneInfo CreateUtc()
85  {
86  lock (this)
87  {
88  TimeZoneInfo timeZoneInfo = m_utcTimeZone;
89  if (timeZoneInfo == null)
90  {
91  timeZoneInfo = (m_utcTimeZone = CreateCustomTimeZone("UTC", TimeSpan.Zero, "UTC", "UTC"));
92  }
93  return timeZoneInfo;
94  }
95  }
96 
97  public DateTimeKind GetCorrespondingKind(TimeZoneInfo timeZone)
98  {
99  if (timeZone == m_utcTimeZone)
100  {
101  return DateTimeKind.Utc;
102  }
103  if (timeZone == m_localTimeZone)
104  {
105  return DateTimeKind.Local;
106  }
107  return DateTimeKind.Unspecified;
108  }
109 
110  [SecuritySafeCritical]
111  private static TimeZoneInfo GetCurrentOneYearLocal()
112  {
113  Win32Native.TimeZoneInformation lpTimeZoneInformation = default(Win32Native.TimeZoneInformation);
114  long num = UnsafeNativeMethods.GetTimeZoneInformation(out lpTimeZoneInformation);
115  if (num == -1)
116  {
117  return CreateCustomTimeZone("Local", TimeSpan.Zero, "Local", "Local");
118  }
119  return GetLocalTimeZoneFromWin32Data(lpTimeZoneInformation, dstDisabled: false);
120  }
121 
122  public OffsetAndRule GetOneYearLocalFromUtc(int year)
123  {
124  OffsetAndRule offsetAndRule = m_oneYearLocalFromUtc;
125  if (offsetAndRule == null || offsetAndRule.year != year)
126  {
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));
130  }
131  return offsetAndRule;
132  }
133  }
134 
135  private class OffsetAndRule
136  {
137  public int year;
138 
139  public TimeSpan offset;
140 
141  public AdjustmentRule rule;
142 
143  public OffsetAndRule(int year, TimeSpan offset, AdjustmentRule rule)
144  {
145  this.year = year;
146  this.offset = offset;
147  this.rule = rule;
148  }
149  }
150 
152  [Serializable]
153  [TypeForwardedFrom("System.Core, Version=3.5.0.0, Culture=Neutral, PublicKeyToken=b77a5c561934e089")]
154  [HostProtection(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
155  public sealed class AdjustmentRule : IEquatable<AdjustmentRule>, ISerializable, IDeserializationCallback
156  {
157  private DateTime m_dateStart;
158 
159  private DateTime m_dateEnd;
160 
161  private TimeSpan m_daylightDelta;
162 
163  private TransitionTime m_daylightTransitionStart;
164 
165  private TransitionTime m_daylightTransitionEnd;
166 
167  private TimeSpan m_baseUtcOffsetDelta;
168 
171  public DateTime DateStart => m_dateStart;
172 
175  public DateTime DateEnd => m_dateEnd;
176 
179  public TimeSpan DaylightDelta => m_daylightDelta;
180 
183  public TransitionTime DaylightTransitionStart => m_daylightTransitionStart;
184 
187  public TransitionTime DaylightTransitionEnd => m_daylightTransitionEnd;
188 
189  internal TimeSpan BaseUtcOffsetDelta => m_baseUtcOffsetDelta;
190 
191  internal bool HasDaylightSaving
192  {
193  get
194  {
196  {
198  }
199  return true;
200  }
201  }
202 
207  public bool Equals(AdjustmentRule other)
208  {
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);
210  }
211 
214  public override int GetHashCode()
215  {
216  return m_dateStart.GetHashCode();
217  }
218 
219  private AdjustmentRule()
220  {
221  }
222 
234  public static AdjustmentRule CreateAdjustmentRule(DateTime dateStart, DateTime dateEnd, TimeSpan daylightDelta, TransitionTime daylightTransitionStart, TransitionTime daylightTransitionEnd)
235  {
236  ValidateAdjustmentRule(dateStart, dateEnd, daylightDelta, daylightTransitionStart, daylightTransitionEnd);
237  AdjustmentRule adjustmentRule = new AdjustmentRule();
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;
243  adjustmentRule.m_baseUtcOffsetDelta = TimeSpan.Zero;
244  return adjustmentRule;
245  }
246 
247  internal static AdjustmentRule CreateAdjustmentRule(DateTime dateStart, DateTime dateEnd, TimeSpan daylightDelta, TransitionTime daylightTransitionStart, TransitionTime daylightTransitionEnd, TimeSpan baseUtcOffsetDelta)
248  {
249  AdjustmentRule adjustmentRule = CreateAdjustmentRule(dateStart, dateEnd, daylightDelta, daylightTransitionStart, daylightTransitionEnd);
250  adjustmentRule.m_baseUtcOffsetDelta = baseUtcOffsetDelta;
251  return adjustmentRule;
252  }
253 
254  internal bool IsStartDateMarkerForBeginningOfYear()
255  {
257  {
258  return m_dateStart.Year == m_dateEnd.Year;
259  }
260  return false;
261  }
262 
263  internal bool IsEndDateMarkerForEndOfYear()
264  {
266  {
267  return m_dateStart.Year == m_dateEnd.Year;
268  }
269  return false;
270  }
271 
272  private static void ValidateAdjustmentRule(DateTime dateStart, DateTime dateEnd, TimeSpan daylightDelta, TransitionTime daylightTransitionStart, TransitionTime daylightTransitionEnd)
273  {
274  if (dateStart.Kind != 0)
275  {
276  throw new ArgumentException(Environment.GetResourceString("Argument_DateTimeKindMustBeUnspecified"), "dateStart");
277  }
278  if (dateEnd.Kind != 0)
279  {
280  throw new ArgumentException(Environment.GetResourceString("Argument_DateTimeKindMustBeUnspecified"), "dateEnd");
281  }
282  if (daylightTransitionStart.Equals(daylightTransitionEnd))
283  {
284  throw new ArgumentException(Environment.GetResourceString("Argument_TransitionTimesAreIdentical"), "daylightTransitionEnd");
285  }
286  if (dateStart > dateEnd)
287  {
288  throw new ArgumentException(Environment.GetResourceString("Argument_OutOfOrderDateTimes"), "dateStart");
289  }
290  if (UtcOffsetOutOfRange(daylightDelta))
291  {
292  throw new ArgumentOutOfRangeException("daylightDelta", daylightDelta, Environment.GetResourceString("ArgumentOutOfRange_UtcOffset"));
293  }
294  if (daylightDelta.Ticks % 600000000 != 0L)
295  {
296  throw new ArgumentException(Environment.GetResourceString("Argument_TimeSpanHasSeconds"), "daylightDelta");
297  }
298  if (dateStart.TimeOfDay != TimeSpan.Zero)
299  {
300  throw new ArgumentException(Environment.GetResourceString("Argument_DateTimeHasTimeOfDay"), "dateStart");
301  }
302  if (dateEnd.TimeOfDay != TimeSpan.Zero)
303  {
304  throw new ArgumentException(Environment.GetResourceString("Argument_DateTimeHasTimeOfDay"), "dateEnd");
305  }
306  }
307 
310  void IDeserializationCallback.OnDeserialization(object sender)
311  {
312  try
313  {
314  ValidateAdjustmentRule(m_dateStart, m_dateEnd, m_daylightDelta, m_daylightTransitionStart, m_daylightTransitionEnd);
315  }
316  catch (ArgumentException innerException)
317  {
318  throw new SerializationException(Environment.GetResourceString("Serialization_InvalidData"), innerException);
319  }
320  }
321 
325  [SecurityCritical]
327  {
328  if (info == null)
329  {
330  throw new ArgumentNullException("info");
331  }
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);
338  }
339 
340  private AdjustmentRule(SerializationInfo info, StreamingContext context)
341  {
342  if (info == null)
343  {
344  throw new ArgumentNullException("info");
345  }
346  m_dateStart = (DateTime)info.GetValue("DateStart", typeof(DateTime));
347  m_dateEnd = (DateTime)info.GetValue("DateEnd", typeof(DateTime));
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)
353  {
354  m_baseUtcOffsetDelta = (TimeSpan)valueNoThrow;
355  }
356  }
357  }
358 
360  [Serializable]
361  [TypeForwardedFrom("System.Core, Version=3.5.0.0, Culture=Neutral, PublicKeyToken=b77a5c561934e089")]
362  [HostProtection(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
364  {
365  private DateTime m_timeOfDay;
366 
367  private byte m_month;
368 
369  private byte m_week;
370 
371  private byte m_day;
372 
373  private DayOfWeek m_dayOfWeek;
374 
375  private bool m_isFixedDateRule;
376 
379  public DateTime TimeOfDay => m_timeOfDay;
380 
383  public int Month => m_month;
384 
387  public int Week => m_week;
388 
391  public int Day => m_day;
392 
395  public DayOfWeek DayOfWeek => m_dayOfWeek;
396 
400  public bool IsFixedDateRule => m_isFixedDateRule;
401 
406  public override bool Equals(object obj)
407  {
408  if (obj is TransitionTime)
409  {
410  return Equals((TransitionTime)obj);
411  }
412  return false;
413  }
414 
420  public static bool operator ==(TransitionTime t1, TransitionTime t2)
421  {
422  return t1.Equals(t2);
423  }
424 
430  public static bool operator !=(TransitionTime t1, TransitionTime t2)
431  {
432  return !t1.Equals(t2);
433  }
434 
439  public bool Equals(TransitionTime other)
440  {
441  bool flag = m_isFixedDateRule == other.m_isFixedDateRule && m_timeOfDay == other.m_timeOfDay && m_month == other.m_month;
442  if (flag)
443  {
444  flag = ((!other.m_isFixedDateRule) ? (m_week == other.m_week && m_dayOfWeek == other.m_dayOfWeek) : (m_day == other.m_day));
445  }
446  return flag;
447  }
448 
451  public override int GetHashCode()
452  {
453  return m_month ^ (m_week << 8);
454  }
455 
463  public static TransitionTime CreateFixedDateRule(DateTime timeOfDay, int month, int day)
464  {
465  return CreateTransitionTime(timeOfDay, month, 1, day, DayOfWeek.Sunday, isFixedDateRule: true);
466  }
467 
478  public static TransitionTime CreateFloatingDateRule(DateTime timeOfDay, int month, int week, DayOfWeek dayOfWeek)
479  {
480  return CreateTransitionTime(timeOfDay, month, week, 1, dayOfWeek, isFixedDateRule: false);
481  }
482 
483  private static TransitionTime CreateTransitionTime(DateTime timeOfDay, int month, int week, int day, DayOfWeek dayOfWeek, bool isFixedDateRule)
484  {
485  ValidateTransitionTime(timeOfDay, month, week, day, dayOfWeek);
486  TransitionTime result = default(TransitionTime);
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;
493  return result;
494  }
495 
496  private static void ValidateTransitionTime(DateTime timeOfDay, int month, int week, int day, DayOfWeek dayOfWeek)
497  {
498  if (timeOfDay.Kind != 0)
499  {
500  throw new ArgumentException(Environment.GetResourceString("Argument_DateTimeKindMustBeUnspecified"), "timeOfDay");
501  }
502  if (month < 1 || month > 12)
503  {
504  throw new ArgumentOutOfRangeException("month", Environment.GetResourceString("ArgumentOutOfRange_MonthParam"));
505  }
506  if (day < 1 || day > 31)
507  {
508  throw new ArgumentOutOfRangeException("day", Environment.GetResourceString("ArgumentOutOfRange_DayParam"));
509  }
510  if (week < 1 || week > 5)
511  {
512  throw new ArgumentOutOfRangeException("week", Environment.GetResourceString("ArgumentOutOfRange_Week"));
513  }
514  if (dayOfWeek < DayOfWeek.Sunday || dayOfWeek > DayOfWeek.Saturday)
515  {
516  throw new ArgumentOutOfRangeException("dayOfWeek", Environment.GetResourceString("ArgumentOutOfRange_DayOfWeek"));
517  }
518  if (timeOfDay.Year != 1 || timeOfDay.Month != 1 || timeOfDay.Day != 1 || timeOfDay.Ticks % 10000 != 0L)
519  {
520  throw new ArgumentException(Environment.GetResourceString("Argument_DateTimeHasTicks"), "timeOfDay");
521  }
522  }
523 
527  {
528  try
529  {
530  ValidateTransitionTime(m_timeOfDay, m_month, m_week, m_day, m_dayOfWeek);
531  }
532  catch (ArgumentException innerException)
533  {
534  throw new SerializationException(Environment.GetResourceString("Serialization_InvalidData"), innerException);
535  }
536  }
537 
541  [SecurityCritical]
543  {
544  if (info == null)
545  {
546  throw new ArgumentNullException("info");
547  }
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);
554  }
555 
556  private TransitionTime(SerializationInfo info, StreamingContext context)
557  {
558  if (info == null)
559  {
560  throw new ArgumentNullException("info");
561  }
562  m_timeOfDay = (DateTime)info.GetValue("TimeOfDay", typeof(DateTime));
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));
566  m_dayOfWeek = (DayOfWeek)info.GetValue("DayOfWeek", typeof(DayOfWeek));
567  m_isFixedDateRule = (bool)info.GetValue("IsFixedDateRule", typeof(bool));
568  }
569  }
570 
571  private sealed class StringSerializer
572  {
573  private enum State
574  {
575  Escaped,
576  NotEscaped,
577  StartOfToken,
578  EndOfLine
579  }
580 
581  private string m_serializedText;
582 
583  private int m_currentTokenStartIndex;
584 
585  private State m_state;
586 
587  private const int initialCapacityForString = 64;
588 
589  private const char esc = '\\';
590 
591  private const char sep = ';';
592 
593  private const char lhs = '[';
594 
595  private const char rhs = ']';
596 
597  private const string escString = "\\";
598 
599  private const string sepString = ";";
600 
601  private const string lhsString = "[";
602 
603  private const string rhsString = "]";
604 
605  private const string escapedEsc = "\\\\";
606 
607  private const string escapedSep = "\\;";
608 
609  private const string escapedLhs = "\\[";
610 
611  private const string escapedRhs = "\\]";
612 
613  private const string dateTimeFormat = "MM:dd:yyyy";
614 
615  private const string timeOfDayFormat = "HH:mm:ss.FFF";
616 
617  public static string GetSerializedString(TimeZoneInfo zone)
618  {
619  StringBuilder stringBuilder = StringBuilderCache.Acquire();
620  stringBuilder.Append(SerializeSubstitute(zone.Id));
621  stringBuilder.Append(';');
622  stringBuilder.Append(SerializeSubstitute(zone.BaseUtcOffset.TotalMinutes.ToString(CultureInfo.InvariantCulture)));
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)
632  {
633  foreach (AdjustmentRule adjustmentRule in adjustmentRules)
634  {
635  stringBuilder.Append('[');
636  stringBuilder.Append(SerializeSubstitute(adjustmentRule.DateStart.ToString("MM:dd:yyyy", DateTimeFormatInfo.InvariantInfo)));
637  stringBuilder.Append(';');
638  stringBuilder.Append(SerializeSubstitute(adjustmentRule.DateEnd.ToString("MM:dd:yyyy", DateTimeFormatInfo.InvariantInfo)));
639  stringBuilder.Append(';');
640  stringBuilder.Append(SerializeSubstitute(adjustmentRule.DaylightDelta.TotalMinutes.ToString(CultureInfo.InvariantCulture)));
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)
647  {
648  stringBuilder.Append(SerializeSubstitute(adjustmentRule.BaseUtcOffsetDelta.TotalMinutes.ToString(CultureInfo.InvariantCulture)));
649  stringBuilder.Append(';');
650  }
651  stringBuilder.Append(']');
652  }
653  }
654  stringBuilder.Append(';');
655  return StringBuilderCache.GetStringAndRelease(stringBuilder);
656  }
657 
658  public static TimeZoneInfo GetDeserializedTimeZoneInfo(string source)
659  {
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);
667  try
668  {
669  return CreateCustomTimeZone(nextStringValue, nextTimeSpanValue, nextStringValue2, nextStringValue3, nextStringValue4, nextAdjustmentRuleArrayValue);
670  }
671  catch (ArgumentException innerException)
672  {
673  throw new SerializationException(Environment.GetResourceString("Serialization_InvalidData"), innerException);
674  }
675  catch (InvalidTimeZoneException innerException2)
676  {
677  throw new SerializationException(Environment.GetResourceString("Serialization_InvalidData"), innerException2);
678  }
679  }
680 
681  private StringSerializer(string str)
682  {
683  m_serializedText = str;
684  m_state = State.StartOfToken;
685  }
686 
687  private static string SerializeSubstitute(string text)
688  {
689  text = text.Replace("\\", "\\\\");
690  text = text.Replace("[", "\\[");
691  text = text.Replace("]", "\\]");
692  return text.Replace(";", "\\;");
693  }
694 
695  private static void SerializeTransitionTime(TransitionTime time, StringBuilder serializedText)
696  {
697  serializedText.Append('[');
698  serializedText.Append((time.IsFixedDateRule ? 1 : 0).ToString(CultureInfo.InvariantCulture));
699  serializedText.Append(';');
700  if (time.IsFixedDateRule)
701  {
702  serializedText.Append(SerializeSubstitute(time.TimeOfDay.ToString("HH:mm:ss.FFF", DateTimeFormatInfo.InvariantInfo)));
703  serializedText.Append(';');
704  serializedText.Append(SerializeSubstitute(time.Month.ToString(CultureInfo.InvariantCulture)));
705  serializedText.Append(';');
706  serializedText.Append(SerializeSubstitute(time.Day.ToString(CultureInfo.InvariantCulture)));
707  serializedText.Append(';');
708  }
709  else
710  {
711  serializedText.Append(SerializeSubstitute(time.TimeOfDay.ToString("HH:mm:ss.FFF", DateTimeFormatInfo.InvariantInfo)));
712  serializedText.Append(';');
713  serializedText.Append(SerializeSubstitute(time.Month.ToString(CultureInfo.InvariantCulture)));
714  serializedText.Append(';');
715  serializedText.Append(SerializeSubstitute(time.Week.ToString(CultureInfo.InvariantCulture)));
716  serializedText.Append(';');
717  serializedText.Append(SerializeSubstitute(((int)time.DayOfWeek).ToString(CultureInfo.InvariantCulture)));
718  serializedText.Append(';');
719  }
720  serializedText.Append(']');
721  }
722 
723  private static void VerifyIsEscapableCharacter(char c)
724  {
725  if (c != '\\' && c != ';' && c != '[' && c != ']')
726  {
727  throw new SerializationException(Environment.GetResourceString("Serialization_InvalidEscapeSequence", c));
728  }
729  }
730 
731  private void SkipVersionNextDataFields(int depth)
732  {
733  if (m_currentTokenStartIndex < 0 || m_currentTokenStartIndex >= m_serializedText.Length)
734  {
735  throw new SerializationException(Environment.GetResourceString("Serialization_InvalidData"));
736  }
737  State state = State.NotEscaped;
738  for (int i = m_currentTokenStartIndex; i < m_serializedText.Length; i++)
739  {
740  switch (state)
741  {
742  case State.Escaped:
743  VerifyIsEscapableCharacter(m_serializedText[i]);
744  state = State.NotEscaped;
745  break;
746  case State.NotEscaped:
747  switch (m_serializedText[i])
748  {
749  case '\\':
750  state = State.Escaped;
751  break;
752  case '[':
753  depth++;
754  break;
755  case ']':
756  depth--;
757  if (depth == 0)
758  {
759  m_currentTokenStartIndex = i + 1;
760  if (m_currentTokenStartIndex >= m_serializedText.Length)
761  {
762  m_state = State.EndOfLine;
763  }
764  else
765  {
766  m_state = State.StartOfToken;
767  }
768  return;
769  }
770  break;
771  case '\0':
772  throw new SerializationException(Environment.GetResourceString("Serialization_InvalidData"));
773  }
774  break;
775  }
776  }
777  throw new SerializationException(Environment.GetResourceString("Serialization_InvalidData"));
778  }
779 
780  private string GetNextStringValue(bool canEndWithoutSeparator)
781  {
782  if (m_state == State.EndOfLine)
783  {
784  if (canEndWithoutSeparator)
785  {
786  return null;
787  }
788  throw new SerializationException(Environment.GetResourceString("Serialization_InvalidData"));
789  }
790  if (m_currentTokenStartIndex < 0 || m_currentTokenStartIndex >= m_serializedText.Length)
791  {
792  throw new SerializationException(Environment.GetResourceString("Serialization_InvalidData"));
793  }
794  State state = State.NotEscaped;
795  StringBuilder stringBuilder = StringBuilderCache.Acquire(64);
796  for (int i = m_currentTokenStartIndex; i < m_serializedText.Length; i++)
797  {
798  switch (state)
799  {
800  case State.Escaped:
801  VerifyIsEscapableCharacter(m_serializedText[i]);
802  stringBuilder.Append(m_serializedText[i]);
803  state = State.NotEscaped;
804  break;
805  case State.NotEscaped:
806  switch (m_serializedText[i])
807  {
808  case '\\':
809  state = State.Escaped;
810  break;
811  case '[':
812  throw new SerializationException(Environment.GetResourceString("Serialization_InvalidData"));
813  case ']':
814  if (canEndWithoutSeparator)
815  {
816  m_currentTokenStartIndex = i;
817  m_state = State.StartOfToken;
818  return stringBuilder.ToString();
819  }
820  throw new SerializationException(Environment.GetResourceString("Serialization_InvalidData"));
821  case ';':
822  m_currentTokenStartIndex = i + 1;
823  if (m_currentTokenStartIndex >= m_serializedText.Length)
824  {
825  m_state = State.EndOfLine;
826  }
827  else
828  {
829  m_state = State.StartOfToken;
830  }
831  return StringBuilderCache.GetStringAndRelease(stringBuilder);
832  case '\0':
833  throw new SerializationException(Environment.GetResourceString("Serialization_InvalidData"));
834  default:
835  stringBuilder.Append(m_serializedText[i]);
836  break;
837  }
838  break;
839  }
840  }
841  if (state == State.Escaped)
842  {
843  throw new SerializationException(Environment.GetResourceString("Serialization_InvalidEscapeSequence", string.Empty));
844  }
845  if (!canEndWithoutSeparator)
846  {
847  throw new SerializationException(Environment.GetResourceString("Serialization_InvalidData"));
848  }
849  m_currentTokenStartIndex = m_serializedText.Length;
850  m_state = State.EndOfLine;
851  return StringBuilderCache.GetStringAndRelease(stringBuilder);
852  }
853 
854  private DateTime GetNextDateTimeValue(bool canEndWithoutSeparator, string format)
855  {
856  string nextStringValue = GetNextStringValue(canEndWithoutSeparator);
857  if (!DateTime.TryParseExact(nextStringValue, format, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None, out DateTime result))
858  {
859  throw new SerializationException(Environment.GetResourceString("Serialization_InvalidData"));
860  }
861  return result;
862  }
863 
864  private TimeSpan GetNextTimeSpanValue(bool canEndWithoutSeparator)
865  {
866  int nextInt32Value = GetNextInt32Value(canEndWithoutSeparator);
867  try
868  {
869  return new TimeSpan(0, nextInt32Value, 0);
870  }
871  catch (ArgumentOutOfRangeException innerException)
872  {
873  throw new SerializationException(Environment.GetResourceString("Serialization_InvalidData"), innerException);
874  }
875  }
876 
877  private int GetNextInt32Value(bool canEndWithoutSeparator)
878  {
879  string nextStringValue = GetNextStringValue(canEndWithoutSeparator);
880  if (!int.TryParse(nextStringValue, NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out int result))
881  {
882  throw new SerializationException(Environment.GetResourceString("Serialization_InvalidData"));
883  }
884  return result;
885  }
886 
887  private AdjustmentRule[] GetNextAdjustmentRuleArrayValue(bool canEndWithoutSeparator)
888  {
890  int num = 0;
891  for (AdjustmentRule nextAdjustmentRuleValue = GetNextAdjustmentRuleValue(canEndWithoutSeparator: true); nextAdjustmentRuleValue != null; nextAdjustmentRuleValue = GetNextAdjustmentRuleValue(canEndWithoutSeparator: true))
892  {
893  list.Add(nextAdjustmentRuleValue);
894  num++;
895  }
896  if (!canEndWithoutSeparator)
897  {
898  if (m_state == State.EndOfLine)
899  {
900  throw new SerializationException(Environment.GetResourceString("Serialization_InvalidData"));
901  }
902  if (m_currentTokenStartIndex < 0 || m_currentTokenStartIndex >= m_serializedText.Length)
903  {
904  throw new SerializationException(Environment.GetResourceString("Serialization_InvalidData"));
905  }
906  }
907  if (num == 0)
908  {
909  return null;
910  }
911  return list.ToArray();
912  }
913 
914  private AdjustmentRule GetNextAdjustmentRuleValue(bool canEndWithoutSeparator)
915  {
916  if (m_state == State.EndOfLine)
917  {
918  if (canEndWithoutSeparator)
919  {
920  return null;
921  }
922  throw new SerializationException(Environment.GetResourceString("Serialization_InvalidData"));
923  }
924  if (m_currentTokenStartIndex < 0 || m_currentTokenStartIndex >= m_serializedText.Length)
925  {
926  throw new SerializationException(Environment.GetResourceString("Serialization_InvalidData"));
927  }
928  if (m_serializedText[m_currentTokenStartIndex] == ';')
929  {
930  return null;
931  }
932  if (m_serializedText[m_currentTokenStartIndex] != '[')
933  {
934  throw new SerializationException(Environment.GetResourceString("Serialization_InvalidData"));
935  }
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)
944  {
945  throw new SerializationException(Environment.GetResourceString("Serialization_InvalidData"));
946  }
947  if ((m_serializedText[m_currentTokenStartIndex] >= '0' && m_serializedText[m_currentTokenStartIndex] <= '9') || m_serializedText[m_currentTokenStartIndex] == '-' || m_serializedText[m_currentTokenStartIndex] == '+')
948  {
949  baseUtcOffsetDelta = GetNextTimeSpanValue(canEndWithoutSeparator: false);
950  }
951  if (m_state == State.EndOfLine || m_currentTokenStartIndex >= m_serializedText.Length)
952  {
953  throw new SerializationException(Environment.GetResourceString("Serialization_InvalidData"));
954  }
955  if (m_serializedText[m_currentTokenStartIndex] != ']')
956  {
957  SkipVersionNextDataFields(1);
958  }
959  else
960  {
961  m_currentTokenStartIndex++;
962  }
963  AdjustmentRule result;
964  try
965  {
966  result = AdjustmentRule.CreateAdjustmentRule(nextDateTimeValue, nextDateTimeValue2, nextTimeSpanValue, nextTransitionTimeValue, nextTransitionTimeValue2, baseUtcOffsetDelta);
967  }
968  catch (ArgumentException innerException)
969  {
970  throw new SerializationException(Environment.GetResourceString("Serialization_InvalidData"), innerException);
971  }
972  if (m_currentTokenStartIndex >= m_serializedText.Length)
973  {
974  m_state = State.EndOfLine;
975  }
976  else
977  {
978  m_state = State.StartOfToken;
979  }
980  return result;
981  }
982 
983  private TransitionTime GetNextTransitionTimeValue(bool canEndWithoutSeparator)
984  {
985  if (m_state == State.EndOfLine || (m_currentTokenStartIndex < m_serializedText.Length && m_serializedText[m_currentTokenStartIndex] == ']'))
986  {
987  throw new SerializationException(Environment.GetResourceString("Serialization_InvalidData"));
988  }
989  if (m_currentTokenStartIndex < 0 || m_currentTokenStartIndex >= m_serializedText.Length)
990  {
991  throw new SerializationException(Environment.GetResourceString("Serialization_InvalidData"));
992  }
993  if (m_serializedText[m_currentTokenStartIndex] != '[')
994  {
995  throw new SerializationException(Environment.GetResourceString("Serialization_InvalidData"));
996  }
997  m_currentTokenStartIndex++;
998  int nextInt32Value = GetNextInt32Value(canEndWithoutSeparator: false);
999  if (nextInt32Value != 0 && nextInt32Value != 1)
1000  {
1001  throw new SerializationException(Environment.GetResourceString("Serialization_InvalidData"));
1002  }
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)
1008  {
1009  int nextInt32Value3 = GetNextInt32Value(canEndWithoutSeparator: false);
1010  try
1011  {
1012  result = TransitionTime.CreateFixedDateRule(nextDateTimeValue, nextInt32Value2, nextInt32Value3);
1013  }
1014  catch (ArgumentException innerException)
1015  {
1016  throw new SerializationException(Environment.GetResourceString("Serialization_InvalidData"), innerException);
1017  }
1018  }
1019  else
1020  {
1021  int nextInt32Value4 = GetNextInt32Value(canEndWithoutSeparator: false);
1022  int nextInt32Value5 = GetNextInt32Value(canEndWithoutSeparator: false);
1023  try
1024  {
1025  result = TransitionTime.CreateFloatingDateRule(nextDateTimeValue, nextInt32Value2, nextInt32Value4, (DayOfWeek)nextInt32Value5);
1026  }
1027  catch (ArgumentException innerException2)
1028  {
1029  throw new SerializationException(Environment.GetResourceString("Serialization_InvalidData"), innerException2);
1030  }
1031  }
1032  if (m_state == State.EndOfLine || m_currentTokenStartIndex >= m_serializedText.Length)
1033  {
1034  throw new SerializationException(Environment.GetResourceString("Serialization_InvalidData"));
1035  }
1036  if (m_serializedText[m_currentTokenStartIndex] != ']')
1037  {
1038  SkipVersionNextDataFields(1);
1039  }
1040  else
1041  {
1042  m_currentTokenStartIndex++;
1043  }
1044  bool flag = false;
1045  if (m_currentTokenStartIndex < m_serializedText.Length && m_serializedText[m_currentTokenStartIndex] == ';')
1046  {
1047  m_currentTokenStartIndex++;
1048  flag = true;
1049  }
1050  if (!flag && !canEndWithoutSeparator)
1051  {
1052  throw new SerializationException(Environment.GetResourceString("Serialization_InvalidData"));
1053  }
1054  if (m_currentTokenStartIndex >= m_serializedText.Length)
1055  {
1056  m_state = State.EndOfLine;
1057  }
1058  else
1059  {
1060  m_state = State.StartOfToken;
1061  }
1062  return result;
1063  }
1064  }
1065 
1066  private class TimeZoneInfoComparer : IComparer<TimeZoneInfo>
1067  {
1068  int IComparer<TimeZoneInfo>.Compare(TimeZoneInfo x, TimeZoneInfo y)
1069  {
1070  int num = x.BaseUtcOffset.CompareTo(y.BaseUtcOffset);
1071  if (num != 0)
1072  {
1073  return num;
1074  }
1075  return string.Compare(x.DisplayName, y.DisplayName, StringComparison.Ordinal);
1076  }
1077  }
1078 
1079  private string m_id;
1080 
1081  private string m_displayName;
1082 
1083  private string m_standardDisplayName;
1084 
1085  private string m_daylightDisplayName;
1086 
1087  private TimeSpan m_baseUtcOffset;
1088 
1089  private bool m_supportsDaylightSavingTime;
1090 
1091  private AdjustmentRule[] m_adjustmentRules;
1092 
1093  private const string c_timeZonesRegistryHive = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones";
1094 
1095  private const string c_timeZonesRegistryHivePermissionList = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones";
1096 
1097  private const string c_displayValue = "Display";
1098 
1099  private const string c_daylightValue = "Dlt";
1100 
1101  private const string c_standardValue = "Std";
1102 
1103  private const string c_muiDisplayValue = "MUI_Display";
1104 
1105  private const string c_muiDaylightValue = "MUI_Dlt";
1106 
1107  private const string c_muiStandardValue = "MUI_Std";
1108 
1109  private const string c_timeZoneInfoValue = "TZI";
1110 
1111  private const string c_firstEntryValue = "FirstEntry";
1112 
1113  private const string c_lastEntryValue = "LastEntry";
1114 
1115  private const string c_utcId = "UTC";
1116 
1117  private const string c_localId = "Local";
1118 
1119  private const int c_maxKeyLength = 255;
1120 
1121  private const int c_regByteLength = 44;
1122 
1123  private const long c_ticksPerMillisecond = 10000L;
1124 
1125  private const long c_ticksPerSecond = 10000000L;
1126 
1127  private const long c_ticksPerMinute = 600000000L;
1128 
1129  private const long c_ticksPerHour = 36000000000L;
1130 
1131  private const long c_ticksPerDay = 864000000000L;
1132 
1133  private const long c_ticksPerDayRange = 863999990000L;
1134 
1135  private static CachedData s_cachedData = new CachedData();
1136 
1137  private static DateTime s_maxDateOnly = new DateTime(9999, 12, 31);
1138 
1139  private static DateTime s_minDateOnly = new DateTime(1, 1, 2);
1140 
1143  [__DynamicallyInvokable]
1144  public string Id
1145  {
1146  [__DynamicallyInvokable]
1147  get
1148  {
1149  return m_id;
1150  }
1151  }
1152 
1155  [__DynamicallyInvokable]
1156  public string DisplayName
1157  {
1158  [__DynamicallyInvokable]
1159  get
1160  {
1161  if (m_displayName != null)
1162  {
1163  return m_displayName;
1164  }
1165  return string.Empty;
1166  }
1167  }
1168 
1171  [__DynamicallyInvokable]
1172  public string StandardName
1173  {
1174  [__DynamicallyInvokable]
1175  get
1176  {
1177  if (m_standardDisplayName != null)
1178  {
1179  return m_standardDisplayName;
1180  }
1181  return string.Empty;
1182  }
1183  }
1184 
1187  [__DynamicallyInvokable]
1188  public string DaylightName
1189  {
1190  [__DynamicallyInvokable]
1191  get
1192  {
1193  if (m_daylightDisplayName != null)
1194  {
1195  return m_daylightDisplayName;
1196  }
1197  return string.Empty;
1198  }
1199  }
1200 
1203  [__DynamicallyInvokable]
1204  public TimeSpan BaseUtcOffset
1205  {
1206  [__DynamicallyInvokable]
1207  get
1208  {
1209  return m_baseUtcOffset;
1210  }
1211  }
1212 
1216  [__DynamicallyInvokable]
1217  public bool SupportsDaylightSavingTime
1218  {
1219  [__DynamicallyInvokable]
1220  get
1221  {
1222  return m_supportsDaylightSavingTime;
1223  }
1224  }
1225 
1228  [__DynamicallyInvokable]
1229  public static TimeZoneInfo Local
1230  {
1231  [__DynamicallyInvokable]
1232  get
1233  {
1234  return s_cachedData.Local;
1235  }
1236  }
1237 
1240  [__DynamicallyInvokable]
1241  public static TimeZoneInfo Utc
1242  {
1243  [__DynamicallyInvokable]
1244  get
1245  {
1246  return s_cachedData.Utc;
1247  }
1248  }
1249 
1254  {
1255  if (m_adjustmentRules == null)
1256  {
1257  return new AdjustmentRule[0];
1258  }
1259  return (AdjustmentRule[])m_adjustmentRules.Clone();
1260  }
1261 
1267  [__DynamicallyInvokable]
1269  {
1271  {
1272  throw new ArgumentException(Environment.GetResourceString("Argument_DateTimeOffsetIsNotAmbiguous"), "dateTimeOffset");
1273  }
1274  DateTime dateTime = ConvertTime(dateTimeOffset, this).DateTime;
1275  bool flag = false;
1276  AdjustmentRule adjustmentRuleForTime = GetAdjustmentRuleForTime(dateTime);
1277  if (adjustmentRuleForTime != null && adjustmentRuleForTime.HasDaylightSaving)
1278  {
1279  DaylightTime daylightTime = GetDaylightTime(dateTime.Year, adjustmentRuleForTime);
1280  flag = GetIsAmbiguousTime(dateTime, adjustmentRuleForTime, daylightTime);
1281  }
1282  if (!flag)
1283  {
1284  throw new ArgumentException(Environment.GetResourceString("Argument_DateTimeOffsetIsNotAmbiguous"), "dateTimeOffset");
1285  }
1286  TimeSpan[] array = new TimeSpan[2];
1287  TimeSpan timeSpan = m_baseUtcOffset + adjustmentRuleForTime.BaseUtcOffsetDelta;
1288  if (adjustmentRuleForTime.DaylightDelta > TimeSpan.Zero)
1289  {
1290  array[0] = timeSpan;
1291  array[1] = timeSpan + adjustmentRuleForTime.DaylightDelta;
1292  }
1293  else
1294  {
1295  array[0] = timeSpan + adjustmentRuleForTime.DaylightDelta;
1296  array[1] = timeSpan;
1297  }
1298  return array;
1299  }
1300 
1306  [__DynamicallyInvokable]
1308  {
1310  {
1311  throw new ArgumentException(Environment.GetResourceString("Argument_DateTimeIsNotAmbiguous"), "dateTime");
1312  }
1313  DateTime dateTime2;
1314  if (dateTime.Kind == DateTimeKind.Local)
1315  {
1316  CachedData cachedData = s_cachedData;
1317  dateTime2 = ConvertTime(dateTime, cachedData.Local, this, TimeZoneInfoOptions.None, cachedData);
1318  }
1319  else if (dateTime.Kind == DateTimeKind.Utc)
1320  {
1321  CachedData cachedData2 = s_cachedData;
1322  dateTime2 = ConvertTime(dateTime, cachedData2.Utc, this, TimeZoneInfoOptions.None, cachedData2);
1323  }
1324  else
1325  {
1326  dateTime2 = dateTime;
1327  }
1328  bool flag = false;
1329  AdjustmentRule adjustmentRuleForTime = GetAdjustmentRuleForTime(dateTime2);
1330  if (adjustmentRuleForTime != null && adjustmentRuleForTime.HasDaylightSaving)
1331  {
1332  DaylightTime daylightTime = GetDaylightTime(dateTime2.Year, adjustmentRuleForTime);
1333  flag = GetIsAmbiguousTime(dateTime2, adjustmentRuleForTime, daylightTime);
1334  }
1335  if (!flag)
1336  {
1337  throw new ArgumentException(Environment.GetResourceString("Argument_DateTimeIsNotAmbiguous"), "dateTime");
1338  }
1339  TimeSpan[] array = new TimeSpan[2];
1340  TimeSpan timeSpan = m_baseUtcOffset + adjustmentRuleForTime.BaseUtcOffsetDelta;
1341  if (adjustmentRuleForTime.DaylightDelta > TimeSpan.Zero)
1342  {
1343  array[0] = timeSpan;
1344  array[1] = timeSpan + adjustmentRuleForTime.DaylightDelta;
1345  }
1346  else
1347  {
1348  array[0] = timeSpan + adjustmentRuleForTime.DaylightDelta;
1349  array[1] = timeSpan;
1350  }
1351  return array;
1352  }
1353 
1357  [__DynamicallyInvokable]
1358  public TimeSpan GetUtcOffset(DateTimeOffset dateTimeOffset)
1359  {
1360  return GetUtcOffsetFromUtc(dateTimeOffset.UtcDateTime, this);
1361  }
1362 
1366  [__DynamicallyInvokable]
1367  public TimeSpan GetUtcOffset(DateTime dateTime)
1368  {
1369  return GetUtcOffset(dateTime, TimeZoneInfoOptions.NoThrowOnInvalidTime, s_cachedData);
1370  }
1371 
1372  internal static TimeSpan GetLocalUtcOffset(DateTime dateTime, TimeZoneInfoOptions flags)
1373  {
1374  CachedData cachedData = s_cachedData;
1375  return cachedData.Local.GetUtcOffset(dateTime, flags, cachedData);
1376  }
1377 
1378  internal TimeSpan GetUtcOffset(DateTime dateTime, TimeZoneInfoOptions flags)
1379  {
1380  return GetUtcOffset(dateTime, flags, s_cachedData);
1381  }
1382 
1383  private TimeSpan GetUtcOffset(DateTime dateTime, TimeZoneInfoOptions flags, CachedData cachedData)
1384  {
1385  if (dateTime.Kind == DateTimeKind.Local)
1386  {
1387  if (cachedData.GetCorrespondingKind(this) != DateTimeKind.Local)
1388  {
1389  DateTime time = ConvertTime(dateTime, cachedData.Local, cachedData.Utc, flags);
1390  return GetUtcOffsetFromUtc(time, this);
1391  }
1392  }
1393  else if (dateTime.Kind == DateTimeKind.Utc)
1394  {
1395  if (cachedData.GetCorrespondingKind(this) == DateTimeKind.Utc)
1396  {
1397  return m_baseUtcOffset;
1398  }
1399  return GetUtcOffsetFromUtc(dateTime, this);
1400  }
1401  return GetUtcOffset(dateTime, this, flags);
1402  }
1403 
1408  [__DynamicallyInvokable]
1409  public bool IsAmbiguousTime(DateTimeOffset dateTimeOffset)
1410  {
1411  if (!m_supportsDaylightSavingTime)
1412  {
1413  return false;
1414  }
1415  return IsAmbiguousTime(ConvertTime(dateTimeOffset, this).DateTime);
1416  }
1417 
1423  [__DynamicallyInvokable]
1424  public bool IsAmbiguousTime(DateTime dateTime)
1425  {
1426  return IsAmbiguousTime(dateTime, TimeZoneInfoOptions.NoThrowOnInvalidTime);
1427  }
1428 
1429  internal bool IsAmbiguousTime(DateTime dateTime, TimeZoneInfoOptions flags)
1430  {
1431  if (!m_supportsDaylightSavingTime)
1432  {
1433  return false;
1434  }
1435  DateTime dateTime2;
1436  if (dateTime.Kind == DateTimeKind.Local)
1437  {
1438  CachedData cachedData = s_cachedData;
1439  dateTime2 = ConvertTime(dateTime, cachedData.Local, this, flags, cachedData);
1440  }
1441  else if (dateTime.Kind == DateTimeKind.Utc)
1442  {
1443  CachedData cachedData2 = s_cachedData;
1444  dateTime2 = ConvertTime(dateTime, cachedData2.Utc, this, flags, cachedData2);
1445  }
1446  else
1447  {
1448  dateTime2 = dateTime;
1449  }
1450  AdjustmentRule adjustmentRuleForTime = GetAdjustmentRuleForTime(dateTime2);
1451  if (adjustmentRuleForTime != null && adjustmentRuleForTime.HasDaylightSaving)
1452  {
1453  DaylightTime daylightTime = GetDaylightTime(dateTime2.Year, adjustmentRuleForTime);
1454  return GetIsAmbiguousTime(dateTime2, adjustmentRuleForTime, daylightTime);
1455  }
1456  return false;
1457  }
1458 
1463  [__DynamicallyInvokable]
1464  public bool IsDaylightSavingTime(DateTimeOffset dateTimeOffset)
1465  {
1466  GetUtcOffsetFromUtc(dateTimeOffset.UtcDateTime, this, out bool isDaylightSavings);
1467  return isDaylightSavings;
1468  }
1469 
1475  [__DynamicallyInvokable]
1476  public bool IsDaylightSavingTime(DateTime dateTime)
1477  {
1478  return IsDaylightSavingTime(dateTime, TimeZoneInfoOptions.NoThrowOnInvalidTime, s_cachedData);
1479  }
1480 
1481  internal bool IsDaylightSavingTime(DateTime dateTime, TimeZoneInfoOptions flags)
1482  {
1483  return IsDaylightSavingTime(dateTime, flags, s_cachedData);
1484  }
1485 
1486  private bool IsDaylightSavingTime(DateTime dateTime, TimeZoneInfoOptions flags, CachedData cachedData)
1487  {
1488  if (!m_supportsDaylightSavingTime || m_adjustmentRules == null)
1489  {
1490  return false;
1491  }
1492  DateTime dateTime2;
1493  if (dateTime.Kind == DateTimeKind.Local)
1494  {
1495  dateTime2 = ConvertTime(dateTime, cachedData.Local, this, flags, cachedData);
1496  }
1497  else
1498  {
1499  if (dateTime.Kind == DateTimeKind.Utc)
1500  {
1501  if (cachedData.GetCorrespondingKind(this) == DateTimeKind.Utc)
1502  {
1503  return false;
1504  }
1505  GetUtcOffsetFromUtc(dateTime, this, out bool isDaylightSavings);
1506  return isDaylightSavings;
1507  }
1508  dateTime2 = dateTime;
1509  }
1510  AdjustmentRule adjustmentRuleForTime = GetAdjustmentRuleForTime(dateTime2);
1511  if (adjustmentRuleForTime != null && adjustmentRuleForTime.HasDaylightSaving)
1512  {
1513  DaylightTime daylightTime = GetDaylightTime(dateTime2.Year, adjustmentRuleForTime);
1514  return GetIsDaylightSavings(dateTime2, adjustmentRuleForTime, daylightTime, flags);
1515  }
1516  return false;
1517  }
1518 
1523  [__DynamicallyInvokable]
1524  public bool IsInvalidTime(DateTime dateTime)
1525  {
1526  bool result = false;
1527  if (dateTime.Kind == DateTimeKind.Unspecified || (dateTime.Kind == DateTimeKind.Local && s_cachedData.GetCorrespondingKind(this) == DateTimeKind.Local))
1528  {
1529  AdjustmentRule adjustmentRuleForTime = GetAdjustmentRuleForTime(dateTime);
1530  if (adjustmentRuleForTime != null && adjustmentRuleForTime.HasDaylightSaving)
1531  {
1532  DaylightTime daylightTime = GetDaylightTime(dateTime.Year, adjustmentRuleForTime);
1533  result = GetIsInvalidTime(dateTime, adjustmentRuleForTime, daylightTime);
1534  }
1535  else
1536  {
1537  result = false;
1538  }
1539  }
1540  return result;
1541  }
1542 
1544  public static void ClearCachedData()
1545  {
1546  s_cachedData = new CachedData();
1547  }
1548 
1558  public static DateTimeOffset ConvertTimeBySystemTimeZoneId(DateTimeOffset dateTimeOffset, string destinationTimeZoneId)
1559  {
1560  return ConvertTime(dateTimeOffset, FindSystemTimeZoneById(destinationTimeZoneId));
1561  }
1562 
1572  public static DateTime ConvertTimeBySystemTimeZoneId(DateTime dateTime, string destinationTimeZoneId)
1573  {
1574  return ConvertTime(dateTime, FindSystemTimeZoneById(destinationTimeZoneId));
1575  }
1576 
1591  public static DateTime ConvertTimeBySystemTimeZoneId(DateTime dateTime, string sourceTimeZoneId, string destinationTimeZoneId)
1592  {
1593  if (dateTime.Kind == DateTimeKind.Local && string.Compare(sourceTimeZoneId, Local.Id, StringComparison.OrdinalIgnoreCase) == 0)
1594  {
1595  CachedData cachedData = s_cachedData;
1596  return ConvertTime(dateTime, cachedData.Local, FindSystemTimeZoneById(destinationTimeZoneId), TimeZoneInfoOptions.None, cachedData);
1597  }
1598  if (dateTime.Kind == DateTimeKind.Utc && string.Compare(sourceTimeZoneId, Utc.Id, StringComparison.OrdinalIgnoreCase) == 0)
1599  {
1600  CachedData cachedData2 = s_cachedData;
1601  return ConvertTime(dateTime, cachedData2.Utc, FindSystemTimeZoneById(destinationTimeZoneId), TimeZoneInfoOptions.None, cachedData2);
1602  }
1603  return ConvertTime(dateTime, FindSystemTimeZoneById(sourceTimeZoneId), FindSystemTimeZoneById(destinationTimeZoneId));
1604  }
1605 
1611  [__DynamicallyInvokable]
1612  public static DateTimeOffset ConvertTime(DateTimeOffset dateTimeOffset, TimeZoneInfo destinationTimeZone)
1613  {
1614  if (destinationTimeZone == null)
1615  {
1616  throw new ArgumentNullException("destinationTimeZone");
1617  }
1618  DateTime utcDateTime = dateTimeOffset.UtcDateTime;
1619  TimeSpan utcOffsetFromUtc = GetUtcOffsetFromUtc(utcDateTime, destinationTimeZone);
1620  long num = utcDateTime.Ticks + utcOffsetFromUtc.Ticks;
1621  if (num > DateTimeOffset.MaxValue.Ticks)
1622  {
1623  return DateTimeOffset.MaxValue;
1624  }
1625  if (num < DateTimeOffset.MinValue.Ticks)
1626  {
1627  return DateTimeOffset.MinValue;
1628  }
1629  return new DateTimeOffset(num, utcOffsetFromUtc);
1630  }
1631 
1638  [__DynamicallyInvokable]
1639  public static DateTime ConvertTime(DateTime dateTime, TimeZoneInfo destinationTimeZone)
1640  {
1641  if (destinationTimeZone == null)
1642  {
1643  throw new ArgumentNullException("destinationTimeZone");
1644  }
1645  if (dateTime.Ticks == 0L)
1646  {
1647  ClearCachedData();
1648  }
1649  CachedData cachedData = s_cachedData;
1650  if (dateTime.Kind == DateTimeKind.Utc)
1651  {
1652  return ConvertTime(dateTime, cachedData.Utc, destinationTimeZone, TimeZoneInfoOptions.None, cachedData);
1653  }
1654  return ConvertTime(dateTime, cachedData.Local, destinationTimeZone, TimeZoneInfoOptions.None, cachedData);
1655  }
1656 
1664  [__DynamicallyInvokable]
1665  public static DateTime ConvertTime(DateTime dateTime, TimeZoneInfo sourceTimeZone, TimeZoneInfo destinationTimeZone)
1666  {
1667  return ConvertTime(dateTime, sourceTimeZone, destinationTimeZone, TimeZoneInfoOptions.None, s_cachedData);
1668  }
1669 
1670  internal static DateTime ConvertTime(DateTime dateTime, TimeZoneInfo sourceTimeZone, TimeZoneInfo destinationTimeZone, TimeZoneInfoOptions flags)
1671  {
1672  return ConvertTime(dateTime, sourceTimeZone, destinationTimeZone, flags, s_cachedData);
1673  }
1674 
1675  private static DateTime ConvertTime(DateTime dateTime, TimeZoneInfo sourceTimeZone, TimeZoneInfo destinationTimeZone, TimeZoneInfoOptions flags, CachedData cachedData)
1676  {
1677  if (sourceTimeZone == null)
1678  {
1679  throw new ArgumentNullException("sourceTimeZone");
1680  }
1681  if (destinationTimeZone == null)
1682  {
1683  throw new ArgumentNullException("destinationTimeZone");
1684  }
1685  DateTimeKind correspondingKind = cachedData.GetCorrespondingKind(sourceTimeZone);
1686  if ((flags & TimeZoneInfoOptions.NoThrowOnInvalidTime) == (TimeZoneInfoOptions)0 && dateTime.Kind != 0 && dateTime.Kind != correspondingKind)
1687  {
1688  throw new ArgumentException(Environment.GetResourceString("Argument_ConvertMismatch"), "sourceTimeZone");
1689  }
1690  AdjustmentRule adjustmentRuleForTime = sourceTimeZone.GetAdjustmentRuleForTime(dateTime);
1691  TimeSpan t = sourceTimeZone.BaseUtcOffset;
1692  if (adjustmentRuleForTime != null)
1693  {
1694  t += adjustmentRuleForTime.BaseUtcOffsetDelta;
1695  if (adjustmentRuleForTime.HasDaylightSaving)
1696  {
1697  bool flag = false;
1698  DaylightTime daylightTime = GetDaylightTime(dateTime.Year, adjustmentRuleForTime);
1699  if ((flags & TimeZoneInfoOptions.NoThrowOnInvalidTime) == (TimeZoneInfoOptions)0 && GetIsInvalidTime(dateTime, adjustmentRuleForTime, daylightTime))
1700  {
1701  throw new ArgumentException(Environment.GetResourceString("Argument_DateTimeIsInvalid"), "dateTime");
1702  }
1703  flag = GetIsDaylightSavings(dateTime, adjustmentRuleForTime, daylightTime, flags);
1704  t += (flag ? adjustmentRuleForTime.DaylightDelta : TimeSpan.Zero);
1705  }
1706  }
1707  DateTimeKind correspondingKind2 = cachedData.GetCorrespondingKind(destinationTimeZone);
1708  if (dateTime.Kind != 0 && correspondingKind != 0 && correspondingKind == correspondingKind2)
1709  {
1710  return dateTime;
1711  }
1712  long ticks = dateTime.Ticks - t.Ticks;
1713  bool isAmbiguousLocalDst = false;
1714  DateTime dateTime2 = ConvertUtcToTimeZone(ticks, destinationTimeZone, out isAmbiguousLocalDst);
1715  if (correspondingKind2 == DateTimeKind.Local)
1716  {
1717  return new DateTime(dateTime2.Ticks, DateTimeKind.Local, isAmbiguousLocalDst);
1718  }
1719  return new DateTime(dateTime2.Ticks, correspondingKind2);
1720  }
1721 
1729  public static DateTime ConvertTimeFromUtc(DateTime dateTime, TimeZoneInfo destinationTimeZone)
1730  {
1731  CachedData cachedData = s_cachedData;
1732  return ConvertTime(dateTime, cachedData.Utc, destinationTimeZone, TimeZoneInfoOptions.None, cachedData);
1733  }
1734 
1742  public static DateTime ConvertTimeToUtc(DateTime dateTime)
1743  {
1744  if (dateTime.Kind == DateTimeKind.Utc)
1745  {
1746  return dateTime;
1747  }
1748  CachedData cachedData = s_cachedData;
1749  return ConvertTime(dateTime, cachedData.Local, cachedData.Utc, TimeZoneInfoOptions.None, cachedData);
1750  }
1751 
1752  internal static DateTime ConvertTimeToUtc(DateTime dateTime, TimeZoneInfoOptions flags)
1753  {
1754  if (dateTime.Kind == DateTimeKind.Utc)
1755  {
1756  return dateTime;
1757  }
1758  CachedData cachedData = s_cachedData;
1759  return ConvertTime(dateTime, cachedData.Local, cachedData.Utc, flags, cachedData);
1760  }
1761 
1777  public static DateTime ConvertTimeToUtc(DateTime dateTime, TimeZoneInfo sourceTimeZone)
1778  {
1779  CachedData cachedData = s_cachedData;
1780  return ConvertTime(dateTime, sourceTimeZone, cachedData.Utc, TimeZoneInfoOptions.None, cachedData);
1781  }
1782 
1787  [__DynamicallyInvokable]
1788  public bool Equals(TimeZoneInfo other)
1789  {
1790  if (other != null && string.Compare(m_id, other.m_id, StringComparison.OrdinalIgnoreCase) == 0)
1791  {
1792  return HasSameRules(other);
1793  }
1794  return false;
1795  }
1796 
1801  public override bool Equals(object obj)
1802  {
1803  TimeZoneInfo timeZoneInfo = obj as TimeZoneInfo;
1804  if (timeZoneInfo == null)
1805  {
1806  return false;
1807  }
1808  return Equals(timeZoneInfo);
1809  }
1810 
1817  public static TimeZoneInfo FromSerializedString(string source)
1818  {
1819  if (source == null)
1820  {
1821  throw new ArgumentNullException("source");
1822  }
1823  if (source.Length == 0)
1824  {
1825  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidSerializedString", source), "source");
1826  }
1827  return StringSerializer.GetDeserializedTimeZoneInfo(source);
1828  }
1829 
1832  [__DynamicallyInvokable]
1833  public override int GetHashCode()
1834  {
1835  return m_id.ToUpper(CultureInfo.InvariantCulture).GetHashCode();
1836  }
1837 
1842  [SecuritySafeCritical]
1843  [__DynamicallyInvokable]
1845  {
1846  CachedData cachedData = s_cachedData;
1847  lock (cachedData)
1848  {
1849  if (cachedData.m_readOnlySystemTimeZones == null)
1850  {
1851  PermissionSet permissionSet = new PermissionSet(PermissionState.None);
1852  permissionSet.AddPermission(new RegistryPermission(RegistryPermissionAccess.Read, "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones"));
1853  permissionSet.Assert();
1854  using (RegistryKey registryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones", RegistryKeyPermissionCheck.Default, RegistryRights.ExecuteKey))
1855  {
1856  if (registryKey != null)
1857  {
1858  string[] subKeyNames = registryKey.GetSubKeyNames();
1859  foreach (string id in subKeyNames)
1860  {
1861  TryGetTimeZone(id, dstDisabled: false, out TimeZoneInfo _, out Exception _, cachedData);
1862  }
1863  }
1864  cachedData.m_allSystemTimeZonesRead = true;
1865  }
1866  List<TimeZoneInfo> list = (cachedData.m_systemTimeZones == null) ? new List<TimeZoneInfo>() : new List<TimeZoneInfo>(cachedData.m_systemTimeZones.Values);
1867  list.Sort(new TimeZoneInfoComparer());
1868  cachedData.m_readOnlySystemTimeZones = new ReadOnlyCollection<TimeZoneInfo>(list);
1869  }
1870  }
1871  return cachedData.m_readOnlySystemTimeZones;
1872  }
1873 
1879  public bool HasSameRules(TimeZoneInfo other)
1880  {
1881  if (other == null)
1882  {
1883  throw new ArgumentNullException("other");
1884  }
1885  if (m_baseUtcOffset != other.m_baseUtcOffset || m_supportsDaylightSavingTime != other.m_supportsDaylightSavingTime)
1886  {
1887  return false;
1888  }
1889  AdjustmentRule[] adjustmentRules = m_adjustmentRules;
1890  AdjustmentRule[] adjustmentRules2 = other.m_adjustmentRules;
1891  bool flag = (adjustmentRules == null && adjustmentRules2 == null) || (adjustmentRules != null && adjustmentRules2 != null);
1892  if (!flag)
1893  {
1894  return false;
1895  }
1896  if (adjustmentRules != null)
1897  {
1898  if (adjustmentRules.Length != adjustmentRules2.Length)
1899  {
1900  return false;
1901  }
1902  for (int i = 0; i < adjustmentRules.Length; i++)
1903  {
1904  if (!adjustmentRules[i].Equals(adjustmentRules2[i]))
1905  {
1906  return false;
1907  }
1908  }
1909  }
1910  return flag;
1911  }
1912 
1915  public string ToSerializedString()
1916  {
1917  return StringSerializer.GetSerializedString(this);
1918  }
1919 
1922  [__DynamicallyInvokable]
1923  public override string ToString()
1924  {
1925  return DisplayName;
1926  }
1927 
1928  [SecurityCritical]
1929  private TimeZoneInfo(Win32Native.TimeZoneInformation zone, bool dstDisabled)
1930  {
1931  if (string.IsNullOrEmpty(zone.StandardName))
1932  {
1933  m_id = "Local";
1934  }
1935  else
1936  {
1937  m_id = zone.StandardName;
1938  }
1939  m_baseUtcOffset = new TimeSpan(0, -zone.Bias, 0);
1940  if (!dstDisabled)
1941  {
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)
1945  {
1946  m_adjustmentRules = new AdjustmentRule[1];
1947  m_adjustmentRules[0] = adjustmentRule;
1948  }
1949  }
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;
1954  }
1955 
1956  private TimeZoneInfo(string id, TimeSpan baseUtcOffset, string displayName, string standardDisplayName, string daylightDisplayName, AdjustmentRule[] adjustmentRules, bool disableDaylightSavingTime)
1957  {
1958  ValidateTimeZoneInfo(id, baseUtcOffset, adjustmentRules, out bool adjustmentRulesSupportDst);
1959  if (!disableDaylightSavingTime && adjustmentRules != null && adjustmentRules.Length != 0)
1960  {
1961  m_adjustmentRules = (AdjustmentRule[])adjustmentRules.Clone();
1962  }
1963  m_id = id;
1964  m_baseUtcOffset = baseUtcOffset;
1965  m_displayName = displayName;
1966  m_standardDisplayName = standardDisplayName;
1967  m_daylightDisplayName = (disableDaylightSavingTime ? null : daylightDisplayName);
1968  m_supportsDaylightSavingTime = (adjustmentRulesSupportDst && !disableDaylightSavingTime);
1969  }
1970 
1980  public static TimeZoneInfo CreateCustomTimeZone(string id, TimeSpan baseUtcOffset, string displayName, string standardDisplayName)
1981  {
1982  return new TimeZoneInfo(id, baseUtcOffset, displayName, standardDisplayName, standardDisplayName, null, disableDaylightSavingTime: false);
1983  }
1984 
1997  public static TimeZoneInfo CreateCustomTimeZone(string id, TimeSpan baseUtcOffset, string displayName, string standardDisplayName, string daylightDisplayName, AdjustmentRule[] adjustmentRules)
1998  {
1999  return new TimeZoneInfo(id, baseUtcOffset, displayName, standardDisplayName, daylightDisplayName, adjustmentRules, disableDaylightSavingTime: false);
2000  }
2001 
2016  public static TimeZoneInfo CreateCustomTimeZone(string id, TimeSpan baseUtcOffset, string displayName, string standardDisplayName, string daylightDisplayName, AdjustmentRule[] adjustmentRules, bool disableDaylightSavingTime)
2017  {
2018  return new TimeZoneInfo(id, baseUtcOffset, displayName, standardDisplayName, daylightDisplayName, adjustmentRules, disableDaylightSavingTime);
2019  }
2020 
2024  void IDeserializationCallback.OnDeserialization(object sender)
2025  {
2026  try
2027  {
2028  ValidateTimeZoneInfo(m_id, m_baseUtcOffset, m_adjustmentRules, out bool adjustmentRulesSupportDst);
2029  if (adjustmentRulesSupportDst != m_supportsDaylightSavingTime)
2030  {
2031  throw new SerializationException(Environment.GetResourceString("Serialization_CorruptField", "SupportsDaylightSavingTime"));
2032  }
2033  }
2034  catch (ArgumentException innerException)
2035  {
2036  throw new SerializationException(Environment.GetResourceString("Serialization_InvalidData"), innerException);
2037  }
2038  catch (InvalidTimeZoneException innerException2)
2039  {
2040  throw new SerializationException(Environment.GetResourceString("Serialization_InvalidData"), innerException2);
2041  }
2042  }
2043 
2048  [SecurityCritical]
2050  {
2051  if (info == null)
2052  {
2053  throw new ArgumentNullException("info");
2054  }
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);
2062  }
2063 
2064  private TimeZoneInfo(SerializationInfo info, StreamingContext context)
2065  {
2066  if (info == null)
2067  {
2068  throw new ArgumentNullException("info");
2069  }
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));
2077  }
2078 
2079  private AdjustmentRule GetAdjustmentRuleForTime(DateTime dateTime)
2080  {
2081  if (m_adjustmentRules == null || m_adjustmentRules.Length == 0)
2082  {
2083  return null;
2084  }
2085  DateTime date = dateTime.Date;
2086  for (int i = 0; i < m_adjustmentRules.Length; i++)
2087  {
2088  if (m_adjustmentRules[i].DateStart <= date && m_adjustmentRules[i].DateEnd >= date)
2089  {
2090  return m_adjustmentRules[i];
2091  }
2092  }
2093  return null;
2094  }
2095 
2096  [SecurityCritical]
2097  private static bool CheckDaylightSavingTimeNotSupported(Win32Native.TimeZoneInformation timeZone)
2098  {
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)
2100  {
2101  return timeZone.DaylightDate.Milliseconds == timeZone.StandardDate.Milliseconds;
2102  }
2103  return false;
2104  }
2105 
2106  private static DateTime ConvertUtcToTimeZone(long ticks, TimeZoneInfo destinationTimeZone, out bool isAmbiguousLocalDst)
2107  {
2108  DateTime time = (ticks > DateTime.MaxValue.Ticks) ? DateTime.MaxValue : ((ticks < DateTime.MinValue.Ticks) ? DateTime.MinValue : new DateTime(ticks));
2109  ticks += GetUtcOffsetFromUtc(time, destinationTimeZone, out isAmbiguousLocalDst).Ticks;
2110  if (ticks > DateTime.MaxValue.Ticks)
2111  {
2112  return DateTime.MaxValue;
2113  }
2114  if (ticks < DateTime.MinValue.Ticks)
2115  {
2116  return DateTime.MinValue;
2117  }
2118  return new DateTime(ticks);
2119  }
2120 
2121  [SecurityCritical]
2122  private static AdjustmentRule CreateAdjustmentRuleFromTimeZoneInformation(Win32Native.RegistryTimeZoneInformation timeZoneInformation, DateTime startDate, DateTime endDate, int defaultBaseUtcOffset)
2123  {
2124  if (timeZoneInformation.StandardDate.Month == 0)
2125  {
2126  if (timeZoneInformation.Bias == defaultBaseUtcOffset)
2127  {
2128  return null;
2129  }
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));
2132  }
2133  if (!TransitionTimeFromTimeZoneInformation(timeZoneInformation, out TransitionTime transitionTime, readStartDate: true))
2134  {
2135  return null;
2136  }
2137  if (!TransitionTimeFromTimeZoneInformation(timeZoneInformation, out TransitionTime transitionTime2, readStartDate: false))
2138  {
2139  return null;
2140  }
2141  if (transitionTime.Equals(transitionTime2))
2142  {
2143  return null;
2144  }
2145  return AdjustmentRule.CreateAdjustmentRule(startDate, endDate, new TimeSpan(0, -timeZoneInformation.DaylightBias, 0), transitionTime, transitionTime2, new TimeSpan(0, defaultBaseUtcOffset - timeZoneInformation.Bias, 0));
2146  }
2147 
2148  [SecuritySafeCritical]
2149  private static string FindIdFromTimeZoneInformation(Win32Native.TimeZoneInformation timeZone, out bool dstDisabled)
2150  {
2151  dstDisabled = false;
2152  try
2153  {
2154  PermissionSet permissionSet = new PermissionSet(PermissionState.None);
2155  permissionSet.AddPermission(new RegistryPermission(RegistryPermissionAccess.Read, "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones"));
2156  permissionSet.Assert();
2157  using (RegistryKey registryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones", RegistryKeyPermissionCheck.Default, RegistryRights.ExecuteKey))
2158  {
2159  if (registryKey == null)
2160  {
2161  return null;
2162  }
2163  string[] subKeyNames = registryKey.GetSubKeyNames();
2164  foreach (string text in subKeyNames)
2165  {
2166  if (TryCompareTimeZoneInformationToRegistry(timeZone, text, out dstDisabled))
2167  {
2168  return text;
2169  }
2170  }
2171  }
2172  }
2173  finally
2174  {
2176  }
2177  return null;
2178  }
2179 
2180  private static DaylightTime GetDaylightTime(int year, AdjustmentRule rule)
2181  {
2182  TimeSpan daylightDelta = rule.DaylightDelta;
2183  DateTime start = TransitionTimeToDateTime(year, rule.DaylightTransitionStart);
2184  DateTime end = TransitionTimeToDateTime(year, rule.DaylightTransitionEnd);
2185  return new DaylightTime(start, end, daylightDelta);
2186  }
2187 
2188  private static bool GetIsDaylightSavings(DateTime time, AdjustmentRule rule, DaylightTime daylightTime, TimeZoneInfoOptions flags)
2189  {
2190  if (rule == null)
2191  {
2192  return false;
2193  }
2194  DateTime startTime;
2195  DateTime endTime;
2196  if (time.Kind == DateTimeKind.Local)
2197  {
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(-1L) : daylightTime.End);
2200  }
2201  else
2202  {
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(-1L) : (daylightTime.End + (flag ? (-rule.DaylightDelta) : TimeSpan.Zero)));
2206  }
2207  bool flag2 = CheckIsDst(startTime, time, endTime, ignoreYearAdjustment: false);
2208  if (flag2 && time.Kind == DateTimeKind.Local && GetIsAmbiguousTime(time, rule, daylightTime))
2209  {
2210  flag2 = time.IsAmbiguousDaylightSavingTime();
2211  }
2212  return flag2;
2213  }
2214 
2215  private static bool GetIsDaylightSavingsFromUtc(DateTime time, int Year, TimeSpan utc, AdjustmentRule rule, out bool isAmbiguousLocalDst, TimeZoneInfo zone)
2216  {
2217  isAmbiguousLocalDst = false;
2218  if (rule == null)
2219  {
2220  return false;
2221  }
2222  TimeSpan t = utc + rule.BaseUtcOffsetDelta;
2223  DaylightTime daylightTime = GetDaylightTime(Year, rule);
2224  bool ignoreYearAdjustment = false;
2225  DateTime dateTime;
2226  if (rule.IsStartDateMarkerForBeginningOfYear() && daylightTime.Start.Year > DateTime.MinValue.Year)
2227  {
2228  AdjustmentRule adjustmentRuleForTime = zone.GetAdjustmentRuleForTime(new DateTime(daylightTime.Start.Year - 1, 12, 31));
2229  if (adjustmentRuleForTime != null && adjustmentRuleForTime.IsEndDateMarkerForEndOfYear())
2230  {
2231  DaylightTime daylightTime2 = GetDaylightTime(daylightTime.Start.Year - 1, adjustmentRuleForTime);
2232  dateTime = daylightTime2.Start - utc - adjustmentRuleForTime.BaseUtcOffsetDelta;
2233  ignoreYearAdjustment = true;
2234  }
2235  else
2236  {
2237  dateTime = new DateTime(daylightTime.Start.Year, 1, 1, 0, 0, 0) - t;
2238  }
2239  }
2240  else
2241  {
2242  dateTime = daylightTime.Start - t;
2243  }
2244  DateTime dateTime2;
2245  if (rule.IsEndDateMarkerForEndOfYear() && daylightTime.End.Year < DateTime.MaxValue.Year)
2246  {
2247  AdjustmentRule adjustmentRuleForTime2 = zone.GetAdjustmentRuleForTime(new DateTime(daylightTime.End.Year + 1, 1, 1));
2248  if (adjustmentRuleForTime2 != null && adjustmentRuleForTime2.IsStartDateMarkerForBeginningOfYear())
2249  {
2250  if (adjustmentRuleForTime2.IsEndDateMarkerForEndOfYear())
2251  {
2252  dateTime2 = new DateTime(daylightTime.End.Year + 1, 12, 31) - utc - adjustmentRuleForTime2.BaseUtcOffsetDelta - adjustmentRuleForTime2.DaylightDelta;
2253  }
2254  else
2255  {
2256  DaylightTime daylightTime3 = GetDaylightTime(daylightTime.End.Year + 1, adjustmentRuleForTime2);
2257  dateTime2 = daylightTime3.End - utc - adjustmentRuleForTime2.BaseUtcOffsetDelta - adjustmentRuleForTime2.DaylightDelta;
2258  }
2259  ignoreYearAdjustment = true;
2260  }
2261  else
2262  {
2263  dateTime2 = new DateTime(daylightTime.End.Year + 1, 1, 1, 0, 0, 0).AddTicks(-1L) - t - rule.DaylightDelta;
2264  }
2265  }
2266  else
2267  {
2268  dateTime2 = daylightTime.End - t - rule.DaylightDelta;
2269  }
2270  DateTime t2;
2271  DateTime t3;
2272  if (daylightTime.Delta.Ticks > 0)
2273  {
2274  t2 = dateTime2 - daylightTime.Delta;
2275  t3 = dateTime2;
2276  }
2277  else
2278  {
2279  t2 = dateTime;
2280  t3 = dateTime - daylightTime.Delta;
2281  }
2282  bool flag = CheckIsDst(dateTime, time, dateTime2, ignoreYearAdjustment);
2283  if (flag)
2284  {
2285  isAmbiguousLocalDst = (time >= t2 && time < t3);
2286  if (!isAmbiguousLocalDst && t2.Year != t3.Year)
2287  {
2288  try
2289  {
2290  DateTime dateTime3 = t2.AddYears(1);
2291  DateTime dateTime4 = t3.AddYears(1);
2292  isAmbiguousLocalDst = (time >= t2 && time < t3);
2293  }
2294  catch (ArgumentOutOfRangeException)
2295  {
2296  }
2297  if (!isAmbiguousLocalDst)
2298  {
2299  try
2300  {
2301  DateTime dateTime3 = t2.AddYears(-1);
2302  DateTime dateTime4 = t3.AddYears(-1);
2303  isAmbiguousLocalDst = (time >= t2 && time < t3);
2304  return flag;
2305  }
2306  catch (ArgumentOutOfRangeException)
2307  {
2308  return flag;
2309  }
2310  }
2311  }
2312  }
2313  return flag;
2314  }
2315 
2316  private static bool CheckIsDst(DateTime startTime, DateTime time, DateTime endTime, bool ignoreYearAdjustment)
2317  {
2318  if (!ignoreYearAdjustment)
2319  {
2320  int year = startTime.Year;
2321  int year2 = endTime.Year;
2322  if (year != year2)
2323  {
2324  endTime = endTime.AddYears(year - year2);
2325  }
2326  int year3 = time.Year;
2327  if (year != year3)
2328  {
2329  time = time.AddYears(year - year3);
2330  }
2331  }
2332  if (startTime > endTime)
2333  {
2334  return time < endTime || time >= startTime;
2335  }
2336  return time >= startTime && time < endTime;
2337  }
2338 
2339  private static bool GetIsAmbiguousTime(DateTime time, AdjustmentRule rule, DaylightTime daylightTime)
2340  {
2341  bool result = false;
2342  if (rule == null || rule.DaylightDelta == TimeSpan.Zero)
2343  {
2344  return result;
2345  }
2346  DateTime t;
2347  DateTime t2;
2348  if (rule.DaylightDelta > TimeSpan.Zero)
2349  {
2350  if (rule.IsEndDateMarkerForEndOfYear())
2351  {
2352  return false;
2353  }
2354  t = daylightTime.End;
2355  t2 = daylightTime.End - rule.DaylightDelta;
2356  }
2357  else
2358  {
2359  if (rule.IsStartDateMarkerForBeginningOfYear())
2360  {
2361  return false;
2362  }
2363  t = daylightTime.Start;
2364  t2 = daylightTime.Start + rule.DaylightDelta;
2365  }
2366  result = (time >= t2 && time < t);
2367  if (!result && t.Year != t2.Year)
2368  {
2369  try
2370  {
2371  DateTime t3 = t.AddYears(1);
2372  DateTime t4 = t2.AddYears(1);
2373  result = (time >= t4 && time < t3);
2374  }
2375  catch (ArgumentOutOfRangeException)
2376  {
2377  }
2378  if (!result)
2379  {
2380  try
2381  {
2382  DateTime t3 = t.AddYears(-1);
2383  DateTime t4 = t2.AddYears(-1);
2384  result = (time >= t4 && time < t3);
2385  return result;
2386  }
2387  catch (ArgumentOutOfRangeException)
2388  {
2389  return result;
2390  }
2391  }
2392  }
2393  return result;
2394  }
2395 
2396  private static bool GetIsInvalidTime(DateTime time, AdjustmentRule rule, DaylightTime daylightTime)
2397  {
2398  bool result = false;
2399  if (rule == null || rule.DaylightDelta == TimeSpan.Zero)
2400  {
2401  return result;
2402  }
2403  DateTime t;
2404  DateTime t2;
2405  if (rule.DaylightDelta < TimeSpan.Zero)
2406  {
2407  if (rule.IsEndDateMarkerForEndOfYear())
2408  {
2409  return false;
2410  }
2411  t = daylightTime.End;
2412  t2 = daylightTime.End - rule.DaylightDelta;
2413  }
2414  else
2415  {
2416  if (rule.IsStartDateMarkerForBeginningOfYear())
2417  {
2418  return false;
2419  }
2420  t = daylightTime.Start;
2421  t2 = daylightTime.Start + rule.DaylightDelta;
2422  }
2423  result = (time >= t && time < t2);
2424  if (!result && t.Year != t2.Year)
2425  {
2426  try
2427  {
2428  DateTime t3 = t.AddYears(1);
2429  DateTime t4 = t2.AddYears(1);
2430  result = (time >= t3 && time < t4);
2431  }
2432  catch (ArgumentOutOfRangeException)
2433  {
2434  }
2435  if (!result)
2436  {
2437  try
2438  {
2439  DateTime t3 = t.AddYears(-1);
2440  DateTime t4 = t2.AddYears(-1);
2441  result = (time >= t3 && time < t4);
2442  return result;
2443  }
2444  catch (ArgumentOutOfRangeException)
2445  {
2446  return result;
2447  }
2448  }
2449  }
2450  return result;
2451  }
2452 
2453  [SecuritySafeCritical]
2454  private static TimeZoneInfo GetLocalTimeZone(CachedData cachedData)
2455  {
2456  string text = null;
2457  Win32Native.DynamicTimeZoneInformation lpDynamicTimeZoneInformation = default(Win32Native.DynamicTimeZoneInformation);
2458  long num = UnsafeNativeMethods.GetDynamicTimeZoneInformation(out lpDynamicTimeZoneInformation);
2459  if (num == -1)
2460  {
2461  return CreateCustomTimeZone("Local", TimeSpan.Zero, "Local", "Local");
2462  }
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)
2466  {
2467  return value;
2468  }
2469  text = FindIdFromTimeZoneInformation(timeZoneInformation, out dstDisabled);
2470  if (text != null && TryGetTimeZone(text, dstDisabled, out TimeZoneInfo value2, out Exception _, cachedData) == TimeZoneInfoResult.Success)
2471  {
2472  return value2;
2473  }
2474  return GetLocalTimeZoneFromWin32Data(timeZoneInformation, dstDisabled);
2475  }
2476 
2477  [SecurityCritical]
2478  private static TimeZoneInfo GetLocalTimeZoneFromWin32Data(Win32Native.TimeZoneInformation timeZoneInformation, bool dstDisabled)
2479  {
2480  try
2481  {
2482  return new TimeZoneInfo(timeZoneInformation, dstDisabled);
2483  }
2484  catch (ArgumentException)
2485  {
2486  }
2487  catch (InvalidTimeZoneException)
2488  {
2489  }
2490  if (!dstDisabled)
2491  {
2492  try
2493  {
2494  return new TimeZoneInfo(timeZoneInformation, dstDisabled: true);
2495  }
2496  catch (ArgumentException)
2497  {
2498  }
2499  catch (InvalidTimeZoneException)
2500  {
2501  }
2502  }
2503  return CreateCustomTimeZone("Local", TimeSpan.Zero, "Local", "Local");
2504  }
2505 
2514  [__DynamicallyInvokable]
2515  public static TimeZoneInfo FindSystemTimeZoneById(string id)
2516  {
2517  if (string.Compare(id, "UTC", StringComparison.OrdinalIgnoreCase) == 0)
2518  {
2519  return Utc;
2520  }
2521  if (id == null)
2522  {
2523  throw new ArgumentNullException("id");
2524  }
2525  if (id.Length == 0 || id.Length > 255 || id.Contains("\0"))
2526  {
2527  throw new TimeZoneNotFoundException(Environment.GetResourceString("TimeZoneNotFound_MissingRegistryData", id));
2528  }
2529  CachedData cachedData = s_cachedData;
2530  TimeZoneInfoResult timeZoneInfoResult;
2531  TimeZoneInfo value;
2532  Exception e;
2533  lock (cachedData)
2534  {
2535  timeZoneInfoResult = TryGetTimeZone(id, dstDisabled: false, out value, out e, cachedData);
2536  }
2537  switch (timeZoneInfoResult)
2538  {
2539  case TimeZoneInfoResult.Success:
2540  return value;
2541  case TimeZoneInfoResult.InvalidTimeZoneException:
2542  throw new InvalidTimeZoneException(Environment.GetResourceString("InvalidTimeZone_InvalidRegistryData", id), e);
2543  case TimeZoneInfoResult.SecurityException:
2544  throw new SecurityException(Environment.GetResourceString("Security_CannotReadRegistryData", id), e);
2545  default:
2546  throw new TimeZoneNotFoundException(Environment.GetResourceString("TimeZoneNotFound_MissingRegistryData", id), e);
2547  }
2548  }
2549 
2550  private static TimeSpan GetUtcOffset(DateTime time, TimeZoneInfo zone, TimeZoneInfoOptions flags)
2551  {
2552  TimeSpan timeSpan = zone.BaseUtcOffset;
2553  AdjustmentRule adjustmentRuleForTime = zone.GetAdjustmentRuleForTime(time);
2554  if (adjustmentRuleForTime != null)
2555  {
2556  timeSpan += adjustmentRuleForTime.BaseUtcOffsetDelta;
2557  if (adjustmentRuleForTime.HasDaylightSaving)
2558  {
2559  DaylightTime daylightTime = GetDaylightTime(time.Year, adjustmentRuleForTime);
2560  bool isDaylightSavings = GetIsDaylightSavings(time, adjustmentRuleForTime, daylightTime, flags);
2561  timeSpan += (isDaylightSavings ? adjustmentRuleForTime.DaylightDelta : TimeSpan.Zero);
2562  }
2563  }
2564  return timeSpan;
2565  }
2566 
2567  private static TimeSpan GetUtcOffsetFromUtc(DateTime time, TimeZoneInfo zone)
2568  {
2569  bool isDaylightSavings;
2570  return GetUtcOffsetFromUtc(time, zone, out isDaylightSavings);
2571  }
2572 
2573  private static TimeSpan GetUtcOffsetFromUtc(DateTime time, TimeZoneInfo zone, out bool isDaylightSavings)
2574  {
2575  bool isAmbiguousLocalDst;
2576  return GetUtcOffsetFromUtc(time, zone, out isDaylightSavings, out isAmbiguousLocalDst);
2577  }
2578 
2579  internal static TimeSpan GetDateTimeNowUtcOffsetFromUtc(DateTime time, out bool isAmbiguousLocalDst)
2580  {
2581  bool flag = false;
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)
2587  {
2588  timeSpan += oneYearLocalFromUtc.rule.BaseUtcOffsetDelta;
2589  if (oneYearLocalFromUtc.rule.HasDaylightSaving)
2590  {
2591  flag = GetIsDaylightSavingsFromUtc(time, year, oneYearLocalFromUtc.offset, oneYearLocalFromUtc.rule, out isAmbiguousLocalDst, Local);
2592  timeSpan += (flag ? oneYearLocalFromUtc.rule.DaylightDelta : TimeSpan.Zero);
2593  }
2594  }
2595  return timeSpan;
2596  }
2597 
2598  internal static TimeSpan GetUtcOffsetFromUtc(DateTime time, TimeZoneInfo zone, out bool isDaylightSavings, out bool isAmbiguousLocalDst)
2599  {
2600  isDaylightSavings = false;
2601  isAmbiguousLocalDst = false;
2602  TimeSpan timeSpan = zone.BaseUtcOffset;
2603  AdjustmentRule adjustmentRuleForTime;
2604  int year;
2605  if (time > s_maxDateOnly)
2606  {
2607  adjustmentRuleForTime = zone.GetAdjustmentRuleForTime(DateTime.MaxValue);
2608  year = 9999;
2609  }
2610  else if (time < s_minDateOnly)
2611  {
2612  adjustmentRuleForTime = zone.GetAdjustmentRuleForTime(DateTime.MinValue);
2613  year = 1;
2614  }
2615  else
2616  {
2617  DateTime dateTime = time + timeSpan;
2618  year = dateTime.Year;
2619  adjustmentRuleForTime = zone.GetAdjustmentRuleForTime(dateTime);
2620  }
2621  if (adjustmentRuleForTime != null)
2622  {
2623  timeSpan += adjustmentRuleForTime.BaseUtcOffsetDelta;
2624  if (adjustmentRuleForTime.HasDaylightSaving)
2625  {
2626  isDaylightSavings = GetIsDaylightSavingsFromUtc(time, year, zone.m_baseUtcOffset, adjustmentRuleForTime, out isAmbiguousLocalDst, zone);
2627  timeSpan += (isDaylightSavings ? adjustmentRuleForTime.DaylightDelta : TimeSpan.Zero);
2628  }
2629  }
2630  return timeSpan;
2631  }
2632 
2633  [SecurityCritical]
2634  private static bool TransitionTimeFromTimeZoneInformation(Win32Native.RegistryTimeZoneInformation timeZoneInformation, out TransitionTime transitionTime, bool readStartDate)
2635  {
2636  if (timeZoneInformation.StandardDate.Month == 0)
2637  {
2638  transitionTime = default(TransitionTime);
2639  return false;
2640  }
2641  if (readStartDate)
2642  {
2643  if (timeZoneInformation.DaylightDate.Year == 0)
2644  {
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);
2646  }
2647  else
2648  {
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);
2650  }
2651  }
2652  else if (timeZoneInformation.StandardDate.Year == 0)
2653  {
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);
2655  }
2656  else
2657  {
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);
2659  }
2660  return true;
2661  }
2662 
2663  private static DateTime TransitionTimeToDateTime(int year, TransitionTime transitionTime)
2664  {
2665  DateTime timeOfDay = transitionTime.TimeOfDay;
2666  DateTime result = default(DateTime);
2667  if (transitionTime.IsFixedDateRule)
2668  {
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);
2671  }
2672  else if (transitionTime.Week <= 4)
2673  {
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);
2677  if (num2 < 0)
2678  {
2679  num2 += 7;
2680  }
2681  num2 += 7 * (transitionTime.Week - 1);
2682  if (num2 > 0)
2683  {
2684  result = result.AddDays(num2);
2685  return result;
2686  }
2687  }
2688  else
2689  {
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);
2694  if (num3 < 0)
2695  {
2696  num3 += 7;
2697  }
2698  if (num3 > 0)
2699  {
2700  result = result.AddDays(-num3);
2701  return result;
2702  }
2703  }
2704  return result;
2705  }
2706 
2707  [SecurityCritical]
2708  private static bool TryCreateAdjustmentRules(string id, Win32Native.RegistryTimeZoneInformation defaultTimeZoneInformation, out AdjustmentRule[] rules, out Exception e, int defaultBaseUtcOffset)
2709  {
2710  e = null;
2711  try
2712  {
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))
2714  {
2715  if (registryKey == null)
2716  {
2717  AdjustmentRule adjustmentRule = CreateAdjustmentRuleFromTimeZoneInformation(defaultTimeZoneInformation, DateTime.MinValue.Date, DateTime.MaxValue.Date, defaultBaseUtcOffset);
2718  if (adjustmentRule == null)
2719  {
2720  rules = null;
2721  }
2722  else
2723  {
2724  rules = new AdjustmentRule[1];
2725  rules[0] = adjustmentRule;
2726  }
2727  return true;
2728  }
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)
2732  {
2733  rules = null;
2734  return false;
2735  }
2736  byte[] array = registryKey.GetValue(num.ToString(CultureInfo.InvariantCulture), null, RegistryValueOptions.None) as byte[];
2737  if (array == null || array.Length != 44)
2738  {
2739  rules = null;
2740  return false;
2741  }
2742  Win32Native.RegistryTimeZoneInformation timeZoneInformation = new Win32Native.RegistryTimeZoneInformation(array);
2743  if (num == num2)
2744  {
2745  AdjustmentRule adjustmentRule2 = CreateAdjustmentRuleFromTimeZoneInformation(timeZoneInformation, DateTime.MinValue.Date, DateTime.MaxValue.Date, defaultBaseUtcOffset);
2746  if (adjustmentRule2 == null)
2747  {
2748  rules = null;
2749  }
2750  else
2751  {
2752  rules = new AdjustmentRule[1];
2753  rules[0] = adjustmentRule2;
2754  }
2755  return true;
2756  }
2758  AdjustmentRule adjustmentRule3 = CreateAdjustmentRuleFromTimeZoneInformation(timeZoneInformation, DateTime.MinValue.Date, new DateTime(num, 12, 31), defaultBaseUtcOffset);
2759  if (adjustmentRule3 != null)
2760  {
2761  list.Add(adjustmentRule3);
2762  }
2763  for (int i = num + 1; i < num2; i++)
2764  {
2765  array = (registryKey.GetValue(i.ToString(CultureInfo.InvariantCulture), null, RegistryValueOptions.None) as byte[]);
2766  if (array == null || array.Length != 44)
2767  {
2768  rules = null;
2769  return false;
2770  }
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)
2774  {
2775  list.Add(adjustmentRule4);
2776  }
2777  }
2778  array = (registryKey.GetValue(num2.ToString(CultureInfo.InvariantCulture), null, RegistryValueOptions.None) as byte[]);
2779  timeZoneInformation = new Win32Native.RegistryTimeZoneInformation(array);
2780  if (array == null || array.Length != 44)
2781  {
2782  rules = null;
2783  return false;
2784  }
2785  AdjustmentRule adjustmentRule5 = CreateAdjustmentRuleFromTimeZoneInformation(timeZoneInformation, new DateTime(num2, 1, 1), DateTime.MaxValue.Date, defaultBaseUtcOffset);
2786  if (adjustmentRule5 != null)
2787  {
2788  list.Add(adjustmentRule5);
2789  }
2790  rules = list.ToArray();
2791  if (rules != null && rules.Length == 0)
2792  {
2793  rules = null;
2794  }
2795  }
2796  }
2797  catch (InvalidCastException ex)
2798  {
2799  rules = null;
2800  e = ex;
2801  return false;
2802  }
2803  catch (ArgumentOutOfRangeException ex2)
2804  {
2805  rules = null;
2806  e = ex2;
2807  return false;
2808  }
2809  catch (ArgumentException ex3)
2810  {
2811  rules = null;
2812  e = ex3;
2813  return false;
2814  }
2815  return true;
2816  }
2817 
2818  [SecurityCritical]
2819  private static bool TryCompareStandardDate(Win32Native.TimeZoneInformation timeZone, Win32Native.RegistryTimeZoneInformation registryTimeZoneInfo)
2820  {
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)
2822  {
2823  return timeZone.StandardDate.Milliseconds == registryTimeZoneInfo.StandardDate.Milliseconds;
2824  }
2825  return false;
2826  }
2827 
2828  [SecuritySafeCritical]
2829  private static bool TryCompareTimeZoneInformationToRegistry(Win32Native.TimeZoneInformation timeZone, string id, out bool dstDisabled)
2830  {
2831  dstDisabled = false;
2832  try
2833  {
2834  PermissionSet permissionSet = new PermissionSet(PermissionState.None);
2835  permissionSet.AddPermission(new RegistryPermission(RegistryPermissionAccess.Read, "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones"));
2836  permissionSet.Assert();
2837  using (RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(string.Format(CultureInfo.InvariantCulture, "{0}\\{1}", "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones", id), RegistryKeyPermissionCheck.Default, RegistryRights.ExecuteKey))
2838  {
2839  if (registryKey == null)
2840  {
2841  return false;
2842  }
2843  byte[] array = (byte[])registryKey.GetValue("TZI", null, RegistryValueOptions.None);
2844  if (array == null || array.Length != 44)
2845  {
2846  return false;
2847  }
2848  Win32Native.RegistryTimeZoneInformation registryTimeZoneInformation = new Win32Native.RegistryTimeZoneInformation(array);
2849  if (!TryCompareStandardDate(timeZone, registryTimeZoneInformation))
2850  {
2851  return false;
2852  }
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);
2854  if (flag)
2855  {
2856  string strA = registryKey.GetValue("Std", string.Empty, RegistryValueOptions.None) as string;
2857  flag = (string.Compare(strA, timeZone.StandardName, StringComparison.Ordinal) == 0);
2858  }
2859  return flag;
2860  }
2861  }
2862  finally
2863  {
2865  }
2866  }
2867 
2868  [SecuritySafeCritical]
2869  [FileIOPermission(SecurityAction.Assert, AllLocalFiles = FileIOPermissionAccess.PathDiscovery)]
2870  private static string TryGetLocalizedNameByMuiNativeResource(string resource)
2871  {
2872  if (string.IsNullOrEmpty(resource))
2873  {
2874  return string.Empty;
2875  }
2876  string[] array = resource.Split(new char[1]
2877  {
2878  ','
2879  }, StringSplitOptions.None);
2880  if (array.Length != 2)
2881  {
2882  return string.Empty;
2883  }
2884  string path = Environment.UnsafeGetFolderPath(Environment.SpecialFolder.System);
2885  string path2 = array[0].TrimStart('@');
2886  string filePath;
2887  try
2888  {
2889  filePath = Path.Combine(path, path2);
2890  }
2891  catch (ArgumentException)
2892  {
2893  return string.Empty;
2894  }
2895  if (!int.TryParse(array[1], NumberStyles.Integer, CultureInfo.InvariantCulture, out int result))
2896  {
2897  return string.Empty;
2898  }
2899  result = -result;
2900  try
2901  {
2902  StringBuilder stringBuilder = StringBuilderCache.Acquire(260);
2903  stringBuilder.Length = 260;
2904  int fileMuiPathLength = 260;
2905  int languageLength = 0;
2906  long enumerator = 0L;
2907  if (!UnsafeNativeMethods.GetFileMUIPath(16, filePath, null, ref languageLength, stringBuilder, ref fileMuiPathLength, ref enumerator))
2908  {
2909  StringBuilderCache.Release(stringBuilder);
2910  return string.Empty;
2911  }
2912  return TryGetLocalizedNameByNativeResource(StringBuilderCache.GetStringAndRelease(stringBuilder), result);
2913  }
2914  catch (EntryPointNotFoundException)
2915  {
2916  return string.Empty;
2917  }
2918  }
2919 
2920  [SecurityCritical]
2921  private static string TryGetLocalizedNameByNativeResource(string filePath, int resource)
2922  {
2923  using (SafeLibraryHandle safeLibraryHandle = UnsafeNativeMethods.LoadLibraryEx(filePath, IntPtr.Zero, 2))
2924  {
2925  if (!safeLibraryHandle.IsInvalid)
2926  {
2927  StringBuilder stringBuilder = StringBuilderCache.Acquire(500);
2928  stringBuilder.Length = 500;
2929  if (UnsafeNativeMethods.LoadString(safeLibraryHandle, resource, stringBuilder, stringBuilder.Length) != 0)
2930  {
2931  return StringBuilderCache.GetStringAndRelease(stringBuilder);
2932  }
2933  }
2934  }
2935  return string.Empty;
2936  }
2937 
2938  private static bool TryGetLocalizedNamesByRegistryKey(RegistryKey key, out string displayName, out string standardName, out string daylightName)
2939  {
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))
2947  {
2948  displayName = TryGetLocalizedNameByMuiNativeResource(text);
2949  }
2950  if (!string.IsNullOrEmpty(text2))
2951  {
2952  standardName = TryGetLocalizedNameByMuiNativeResource(text2);
2953  }
2954  if (!string.IsNullOrEmpty(text3))
2955  {
2956  daylightName = TryGetLocalizedNameByMuiNativeResource(text3);
2957  }
2958  if (string.IsNullOrEmpty(displayName))
2959  {
2960  displayName = (key.GetValue("Display", string.Empty, RegistryValueOptions.None) as string);
2961  }
2962  if (string.IsNullOrEmpty(standardName))
2963  {
2964  standardName = (key.GetValue("Std", string.Empty, RegistryValueOptions.None) as string);
2965  }
2966  if (string.IsNullOrEmpty(daylightName))
2967  {
2968  daylightName = (key.GetValue("Dlt", string.Empty, RegistryValueOptions.None) as string);
2969  }
2970  return true;
2971  }
2972 
2973  [SecuritySafeCritical]
2974  private static TimeZoneInfoResult TryGetTimeZoneByRegistryKey(string id, out TimeZoneInfo value, out Exception e)
2975  {
2976  e = null;
2977  try
2978  {
2979  PermissionSet permissionSet = new PermissionSet(PermissionState.None);
2980  permissionSet.AddPermission(new RegistryPermission(RegistryPermissionAccess.Read, "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones"));
2981  permissionSet.Assert();
2982  using (RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(string.Format(CultureInfo.InvariantCulture, "{0}\\{1}", "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones", id), RegistryKeyPermissionCheck.Default, RegistryRights.ExecuteKey))
2983  {
2984  if (registryKey == null)
2985  {
2986  value = null;
2987  return TimeZoneInfoResult.TimeZoneNotFoundException;
2988  }
2989  byte[] array = registryKey.GetValue("TZI", null, RegistryValueOptions.None) as byte[];
2990  if (array == null || array.Length != 44)
2991  {
2992  value = null;
2993  return TimeZoneInfoResult.InvalidTimeZoneException;
2994  }
2995  Win32Native.RegistryTimeZoneInformation registryTimeZoneInformation = new Win32Native.RegistryTimeZoneInformation(array);
2996  if (!TryCreateAdjustmentRules(id, registryTimeZoneInformation, out AdjustmentRule[] rules, out e, registryTimeZoneInformation.Bias))
2997  {
2998  value = null;
2999  return TimeZoneInfoResult.InvalidTimeZoneException;
3000  }
3001  if (TryGetLocalizedNamesByRegistryKey(registryKey, out string displayName, out string standardName, out string daylightName))
3002  {
3003  try
3004  {
3005  value = new TimeZoneInfo(id, new TimeSpan(0, -registryTimeZoneInformation.Bias, 0), displayName, standardName, daylightName, rules, disableDaylightSavingTime: false);
3006  return TimeZoneInfoResult.Success;
3007  }
3008  catch (ArgumentException ex)
3009  {
3010  value = null;
3011  e = ex;
3012  return TimeZoneInfoResult.InvalidTimeZoneException;
3013  }
3014  catch (InvalidTimeZoneException ex2)
3015  {
3016  value = null;
3017  e = ex2;
3018  return TimeZoneInfoResult.InvalidTimeZoneException;
3019  }
3020  }
3021  value = null;
3022  return TimeZoneInfoResult.InvalidTimeZoneException;
3023  }
3024  }
3025  finally
3026  {
3028  }
3029  }
3030 
3031  private static TimeZoneInfoResult TryGetTimeZone(string id, bool dstDisabled, out TimeZoneInfo value, out Exception e, CachedData cachedData)
3032  {
3033  TimeZoneInfoResult result = TimeZoneInfoResult.Success;
3034  e = null;
3035  TimeZoneInfo value2 = null;
3036  if (cachedData.m_systemTimeZones != null && cachedData.m_systemTimeZones.TryGetValue(id, out value2))
3037  {
3038  if (dstDisabled && value2.m_supportsDaylightSavingTime)
3039  {
3040  value = CreateCustomTimeZone(value2.m_id, value2.m_baseUtcOffset, value2.m_displayName, value2.m_standardDisplayName);
3041  }
3042  else
3043  {
3044  value = new TimeZoneInfo(value2.m_id, value2.m_baseUtcOffset, value2.m_displayName, value2.m_standardDisplayName, value2.m_daylightDisplayName, value2.m_adjustmentRules, disableDaylightSavingTime: false);
3045  }
3046  return result;
3047  }
3048  if (!cachedData.m_allSystemTimeZonesRead)
3049  {
3050  result = TryGetTimeZoneByRegistryKey(id, out value2, out e);
3051  if (result == TimeZoneInfoResult.Success)
3052  {
3053  if (cachedData.m_systemTimeZones == null)
3054  {
3055  cachedData.m_systemTimeZones = new Dictionary<string, TimeZoneInfo>();
3056  }
3057  cachedData.m_systemTimeZones.Add(id, value2);
3058  if (dstDisabled && value2.m_supportsDaylightSavingTime)
3059  {
3060  value = CreateCustomTimeZone(value2.m_id, value2.m_baseUtcOffset, value2.m_displayName, value2.m_standardDisplayName);
3061  }
3062  else
3063  {
3064  value = new TimeZoneInfo(value2.m_id, value2.m_baseUtcOffset, value2.m_displayName, value2.m_standardDisplayName, value2.m_daylightDisplayName, value2.m_adjustmentRules, disableDaylightSavingTime: false);
3065  }
3066  }
3067  else
3068  {
3069  value = null;
3070  }
3071  }
3072  else
3073  {
3074  result = TimeZoneInfoResult.TimeZoneNotFoundException;
3075  value = null;
3076  }
3077  return result;
3078  }
3079 
3080  internal static bool UtcOffsetOutOfRange(TimeSpan offset)
3081  {
3082  if (!(offset.TotalHours < -14.0))
3083  {
3084  return offset.TotalHours > 14.0;
3085  }
3086  return true;
3087  }
3088 
3089  private static void ValidateTimeZoneInfo(string id, TimeSpan baseUtcOffset, AdjustmentRule[] adjustmentRules, out bool adjustmentRulesSupportDst)
3090  {
3091  if (id == null)
3092  {
3093  throw new ArgumentNullException("id");
3094  }
3095  if (id.Length == 0)
3096  {
3097  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidId", id), "id");
3098  }
3099  if (UtcOffsetOutOfRange(baseUtcOffset))
3100  {
3101  throw new ArgumentOutOfRangeException("baseUtcOffset", Environment.GetResourceString("ArgumentOutOfRange_UtcOffset"));
3102  }
3103  if (baseUtcOffset.Ticks % 600000000 != 0L)
3104  {
3105  throw new ArgumentException(Environment.GetResourceString("Argument_TimeSpanHasSeconds"), "baseUtcOffset");
3106  }
3107  adjustmentRulesSupportDst = false;
3108  if (adjustmentRules == null || adjustmentRules.Length == 0)
3109  {
3110  return;
3111  }
3112  adjustmentRulesSupportDst = true;
3113  AdjustmentRule adjustmentRule = null;
3114  AdjustmentRule adjustmentRule2 = null;
3115  int num = 0;
3116  while (true)
3117  {
3118  if (num < adjustmentRules.Length)
3119  {
3120  adjustmentRule = adjustmentRule2;
3121  adjustmentRule2 = adjustmentRules[num];
3122  if (adjustmentRule2 == null)
3123  {
3124  throw new InvalidTimeZoneException(Environment.GetResourceString("Argument_AdjustmentRulesNoNulls"));
3125  }
3126  if (UtcOffsetOutOfRange(baseUtcOffset + adjustmentRule2.DaylightDelta))
3127  {
3128  throw new InvalidTimeZoneException(Environment.GetResourceString("ArgumentOutOfRange_UtcOffsetAndDaylightDelta"));
3129  }
3130  if (adjustmentRule != null && adjustmentRule2.DateStart <= adjustmentRule.DateEnd)
3131  {
3132  break;
3133  }
3134  num++;
3135  continue;
3136  }
3137  return;
3138  }
3139  throw new InvalidTimeZoneException(Environment.GetResourceString("Argument_AdjustmentRulesOutOfOrder"));
3140  }
3141  }
3142 }
Represents any time zone in the world.
Definition: TimeZoneInfo.cs:20
static CultureInfo InvariantCulture
Gets the T:System.Globalization.CultureInfo object that is culture-independent (invariant).
Definition: CultureInfo.cs:263
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.
Definition: Path.cs:1107
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.
Definition: DateTime.cs:109
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 ...
Definition: __Canon.cs:3
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.
Definition: DaylightTime.cs:26
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.
Definition: DateTime.cs:327
Represents an instant in time, typically expressed as a date and time of day. To browse the ....
Definition: DateTime.cs:13
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.
Definition: IComparer.cs:6
Provides culture-specific information about the format of date and time values.
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...
Definition: NumberStyles.cs:10
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.
Definition: DateTime.cs:303
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.
Definition: DateTime.cs:196
long Ticks
Gets the number of ticks that represent the value of the current T:System.TimeSpan structure.
Definition: TimeSpan.cs:84
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.
Definition: DateTime.cs:351
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
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,...
Definition: DateTime.cs:208
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.
Definition: DaylightTime.cs:22
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.
Definition: DateTime.cs:240
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.
Definition: TimeSpan.cs:64
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.
Definition: DateTime.cs:160
DateTime Start
Gets the object that represents the date and time when the daylight saving period begins.
Definition: DaylightTime.cs:18
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,...
Definition: Dictionary.cs:17
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.
Definition: ISerializable.cs:8
DateTime AddMilliseconds(double value)
Returns a new T:System.DateTime that adds the specified number of milliseconds to the value of this i...
Definition: DateTime.cs:758
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
Definition: List.cs:14
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...
Definition: Exception.cs:22
int Month
Gets the month component of the date represented by this instance.
Definition: DateTime.cs:252
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition: IEquatable.cs:6
DateTimeKind
Specifies whether a T:System.DateTime object represents a local time, a Coordinated Universal Time (U...
Definition: DateTimeKind.cs:9
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,...
Definition: TimeSpan.cs:12
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.
Definition: DaylightTime.cs:8
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...
static DateTimeFormatInfo InvariantInfo
Gets the default read-only T:System.Globalization.DateTimeFormatInfo object that is culture-independe...
Provides information about a specific culture (called a locale for unmanaged code development)....
Definition: CultureInfo.cs:16
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....
Definition: Path.cs:13
DayOfWeek
Specifies the day of the week.
Definition: DayOfWeek.cs:9
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.
Definition: DateTime.cs:315
string StandardName
Gets the display name for the time zone's standard time.
static void ClearCachedData()
Clears cached time zone data.