Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
TimeZoneInfo.cs
Go to the documentation of this file.
5using System.IO;
9using System.Text;
10using Internal.Win32;
11
12namespace System;
13
15[TypeForwardedFrom("System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
16public sealed class TimeZoneInfo : IEquatable<TimeZoneInfo?>, ISerializable, IDeserializationCallback
17{
18 [Serializable]
19 public sealed class AdjustmentRule : IEquatable<AdjustmentRule?>, ISerializable, IDeserializationCallback
20 {
21 private static readonly TimeSpan DaylightDeltaAdjustment = TimeSpan.FromHours(24.0);
22
23 private static readonly TimeSpan MaxDaylightDelta = TimeSpan.FromHours(12.0);
24
25 private readonly DateTime _dateStart;
26
27 private readonly DateTime _dateEnd;
28
29 private readonly TimeSpan _daylightDelta;
30
32
34
35 private readonly TimeSpan _baseUtcOffsetDelta;
36
37 private readonly bool _noDaylightTransitions;
38
40
42
44
46
48
50
52
53 internal bool HasDaylightSaving
54 {
55 get
56 {
58 {
60 {
61 return DaylightTransitionEnd.TimeOfDay != DateTime.MinValue.AddMilliseconds(1.0);
62 }
63 return false;
64 }
65 return true;
66 }
67 }
68
69 public bool Equals([NotNullWhen(true)] AdjustmentRule? other)
70 {
71 if (other != null && _dateStart == other._dateStart && _dateEnd == other._dateEnd && _daylightDelta == other._daylightDelta && _baseUtcOffsetDelta == other._baseUtcOffsetDelta && _daylightTransitionEnd.Equals(other._daylightTransitionEnd))
72 {
73 return _daylightTransitionStart.Equals(other._daylightTransitionStart);
74 }
75 return false;
76 }
77
78 public override int GetHashCode()
79 {
80 return _dateStart.GetHashCode();
81 }
82
94
99
104
110
112 {
114 {
116 }
117 return false;
118 }
119
121 {
123 {
125 }
126 return false;
127 }
128
130 {
131 if (dateStart.Kind != 0 && dateStart.Kind != DateTimeKind.Utc)
132 {
134 }
135 if (dateEnd.Kind != 0 && dateEnd.Kind != DateTimeKind.Utc)
136 {
138 }
140 {
141 throw new ArgumentException(SR.Argument_TransitionTimesAreIdentical, "daylightTransitionEnd");
142 }
143 if (dateStart > dateEnd)
144 {
145 throw new ArgumentException(SR.Argument_OutOfOrderDateTimes, "dateStart");
146 }
147 if (daylightDelta.TotalHours < -23.0 || daylightDelta.TotalHours > 14.0)
148 {
150 }
151 if (daylightDelta.Ticks % 600000000 != 0L)
152 {
153 throw new ArgumentException(SR.Argument_TimeSpanHasSeconds, "daylightDelta");
154 }
155 if (dateStart != DateTime.MinValue && dateStart.Kind == DateTimeKind.Unspecified && dateStart.TimeOfDay != TimeSpan.Zero)
156 {
157 throw new ArgumentException(SR.Argument_DateTimeHasTimeOfDay, "dateStart");
158 }
159 if (dateEnd != DateTime.MaxValue && dateEnd.Kind == DateTimeKind.Unspecified && dateEnd.TimeOfDay != TimeSpan.Zero)
160 {
162 }
163 }
164
178
190
192 {
193 if (info == null)
194 {
195 throw new ArgumentNullException("info");
196 }
197 info.AddValue("DateStart", _dateStart);
198 info.AddValue("DateEnd", _dateEnd);
199 info.AddValue("DaylightDelta", _daylightDelta);
200 info.AddValue("DaylightTransitionStart", _daylightTransitionStart);
201 info.AddValue("DaylightTransitionEnd", _daylightTransitionEnd);
202 info.AddValue("BaseUtcOffsetDelta", _baseUtcOffsetDelta);
203 info.AddValue("NoDaylightTransitions", _noDaylightTransitions);
204 }
205
207 {
208 if (info == null)
209 {
210 throw new ArgumentNullException("info");
211 }
212 _dateStart = (DateTime)info.GetValue("DateStart", typeof(DateTime));
213 _dateEnd = (DateTime)info.GetValue("DateEnd", typeof(DateTime));
214 _daylightDelta = (TimeSpan)info.GetValue("DaylightDelta", typeof(TimeSpan));
215 _daylightTransitionStart = (TransitionTime)info.GetValue("DaylightTransitionStart", typeof(TransitionTime));
216 _daylightTransitionEnd = (TransitionTime)info.GetValue("DaylightTransitionEnd", typeof(TransitionTime));
217 object valueNoThrow = info.GetValueNoThrow("BaseUtcOffsetDelta", typeof(TimeSpan));
218 if (valueNoThrow != null)
219 {
221 }
222 valueNoThrow = info.GetValueNoThrow("NoDaylightTransitions", typeof(bool));
223 if (valueNoThrow != null)
224 {
226 }
227 }
228 }
229
237
238 private sealed class CachedData
239 {
240 private volatile TimeZoneInfo _localTimeZone;
241
243
245
247
249
251
253 {
254 lock (this)
255 {
257 if (timeZoneInfo == null)
258 {
260 timeZoneInfo = (_localTimeZone = new TimeZoneInfo(timeZoneInfo._id, timeZoneInfo._baseUtcOffset, timeZoneInfo._displayName, timeZoneInfo._standardDisplayName, timeZoneInfo._daylightDisplayName, timeZoneInfo._adjustmentRules, disableDaylightSavingTime: false, timeZoneInfo.HasIanaId));
261 }
262 return timeZoneInfo;
263 }
264 }
265
267 {
268 if (timeZone != s_utcTimeZone)
269 {
271 {
272 return DateTimeKind.Unspecified;
273 }
274 return DateTimeKind.Local;
275 }
276 return DateTimeKind.Utc;
277 }
278
289
302 }
303
304 private struct StringSerializer
305 {
306 private enum State
307 {
308 Escaped,
312 }
313
314 private readonly string _serializedText;
315
317
318 private State _state;
319
321 {
325 serializedText.Append(';');
326 serializedText.AppendSpanFormattable(zone.BaseUtcOffset.TotalMinutes, null, CultureInfo.InvariantCulture);
327 serializedText.Append(';');
329 serializedText.Append(';');
331 serializedText.Append(';');
333 serializedText.Append(';');
334 AdjustmentRule[] adjustmentRules = zone.GetAdjustmentRules();
337 {
338 serializedText.Append('[');
339 serializedText.AppendSpanFormattable(adjustmentRule.DateStart, "MM:dd:yyyy", DateTimeFormatInfo.InvariantInfo);
340 serializedText.Append(';');
341 serializedText.AppendSpanFormattable(adjustmentRule.DateEnd, "MM:dd:yyyy", DateTimeFormatInfo.InvariantInfo);
342 serializedText.Append(';');
343 serializedText.AppendSpanFormattable(adjustmentRule.DaylightDelta.TotalMinutes, null, CultureInfo.InvariantCulture);
344 serializedText.Append(';');
346 serializedText.Append(';');
348 serializedText.Append(';');
349 if (adjustmentRule.BaseUtcOffsetDelta != TimeSpan.Zero)
350 {
351 serializedText.AppendSpanFormattable(adjustmentRule.BaseUtcOffsetDelta.TotalMinutes, null, CultureInfo.InvariantCulture);
352 serializedText.Append(';');
353 }
354 if (adjustmentRule.NoDaylightTransitions)
355 {
356 serializedText.Append('1');
357 serializedText.Append(';');
358 }
359 serializedText.Append(']');
360 }
361 serializedText.Append(';');
362 return serializedText.ToString();
363 }
364
387
388 private StringSerializer(string str)
389 {
392 _state = State.StartOfToken;
393 }
394
396 {
397 foreach (char c in text)
398 {
399 if (c == '\\' || c == '[' || c == ']' || c == ';')
400 {
401 serializedText.Append('\\');
402 }
403 serializedText.Append(c);
404 }
405 }
406
408 {
409 serializedText.Append('[');
410 serializedText.Append(time.IsFixedDateRule ? '1' : '0');
411 serializedText.Append(';');
412 serializedText.AppendSpanFormattable(time.TimeOfDay, "HH:mm:ss.FFF", DateTimeFormatInfo.InvariantInfo);
413 serializedText.Append(';');
414 serializedText.AppendSpanFormattable(time.Month, null, CultureInfo.InvariantCulture);
415 serializedText.Append(';');
416 if (time.IsFixedDateRule)
417 {
418 serializedText.AppendSpanFormattable(time.Day, null, CultureInfo.InvariantCulture);
419 serializedText.Append(';');
420 }
421 else
422 {
423 serializedText.AppendSpanFormattable(time.Week, null, CultureInfo.InvariantCulture);
424 serializedText.Append(';');
425 serializedText.AppendSpanFormattable((int)time.DayOfWeek, null, CultureInfo.InvariantCulture);
426 serializedText.Append(';');
427 }
428 serializedText.Append(']');
429 }
430
431 private static void VerifyIsEscapableCharacter(char c)
432 {
433 if (c != '\\' && c != ';' && c != '[' && c != ']')
434 {
436 }
437 }
438
439 private void SkipVersionNextDataFields(int depth)
440 {
442 {
444 }
445 State state = State.NotEscaped;
446 for (int i = _currentTokenStartIndex; i < _serializedText.Length; i++)
447 {
448 switch (state)
449 {
450 case State.Escaped:
452 state = State.NotEscaped;
453 break;
454 case State.NotEscaped:
455 switch (_serializedText[i])
456 {
457 case '\\':
458 state = State.Escaped;
459 break;
460 case '[':
461 depth++;
462 break;
463 case ']':
464 depth--;
465 if (depth == 0)
466 {
469 {
470 _state = State.EndOfLine;
471 }
472 else
473 {
474 _state = State.StartOfToken;
475 }
476 return;
477 }
478 break;
479 case '\0':
481 }
482 break;
483 }
484 }
486 }
487
488 private string GetNextStringValue()
489 {
490 if (_state == State.EndOfLine)
491 {
493 }
495 {
497 }
498 State state = State.NotEscaped;
501 for (int i = _currentTokenStartIndex; i < _serializedText.Length; i++)
502 {
503 switch (state)
504 {
505 case State.Escaped:
508 state = State.NotEscaped;
509 break;
510 case State.NotEscaped:
511 switch (_serializedText[i])
512 {
513 case '\\':
514 state = State.Escaped;
515 break;
516 case '[':
518 case ']':
520 case ';':
523 {
524 _state = State.EndOfLine;
525 }
526 else
527 {
528 _state = State.StartOfToken;
529 }
530 return valueStringBuilder.ToString();
531 case '\0':
533 default:
535 break;
536 }
537 break;
538 }
539 }
540 if (state == State.Escaped)
541 {
543 }
545 }
546
556
558 {
560 try
561 {
562 return new TimeSpan(0, nextInt32Value, 0);
563 }
565 {
567 }
568 }
569
570 private int GetNextInt32Value()
571 {
573 if (!int.TryParse(nextStringValue, NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out var result))
574 {
576 }
577 return result;
578 }
579
581 {
583 int num = 0;
585 {
587 num++;
588 }
589 if (_state == State.EndOfLine)
590 {
592 }
594 {
596 }
597 if (num == 0)
598 {
599 return null;
600 }
601 return list.ToArray();
602 }
603
605 {
606 if (_state == State.EndOfLine)
607 {
608 return null;
609 }
611 {
613 }
615 {
616 return null;
617 }
619 {
621 }
629 int num = 0;
630 if (_state == State.EndOfLine || _currentTokenStartIndex >= _serializedText.Length)
631 {
633 }
635 {
637 }
639 {
640 num = GetNextInt32Value();
641 }
642 if (_state == State.EndOfLine || _currentTokenStartIndex >= _serializedText.Length)
643 {
645 }
647 {
649 }
650 else
651 {
653 }
654 AdjustmentRule result;
655 try
656 {
658 }
660 {
662 }
664 {
665 _state = State.EndOfLine;
666 }
667 else
668 {
669 _state = State.StartOfToken;
670 }
671 return result;
672 }
673
675 {
677 {
679 }
681 {
683 }
685 {
687 }
690 if (nextInt32Value != 0 && nextInt32Value != 1)
691 {
693 }
697 TransitionTime result;
698 if (nextInt32Value == 1)
699 {
701 try
702 {
704 }
706 {
708 }
709 }
710 else
711 {
714 try
715 {
717 }
719 {
721 }
722 }
723 if (_state == State.EndOfLine || _currentTokenStartIndex >= _serializedText.Length)
724 {
726 }
728 {
730 }
731 else
732 {
734 }
735 bool flag = false;
737 {
739 flag = true;
740 }
741 if (!flag)
742 {
744 }
746 {
747 _state = State.EndOfLine;
748 }
749 else
750 {
751 _state = State.StartOfToken;
752 }
753 return result;
754 }
755 }
756
757 [Serializable]
758 public readonly struct TransitionTime : IEquatable<TransitionTime>, ISerializable, IDeserializationCallback
759 {
760 private readonly DateTime _timeOfDay;
761
762 private readonly byte _month;
763
764 private readonly byte _week;
765
766 private readonly byte _day;
767
768 private readonly DayOfWeek _dayOfWeek;
769
770 private readonly bool _isFixedDateRule;
771
773
774 public int Month => _month;
775
776 public int Week => _week;
777
778 public int Day => _day;
779
781
783
784 public override bool Equals([NotNullWhen(true)] object? obj)
785 {
787 {
788 return Equals((TransitionTime)obj);
789 }
790 return false;
791 }
792
794 {
795 return t1.Equals(t2);
796 }
797
799 {
800 return !t1.Equals(t2);
801 }
802
804 {
805 if (_isFixedDateRule == other._isFixedDateRule && _timeOfDay == other._timeOfDay && _month == other._month)
806 {
807 if (!other._isFixedDateRule)
808 {
809 if (_week == other._week)
810 {
811 return _dayOfWeek == other._dayOfWeek;
812 }
813 return false;
814 }
815 return _day == other._day;
816 }
817 return false;
818 }
819
820 public override int GetHashCode()
821 {
822 return _month ^ (_week << 8);
823 }
824
825 private TransitionTime(DateTime timeOfDay, int month, int week, int day, DayOfWeek dayOfWeek, bool isFixedDateRule)
826 {
827 ValidateTransitionTime(timeOfDay, month, week, day, dayOfWeek);
829 _month = (byte)month;
830 _week = (byte)week;
831 _day = (byte)day;
832 _dayOfWeek = dayOfWeek;
834 }
835
836 public static TransitionTime CreateFixedDateRule(DateTime timeOfDay, int month, int day)
837 {
838 return new TransitionTime(timeOfDay, month, 1, day, DayOfWeek.Sunday, isFixedDateRule: true);
839 }
840
841 public static TransitionTime CreateFloatingDateRule(DateTime timeOfDay, int month, int week, DayOfWeek dayOfWeek)
842 {
843 return new TransitionTime(timeOfDay, month, week, 1, dayOfWeek, isFixedDateRule: false);
844 }
845
846 private static void ValidateTransitionTime(DateTime timeOfDay, int month, int week, int day, DayOfWeek dayOfWeek)
847 {
848 if (timeOfDay.Kind != 0)
849 {
851 }
853 {
855 }
856 if (day < 1 || day > 31)
857 {
859 }
860 if (week < 1 || week > 5)
861 {
863 }
865 {
867 }
869 if (year != 1 || month2 != 1 || day2 != 1 || timeOfDay.Ticks % 10000 != 0L)
870 {
871 throw new ArgumentException(SR.Argument_DateTimeHasTicks, "timeOfDay");
872 }
873 }
874
876 {
877 if (this != default(TransitionTime))
878 {
879 try
880 {
882 }
884 {
886 }
887 }
888 }
889
891 {
892 if (info == null)
893 {
894 throw new ArgumentNullException("info");
895 }
896 info.AddValue("TimeOfDay", _timeOfDay);
897 info.AddValue("Month", _month);
898 info.AddValue("Week", _week);
899 info.AddValue("Day", _day);
900 info.AddValue("DayOfWeek", _dayOfWeek);
901 info.AddValue("IsFixedDateRule", _isFixedDateRule);
902 }
903
905 {
906 if (info == null)
907 {
908 throw new ArgumentNullException("info");
909 }
910 _timeOfDay = (DateTime)info.GetValue("TimeOfDay", typeof(DateTime));
911 _month = (byte)info.GetValue("Month", typeof(byte));
912 _week = (byte)info.GetValue("Week", typeof(byte));
913 _day = (byte)info.GetValue("Day", typeof(byte));
914 _dayOfWeek = (DayOfWeek)info.GetValue("DayOfWeek", typeof(DayOfWeek));
915 _isFixedDateRule = (bool)info.GetValue("IsFixedDateRule", typeof(bool));
916 }
917 }
918
919 private sealed class OffsetAndRule
920 {
921 public readonly int Year;
922
923 public readonly TimeSpan Offset;
924
925 public readonly AdjustmentRule Rule;
926
928 {
929 Year = year;
930 Offset = offset;
931 Rule = rule;
932 }
933 }
934
935 private readonly string _id;
936
937 private readonly string _displayName;
938
939 private readonly string _standardDisplayName;
940
941 private readonly string _daylightDisplayName;
942
943 private readonly TimeSpan _baseUtcOffset;
944
945 private readonly bool _supportsDaylightSavingTime;
946
948
950
951 private static readonly TimeZoneInfo s_utcTimeZone = CreateUtcTimeZone();
952
953 private static CachedData s_cachedData = new CachedData();
954
955 private static readonly DateTime s_maxDateOnly = new DateTime(9999, 12, 31);
956
957 private static readonly DateTime s_minDateOnly = new DateTime(1, 1, 2);
958
959 private static readonly TimeSpan MaxOffset = TimeSpan.FromHours(14.0);
960
961 private static readonly TimeSpan MinOffset = -MaxOffset;
962
963 public string Id => _id;
964
965 public bool HasIanaId { get; }
966
967 public string DisplayName => _displayName ?? string.Empty;
968
969 public string StandardName => _standardDisplayName ?? string.Empty;
970
971 public string DaylightName => _daylightDisplayName ?? string.Empty;
972
974
976
977 public static TimeZoneInfo Local => s_cachedData.Local;
978
980
1014
1016 {
1018 {
1020 }
1022 if (dateTime.Kind == DateTimeKind.Local)
1023 {
1026 }
1027 else if (dateTime.Kind == DateTimeKind.Utc)
1028 {
1031 }
1032 else
1033 {
1035 }
1036 bool flag = false;
1037 int? ruleIndex;
1040 {
1043 }
1044 if (!flag)
1045 {
1047 }
1048 TimeSpan[] array = new TimeSpan[2];
1051 {
1052 array[0] = timeSpan;
1054 }
1055 else
1056 {
1058 array[1] = timeSpan;
1059 }
1060 return array;
1061 }
1062
1072
1074 {
1075 if (ruleIndex.HasValue && 0 < ruleIndex.GetValueOrDefault() && ruleIndex.GetValueOrDefault() < _adjustmentRules.Length)
1076 {
1077 return _adjustmentRules[ruleIndex.GetValueOrDefault() - 1];
1078 }
1079 AdjustmentRule result = rule;
1080 for (int i = 1; i < _adjustmentRules.Length; i++)
1081 {
1082 if (rule == _adjustmentRules[i])
1083 {
1084 result = _adjustmentRules[i - 1];
1085 break;
1086 }
1087 }
1088 return result;
1089 }
1090
1092 {
1093 return GetUtcOffsetFromUtc(dateTimeOffset.UtcDateTime, this);
1094 }
1095
1097 {
1098 return GetUtcOffset(dateTime, TimeZoneInfoOptions.NoThrowOnInvalidTime, s_cachedData);
1099 }
1100
1102 {
1104 return cachedData.Local.GetUtcOffset(dateTime, flags, cachedData);
1105 }
1106
1108 {
1109 return GetUtcOffset(dateTime, flags, s_cachedData);
1110 }
1111
1113 {
1114 if (dateTime.Kind == DateTimeKind.Local)
1115 {
1116 if (cachedData.GetCorrespondingKind(this) != DateTimeKind.Local)
1117 {
1118 DateTime time = ConvertTime(dateTime, cachedData.Local, s_utcTimeZone, flags);
1119 return GetUtcOffsetFromUtc(time, this);
1120 }
1121 }
1122 else if (dateTime.Kind == DateTimeKind.Utc)
1123 {
1124 if (cachedData.GetCorrespondingKind(this) == DateTimeKind.Utc)
1125 {
1126 return _baseUtcOffset;
1127 }
1128 return GetUtcOffsetFromUtc(dateTime, this);
1129 }
1130 return GetUtcOffset(dateTime, this);
1131 }
1132
1134 {
1136 {
1137 return false;
1138 }
1140 }
1141
1143 {
1144 return IsAmbiguousTime(dateTime, TimeZoneInfoOptions.NoThrowOnInvalidTime);
1145 }
1146
1164
1170
1172 {
1173 return IsDaylightSavingTime(dateTime, TimeZoneInfoOptions.NoThrowOnInvalidTime, s_cachedData);
1174 }
1175
1180
1182 {
1184 {
1185 return false;
1186 }
1188 if (dateTime.Kind == DateTimeKind.Local)
1189 {
1190 dateTime2 = ConvertTime(dateTime, cachedData.Local, this, flags, cachedData);
1191 }
1192 else
1193 {
1194 if (dateTime.Kind == DateTimeKind.Utc)
1195 {
1196 if (cachedData.GetCorrespondingKind(this) == DateTimeKind.Utc)
1197 {
1198 return false;
1199 }
1201 return isDaylightSavings;
1202 }
1204 }
1205 int? ruleIndex;
1207 if (adjustmentRuleForTime != null && adjustmentRuleForTime.HasDaylightSaving)
1208 {
1211 }
1212 return false;
1213 }
1214
1216 {
1217 bool result = false;
1218 if (dateTime.Kind == DateTimeKind.Unspecified || (dateTime.Kind == DateTimeKind.Local && s_cachedData.GetCorrespondingKind(this) == DateTimeKind.Local))
1219 {
1220 int? ruleIndex;
1222 if (adjustmentRuleForTime != null && adjustmentRuleForTime.HasDaylightSaving)
1223 {
1226 }
1227 else
1228 {
1229 result = false;
1230 }
1231 }
1232 return result;
1233 }
1234
1235 public static void ClearCachedData()
1236 {
1237 s_cachedData = new CachedData();
1238 }
1239
1244
1249
1263
1265 {
1266 if (destinationTimeZone == null)
1267 {
1268 throw new ArgumentNullException("destinationTimeZone");
1269 }
1270 DateTime utcDateTime = dateTimeOffset.UtcDateTime;
1272 long num = utcDateTime.Ticks + utcOffsetFromUtc.Ticks;
1273 if (num <= DateTimeOffset.MaxValue.Ticks)
1274 {
1275 if (num >= DateTimeOffset.MinValue.Ticks)
1276 {
1277 return new DateTimeOffset(num, utcOffsetFromUtc);
1278 }
1279 return DateTimeOffset.MinValue;
1280 }
1281 return DateTimeOffset.MaxValue;
1282 }
1283
1285 {
1286 if (destinationTimeZone == null)
1287 {
1288 throw new ArgumentNullException("destinationTimeZone");
1289 }
1290 if (dateTime.Ticks == 0L)
1291 {
1293 }
1297 }
1298
1303
1308
1310 {
1311 if (sourceTimeZone == null)
1312 {
1313 throw new ArgumentNullException("sourceTimeZone");
1314 }
1315 if (destinationTimeZone == null)
1316 {
1317 throw new ArgumentNullException("destinationTimeZone");
1318 }
1320 if ((flags & TimeZoneInfoOptions.NoThrowOnInvalidTime) == 0 && dateTime.Kind != 0 && dateTime.Kind != correspondingKind)
1321 {
1322 throw new ArgumentException(SR.Argument_ConvertMismatch, "sourceTimeZone");
1323 }
1324 int? ruleIndex;
1326 TimeSpan baseUtcOffset = sourceTimeZone.BaseUtcOffset;
1327 if (adjustmentRuleForTime != null)
1328 {
1329 baseUtcOffset += adjustmentRuleForTime.BaseUtcOffsetDelta;
1330 if (adjustmentRuleForTime.HasDaylightSaving)
1331 {
1332 bool flag = false;
1334 if ((flags & TimeZoneInfoOptions.NoThrowOnInvalidTime) == 0 && GetIsInvalidTime(dateTime, adjustmentRuleForTime, daylightTime))
1335 {
1336 throw new ArgumentException(SR.Argument_DateTimeIsInvalid, "dateTime");
1337 }
1340 }
1341 }
1344 {
1345 return dateTime;
1346 }
1347 long ticks = dateTime.Ticks - baseUtcOffset.Ticks;
1350 if (correspondingKind2 == DateTimeKind.Local)
1351 {
1352 return new DateTime(dateTime2.Ticks, DateTimeKind.Local, isAmbiguousLocalDst);
1353 }
1354 return new DateTime(dateTime2.Ticks, correspondingKind2);
1355 }
1356
1361
1363 {
1364 if (dateTime.Kind == DateTimeKind.Utc)
1365 {
1366 return dateTime;
1367 }
1370 }
1371
1373 {
1374 if (dateTime.Kind == DateTimeKind.Utc)
1375 {
1376 return dateTime;
1377 }
1379 return ConvertTime(dateTime, cachedData.Local, s_utcTimeZone, flags, cachedData);
1380 }
1381
1386
1387 public bool Equals([NotNullWhen(true)] TimeZoneInfo? other)
1388 {
1389 if (other != null && string.Equals(_id, other._id, StringComparison.OrdinalIgnoreCase))
1390 {
1391 return HasSameRules(other);
1392 }
1393 return false;
1394 }
1395
1396 public override bool Equals([NotNullWhen(true)] object? obj)
1397 {
1398 return Equals(obj as TimeZoneInfo);
1399 }
1400
1402 {
1403 if (source == null)
1404 {
1405 throw new ArgumentNullException("source");
1406 }
1407 if (source.Length == 0)
1408 {
1410 }
1412 }
1413
1414 public override int GetHashCode()
1415 {
1416 return StringComparer.OrdinalIgnoreCase.GetHashCode(_id);
1417 }
1418
1420 {
1423 {
1424 if (cachedData._readOnlySystemTimeZones == null)
1425 {
1430 {
1431 int num = x.BaseUtcOffset.CompareTo(y.BaseUtcOffset);
1432 return (num != 0) ? num : string.CompareOrdinal(x.DisplayName, y.DisplayName);
1433 });
1435 }
1436 }
1437 return cachedData._readOnlySystemTimeZones;
1438 }
1439
1441 {
1442 if (other == null)
1443 {
1444 throw new ArgumentNullException("other");
1445 }
1446 if (_baseUtcOffset != other._baseUtcOffset || _supportsDaylightSavingTime != other._supportsDaylightSavingTime)
1447 {
1448 return false;
1449 }
1451 AdjustmentRule[] adjustmentRules2 = other._adjustmentRules;
1452 if (adjustmentRules == null || adjustmentRules2 == null)
1453 {
1455 }
1456 return adjustmentRules.AsSpan().SequenceEqual(adjustmentRules2);
1457 }
1458
1459 public string ToSerializedString()
1460 {
1462 }
1463
1464 public override string ToString()
1465 {
1466 return DisplayName;
1467 }
1468
1481
1488
1493
1504
1505 public static bool TryConvertIanaIdToWindowsId(string ianaId, [NotNullWhen(true)] out string? windowsId)
1506 {
1508 }
1509
1510 public static bool TryConvertWindowsIdToIanaId(string windowsId, [NotNullWhen(true)] out string? ianaId)
1511 {
1513 }
1514
1515 public static bool TryConvertWindowsIdToIanaId(string windowsId, string? region, [NotNullWhen(true)] out string? ianaId)
1516 {
1518 }
1519
1539
1541 {
1542 if (info == null)
1543 {
1544 throw new ArgumentNullException("info");
1545 }
1546 info.AddValue("Id", _id);
1547 info.AddValue("DisplayName", _displayName);
1548 info.AddValue("StandardName", _standardDisplayName);
1549 info.AddValue("DaylightName", _daylightDisplayName);
1550 info.AddValue("BaseUtcOffset", _baseUtcOffset);
1551 info.AddValue("AdjustmentRules", _adjustmentRules);
1552 info.AddValue("SupportsDaylightSavingTime", _supportsDaylightSavingTime);
1553 }
1554
1556 {
1557 if (info == null)
1558 {
1559 throw new ArgumentNullException("info");
1560 }
1561 _id = (string)info.GetValue("Id", typeof(string));
1562 _displayName = (string)info.GetValue("DisplayName", typeof(string));
1563 _standardDisplayName = (string)info.GetValue("StandardName", typeof(string));
1564 _daylightDisplayName = (string)info.GetValue("DaylightName", typeof(string));
1565 _baseUtcOffset = (TimeSpan)info.GetValue("BaseUtcOffset", typeof(TimeSpan));
1566 _adjustmentRules = (AdjustmentRule[])info.GetValue("AdjustmentRules", typeof(AdjustmentRule[]));
1567 _supportsDaylightSavingTime = (bool)info.GetValue("SupportsDaylightSavingTime", typeof(bool));
1568 }
1569
1574
1576 {
1577 if (_adjustmentRules == null || _adjustmentRules.Length == 0)
1578 {
1579 ruleIndex = null;
1580 return null;
1581 }
1583 int num = 0;
1584 int num2 = _adjustmentRules.Length - 1;
1585 while (num <= num2)
1586 {
1587 int num3 = num + (num2 - num >> 1);
1591 if (num4 == 0)
1592 {
1593 ruleIndex = num3;
1594 return adjustmentRule;
1595 }
1596 if (num4 < 0)
1597 {
1598 num = num3 + 1;
1599 }
1600 else
1601 {
1602 num2 = num3 - 1;
1603 }
1604 }
1605 ruleIndex = null;
1606 return null;
1607 }
1608
1610 {
1611 bool flag;
1612 if (rule.DateStart.Kind == DateTimeKind.Utc)
1613 {
1614 DateTime dateTime2 = (dateTimeisUtc ? dateTime : ConvertToUtc(dateTime, previousRule.DaylightDelta, previousRule.BaseUtcOffsetDelta));
1615 flag = dateTime2 >= rule.DateStart;
1616 }
1617 else
1618 {
1619 flag = dateOnly >= rule.DateStart;
1620 }
1621 if (!flag)
1622 {
1623 return 1;
1624 }
1625 bool flag2;
1626 if (rule.DateEnd.Kind == DateTimeKind.Utc)
1627 {
1628 DateTime dateTime3 = (dateTimeisUtc ? dateTime : ConvertToUtc(dateTime, rule.DaylightDelta, rule.BaseUtcOffsetDelta));
1629 flag2 = dateTime3 <= rule.DateEnd;
1630 }
1631 else
1632 {
1633 flag2 = dateOnly <= rule.DateEnd;
1634 }
1635 if (!flag2)
1636 {
1637 return -1;
1638 }
1639 return 0;
1640 }
1641
1646
1651
1653 {
1655 if (convertToUtc)
1656 {
1657 timeSpan = timeSpan.Negate();
1658 }
1659 long num = dateTime.Ticks + timeSpan.Ticks;
1660 if (num <= DateTime.MaxValue.Ticks)
1661 {
1662 if (num >= DateTime.MinValue.Ticks)
1663 {
1664 return new DateTime(num);
1665 }
1666 return DateTime.MinValue;
1667 }
1668 return DateTime.MaxValue;
1669 }
1670
1672 {
1673 DateTime time = ((ticks > DateTime.MaxValue.Ticks) ? DateTime.MaxValue : ((ticks < DateTime.MinValue.Ticks) ? DateTime.MinValue : new DateTime(ticks)));
1675 if (ticks <= DateTime.MaxValue.Ticks)
1676 {
1677 if (ticks >= DateTime.MinValue.Ticks)
1678 {
1679 return new DateTime(ticks);
1680 }
1681 return DateTime.MinValue;
1682 }
1683 return DateTime.MaxValue;
1684 }
1685
1687 {
1688 TimeSpan daylightDelta = rule.DaylightDelta;
1690 DateTime end;
1691 if (rule.NoDaylightTransitions)
1692 {
1694 start = ConvertFromUtc(rule.DateStart, previousAdjustmentRule.DaylightDelta, previousAdjustmentRule.BaseUtcOffsetDelta);
1695 end = ConvertFromUtc(rule.DateEnd, rule.DaylightDelta, rule.BaseUtcOffsetDelta);
1696 }
1697 else
1698 {
1699 start = TransitionTimeToDateTime(year, rule.DaylightTransitionStart);
1700 end = TransitionTimeToDateTime(year, rule.DaylightTransitionEnd);
1701 }
1702 return new DaylightTimeStruct(start, end, daylightDelta);
1703 }
1704
1706 {
1707 if (rule == null)
1708 {
1709 return false;
1710 }
1713 if (time.Kind == DateTimeKind.Local)
1714 {
1715 startTime = (rule.IsStartDateMarkerForBeginningOfYear() ? new DateTime(daylightTime.Start.Year, 1, 1, 0, 0, 0) : (daylightTime.Start + daylightTime.Delta));
1716 endTime = (rule.IsEndDateMarkerForEndOfYear() ? new DateTime(daylightTime.End.Year + 1, 1, 1, 0, 0, 0).AddTicks(-1L) : daylightTime.End);
1717 }
1718 else
1719 {
1720 bool flag = rule.DaylightDelta > TimeSpan.Zero;
1721 startTime = (rule.IsStartDateMarkerForBeginningOfYear() ? new DateTime(daylightTime.Start.Year, 1, 1, 0, 0, 0) : (daylightTime.Start + (flag ? rule.DaylightDelta : TimeSpan.Zero)));
1722 endTime = (rule.IsEndDateMarkerForEndOfYear() ? new DateTime(daylightTime.End.Year + 1, 1, 1, 0, 0, 0).AddTicks(-1L) : (daylightTime.End + (flag ? (-rule.DaylightDelta) : TimeSpan.Zero)));
1723 }
1725 if (flag2 && time.Kind == DateTimeKind.Local && GetIsAmbiguousTime(time, rule, daylightTime))
1726 {
1728 }
1729 return flag2;
1730 }
1731
1741
1746
1748 {
1749 isAmbiguousLocalDst = false;
1750 if (rule == null)
1751 {
1752 return false;
1753 }
1755 bool ignoreYearAdjustment = false;
1756 TimeSpan daylightSavingsStartOffsetFromUtc = zone.GetDaylightSavingsStartOffsetFromUtc(utc, rule, ruleIndex);
1758 if (rule.IsStartDateMarkerForBeginningOfYear() && daylightTime.Start.Year > DateTime.MinValue.Year)
1759 {
1760 int? ruleIndex2;
1761 AdjustmentRule adjustmentRuleForTime = zone.GetAdjustmentRuleForTime(new DateTime(daylightTime.Start.Year - 1, 12, 31), out ruleIndex2);
1762 if (adjustmentRuleForTime != null && adjustmentRuleForTime.IsEndDateMarkerForEndOfYear())
1763 {
1764 dateTime = zone.GetDaylightTime(daylightTime.Start.Year - 1, adjustmentRuleForTime, ruleIndex2).Start - utc - adjustmentRuleForTime.BaseUtcOffsetDelta;
1765 ignoreYearAdjustment = true;
1766 }
1767 else
1768 {
1769 dateTime = new DateTime(daylightTime.Start.Year, 1, 1, 0, 0, 0) - daylightSavingsStartOffsetFromUtc;
1770 }
1771 }
1772 else
1773 {
1775 }
1778 if (rule.IsEndDateMarkerForEndOfYear() && daylightTime.End.Year < DateTime.MaxValue.Year)
1779 {
1780 int? ruleIndex3;
1781 AdjustmentRule adjustmentRuleForTime2 = zone.GetAdjustmentRuleForTime(new DateTime(daylightTime.End.Year + 1, 1, 1), out ruleIndex3);
1782 if (adjustmentRuleForTime2 != null && adjustmentRuleForTime2.IsStartDateMarkerForBeginningOfYear())
1783 {
1784 dateTime2 = ((!adjustmentRuleForTime2.IsEndDateMarkerForEndOfYear()) ? (zone.GetDaylightTime(daylightTime.End.Year + 1, adjustmentRuleForTime2, ruleIndex3).End - utc - adjustmentRuleForTime2.BaseUtcOffsetDelta - adjustmentRuleForTime2.DaylightDelta) : (new DateTime(daylightTime.End.Year + 1, 12, 31) - utc - adjustmentRuleForTime2.BaseUtcOffsetDelta - adjustmentRuleForTime2.DaylightDelta));
1785 ignoreYearAdjustment = true;
1786 }
1787 else
1788 {
1789 dateTime2 = new DateTime(daylightTime.End.Year + 1, 1, 1, 0, 0, 0).AddTicks(-1L) - daylightSavingsEndOffsetFromUtc;
1790 }
1791 }
1792 else
1793 {
1795 }
1798 if (daylightTime.Delta.Ticks > 0)
1799 {
1802 }
1803 else
1804 {
1807 }
1809 if (flag)
1810 {
1811 isAmbiguousLocalDst = time >= dateTime3 && time < dateTime4;
1812 if (!isAmbiguousLocalDst && dateTime3.Year != dateTime4.Year)
1813 {
1814 try
1815 {
1816 DateTime dateTime5 = dateTime3.AddYears(1);
1817 DateTime dateTime6 = dateTime4.AddYears(1);
1818 isAmbiguousLocalDst = time >= dateTime5 && time < dateTime6;
1819 }
1821 {
1822 }
1824 {
1825 try
1826 {
1827 DateTime dateTime5 = dateTime3.AddYears(-1);
1828 DateTime dateTime6 = dateTime4.AddYears(-1);
1829 isAmbiguousLocalDst = time >= dateTime5 && time < dateTime6;
1830 }
1832 {
1833 }
1834 }
1835 }
1836 }
1837 return flag;
1838 }
1839
1841 {
1842 if (!ignoreYearAdjustment && !rule.NoDaylightTransitions)
1843 {
1844 int year = startTime.Year;
1845 int year2 = endTime.Year;
1846 if (year != year2)
1847 {
1848 endTime = endTime.AddYears(year - year2);
1849 }
1850 int year3 = time.Year;
1851 if (year != year3)
1852 {
1853 time = time.AddYears(year - year3);
1854 }
1855 }
1856 if (startTime > endTime)
1857 {
1858 if (!(time < endTime))
1859 {
1860 return time >= startTime;
1861 }
1862 return true;
1863 }
1864 if (rule.NoDaylightTransitions)
1865 {
1866 if (time >= startTime)
1867 {
1868 return time <= endTime;
1869 }
1870 return false;
1871 }
1872 if (time >= startTime)
1873 {
1874 return time < endTime;
1875 }
1876 return false;
1877 }
1878
1880 {
1881 bool result = false;
1882 if (rule == null || rule.DaylightDelta == TimeSpan.Zero)
1883 {
1884 return result;
1885 }
1888 if (rule.DaylightDelta > TimeSpan.Zero)
1889 {
1890 if (rule.IsEndDateMarkerForEndOfYear())
1891 {
1892 return false;
1893 }
1894 dateTime = daylightTime.End;
1895 dateTime2 = daylightTime.End - rule.DaylightDelta;
1896 }
1897 else
1898 {
1899 if (rule.IsStartDateMarkerForBeginningOfYear())
1900 {
1901 return false;
1902 }
1903 dateTime = daylightTime.Start;
1904 dateTime2 = daylightTime.Start + rule.DaylightDelta;
1905 }
1906 result = time >= dateTime2 && time < dateTime;
1907 if (!result && dateTime.Year != dateTime2.Year)
1908 {
1909 try
1910 {
1911 DateTime dateTime3 = dateTime.AddYears(1);
1912 DateTime dateTime4 = dateTime2.AddYears(1);
1913 result = time >= dateTime4 && time < dateTime3;
1914 }
1916 {
1917 }
1918 if (!result)
1919 {
1920 try
1921 {
1922 DateTime dateTime3 = dateTime.AddYears(-1);
1923 DateTime dateTime4 = dateTime2.AddYears(-1);
1924 result = time >= dateTime4 && time < dateTime3;
1925 }
1927 {
1928 }
1929 }
1930 }
1931 return result;
1932 }
1933
1935 {
1936 bool result = false;
1937 if (rule == null || rule.DaylightDelta == TimeSpan.Zero)
1938 {
1939 return result;
1940 }
1943 if (rule.DaylightDelta < TimeSpan.Zero)
1944 {
1945 if (rule.IsEndDateMarkerForEndOfYear())
1946 {
1947 return false;
1948 }
1949 dateTime = daylightTime.End;
1950 dateTime2 = daylightTime.End - rule.DaylightDelta;
1951 }
1952 else
1953 {
1954 if (rule.IsStartDateMarkerForBeginningOfYear())
1955 {
1956 return false;
1957 }
1958 dateTime = daylightTime.Start;
1959 dateTime2 = daylightTime.Start + rule.DaylightDelta;
1960 }
1961 result = time >= dateTime && time < dateTime2;
1962 if (!result && dateTime.Year != dateTime2.Year)
1963 {
1964 try
1965 {
1966 DateTime dateTime3 = dateTime.AddYears(1);
1967 DateTime dateTime4 = dateTime2.AddYears(1);
1968 result = time >= dateTime3 && time < dateTime4;
1969 }
1971 {
1972 }
1973 if (!result)
1974 {
1975 try
1976 {
1977 DateTime dateTime3 = dateTime.AddYears(-1);
1978 DateTime dateTime4 = dateTime2.AddYears(-1);
1979 result = time >= dateTime3 && time < dateTime4;
1980 }
1982 {
1983 }
1984 }
1985 }
1986 return result;
1987 }
1988
1990 {
1991 TimeSpan baseUtcOffset = zone.BaseUtcOffset;
1992 int? ruleIndex;
1993 AdjustmentRule adjustmentRuleForTime = zone.GetAdjustmentRuleForTime(time, out ruleIndex);
1994 if (adjustmentRuleForTime != null)
1995 {
1996 baseUtcOffset += adjustmentRuleForTime.BaseUtcOffsetDelta;
1997 if (adjustmentRuleForTime.HasDaylightSaving)
1998 {
2002 }
2003 }
2004 return baseUtcOffset;
2005 }
2006
2008 {
2009 bool isDaylightSavings;
2011 }
2012
2018
2020 {
2021 isDaylightSavings = false;
2022 isAmbiguousLocalDst = false;
2023 TimeSpan baseUtcOffset = zone.BaseUtcOffset;
2025 int? ruleIndex;
2026 int year;
2027 if (time > s_maxDateOnly)
2028 {
2029 adjustmentRuleForTime = zone.GetAdjustmentRuleForTime(DateTime.MaxValue, out ruleIndex);
2030 year = 9999;
2031 }
2032 else if (time < s_minDateOnly)
2033 {
2034 adjustmentRuleForTime = zone.GetAdjustmentRuleForTime(DateTime.MinValue, out ruleIndex);
2035 year = 1;
2036 }
2037 else
2038 {
2039 adjustmentRuleForTime = zone.GetAdjustmentRuleForTime(time, dateTimeisUtc: true, out ruleIndex);
2040 year = (time + baseUtcOffset).Year;
2041 }
2042 if (adjustmentRuleForTime != null)
2043 {
2044 baseUtcOffset += adjustmentRuleForTime.BaseUtcOffsetDelta;
2045 if (adjustmentRuleForTime.HasDaylightSaving)
2046 {
2049 }
2050 }
2051 return baseUtcOffset;
2052 }
2053
2055 {
2056 TimeSpan timeOfDay = transitionTime.TimeOfDay.TimeOfDay;
2057 DateTime result;
2058 if (transitionTime.IsFixedDateRule)
2059 {
2060 int num = transitionTime.Day;
2061 if (num > 28)
2062 {
2064 if (num > num2)
2065 {
2066 num = num2;
2067 }
2068 }
2069 result = new DateTime(year, transitionTime.Month, num) + timeOfDay;
2070 }
2071 else if (transitionTime.Week <= 4)
2072 {
2073 result = new DateTime(year, transitionTime.Month, 1) + timeOfDay;
2074 int dayOfWeek = (int)result.DayOfWeek;
2075 int num3 = (int)(transitionTime.DayOfWeek - dayOfWeek);
2076 if (num3 < 0)
2077 {
2078 num3 += 7;
2079 }
2080 num3 += 7 * (transitionTime.Week - 1);
2081 if (num3 > 0)
2082 {
2083 result = result.AddDays(num3);
2084 }
2085 }
2086 else
2087 {
2088 int day = DateTime.DaysInMonth(year, transitionTime.Month);
2089 result = new DateTime(year, transitionTime.Month, day) + timeOfDay;
2090 int dayOfWeek2 = (int)result.DayOfWeek;
2091 int num4 = (int)(dayOfWeek2 - transitionTime.DayOfWeek);
2092 if (num4 < 0)
2093 {
2094 num4 += 7;
2095 }
2096 if (num4 > 0)
2097 {
2098 result = result.AddDays(-num4);
2099 }
2100 }
2101 return result;
2102 }
2103
2105 {
2107 if (timeZoneInfoResult != 0)
2108 {
2109 bool idIsIana;
2111 if (alternativeId != null)
2112 {
2115 {
2117 if (value._equivalentZones == null)
2118 {
2119 timeZoneInfo = new TimeZoneInfo(id, value._baseUtcOffset, value._displayName, value._standardDisplayName, value._daylightDisplayName, value._adjustmentRules, dstDisabled && value._supportsDaylightSavingTime, idIsIana);
2121 lock (value._equivalentZones)
2122 {
2123 value._equivalentZones.Add(timeZoneInfo);
2124 }
2125 }
2126 else
2127 {
2128 foreach (TimeZoneInfo equivalentZone in value._equivalentZones)
2129 {
2130 if (equivalentZone.Id == id)
2131 {
2133 break;
2134 }
2135 }
2136 if (timeZoneInfo == null)
2137 {
2138 timeZoneInfo = new TimeZoneInfo(id, value._baseUtcOffset, value._displayName, value._standardDisplayName, value._daylightDisplayName, value._adjustmentRules, dstDisabled && value._supportsDaylightSavingTime, idIsIana);
2139 lock (value._equivalentZones)
2140 {
2141 value._equivalentZones.Add(timeZoneInfo);
2142 }
2143 }
2144 }
2146 }
2147 }
2148 }
2149 return timeZoneInfoResult;
2150 }
2151
2153 {
2154 TimeZoneInfoResult result = TimeZoneInfoResult.Success;
2155 e = null;
2156 if (cachedData._systemTimeZones != null && cachedData._systemTimeZones.TryGetValue(id, out var value2))
2157 {
2158 if (dstDisabled && value2._supportsDaylightSavingTime)
2159 {
2160 value = CreateCustomTimeZone(value2._id, value2._baseUtcOffset, value2._displayName, value2._standardDisplayName);
2161 }
2162 else
2163 {
2164 value = new TimeZoneInfo(value2._id, value2._baseUtcOffset, value2._displayName, value2._standardDisplayName, value2._daylightDisplayName, value2._adjustmentRules, disableDaylightSavingTime: false, value2.HasIanaId);
2165 }
2166 return result;
2167 }
2168 if (!cachedData._allSystemTimeZonesRead || alwaysFallbackToLocalMachine)
2169 {
2171 }
2172 else
2173 {
2174 result = TimeZoneInfoResult.TimeZoneNotFoundException;
2175 value = null;
2176 }
2177 return result;
2178 }
2179
2181 {
2185 {
2186 if (cachedData._systemTimeZones == null)
2187 {
2189 }
2190 if (!id.Equals("UTC", StringComparison.OrdinalIgnoreCase))
2191 {
2192 cachedData._systemTimeZones.Add(id, value2);
2193 }
2194 if (dstDisabled && value2._supportsDaylightSavingTime)
2195 {
2196 value = CreateCustomTimeZone(value2._id, value2._baseUtcOffset, value2._displayName, value2._standardDisplayName);
2197 }
2198 else
2199 {
2200 value = new TimeZoneInfo(value2._id, value2._baseUtcOffset, value2._displayName, value2._standardDisplayName, value2._daylightDisplayName, value2._adjustmentRules, disableDaylightSavingTime: false, value2.HasIanaId);
2201 }
2202 }
2203 else
2204 {
2205 value = null;
2206 }
2207 return timeZoneInfoResult;
2208 }
2209
2211 {
2212 if (id == null)
2213 {
2214 throw new ArgumentNullException("id");
2215 }
2216 if (id.Length == 0)
2217 {
2218 throw new ArgumentException(SR.Format(SR.Argument_InvalidId, id), "id");
2219 }
2221 {
2223 }
2224 if (baseUtcOffset.Ticks % 600000000 != 0L)
2225 {
2226 throw new ArgumentException(SR.Argument_TimeSpanHasSeconds, "baseUtcOffset");
2227 }
2229 if (adjustmentRules == null || adjustmentRules.Length == 0)
2230 {
2231 return;
2232 }
2236 for (int i = 0; i < adjustmentRules.Length; i++)
2237 {
2240 if (adjustmentRule2 == null)
2241 {
2243 }
2245 {
2247 }
2248 if (adjustmentRule != null && adjustmentRule2.DateStart <= adjustmentRule.DateEnd)
2249 {
2251 }
2252 }
2253 }
2254
2256 {
2257 if (!(offset < MinOffset))
2258 {
2259 return offset > MaxOffset;
2260 }
2261 return true;
2262 }
2263
2268
2274
2281
2282 private unsafe static bool TryConvertIanaIdToWindowsId(string ianaId, bool allocate, out string windowsId)
2283 {
2285 {
2286 windowsId = null;
2287 return false;
2288 }
2289 foreach (char c in ianaId)
2290 {
2291 if (c == '\\' || c == '\n' || c == '\r')
2292 {
2293 windowsId = null;
2294 return false;
2295 }
2296 }
2297 char* ptr = stackalloc char[100];
2299 if (num > 0)
2300 {
2301 windowsId = (allocate ? new string(ptr, 0, num) : null);
2302 return true;
2303 }
2304 windowsId = null;
2305 return false;
2306 }
2307
2308 private unsafe static bool TryConvertWindowsIdToIanaId(string windowsId, string region, bool allocate, out string ianaId)
2309 {
2311 {
2312 ianaId = null;
2313 return false;
2314 }
2315 if (windowsId.Equals("utc", StringComparison.OrdinalIgnoreCase))
2316 {
2317 ianaId = "Etc/UTC";
2318 return true;
2319 }
2320 foreach (char c in windowsId)
2321 {
2322 if (c == '\\' || c == '\n' || c == '\r')
2323 {
2324 ianaId = null;
2325 return false;
2326 }
2327 }
2329 if (region != null && region.Length < 11)
2330 {
2331 byte* ptr = stackalloc byte[(int)(uint)(region.Length + 1)];
2332 int j;
2333 for (j = 0; j < region.Length && region[j] <= '\u007f'; j++)
2334 {
2335 ptr[j] = (((uint)(region[j] - 97) <= 25u) ? ((byte)(region[j] - 97 + 65)) : ((byte)region[j]));
2336 }
2337 if (j >= region.Length)
2338 {
2339 ptr[region.Length] = 0;
2340 region2 = new IntPtr(ptr);
2341 }
2342 }
2343 char* ptr2 = stackalloc char[100];
2345 if (num > 0)
2346 {
2347 ianaId = (allocate ? new string(ptr2, 0, num) : null);
2348 return true;
2349 }
2350 ianaId = null;
2351 return false;
2352 }
2353
2355 {
2356 if (_adjustmentRules == null)
2357 {
2358 return Array.Empty<AdjustmentRule>();
2359 }
2360 return (AdjustmentRule[])_adjustmentRules.Clone();
2361 }
2362
2364 {
2365 using RegistryKey registryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones", writable: false);
2366 if (registryKey != null)
2367 {
2368 string[] subKeyNames = registryKey.GetSubKeyNames();
2369 foreach (string id in subKeyNames)
2370 {
2372 }
2373 }
2374 }
2375
2376 private static string GetAlternativeId(string id, out bool idIsIana)
2377 {
2378 idIsIana = true;
2379 if (!TryConvertIanaIdToWindowsId(id, out string windowsId))
2380 {
2381 return null;
2382 }
2383 return windowsId;
2384 }
2385
2412
2414 {
2415 return timeZone.DaylightDate.Equals(in timeZone.StandardDate);
2416 }
2417
2442
2444 {
2445 dstDisabled = false;
2446 using (RegistryKey registryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones", writable: false))
2447 {
2448 if (registryKey == null)
2449 {
2450 return null;
2451 }
2452 string[] subKeyNames = registryKey.GetSubKeyNames();
2453 foreach (string text in subKeyNames)
2454 {
2456 {
2457 return text;
2458 }
2459 }
2460 }
2461 return null;
2462 }
2463
2486
2488 {
2489 try
2490 {
2492 }
2493 catch (ArgumentException)
2494 {
2495 }
2497 {
2498 }
2499 if (!dstDisabled)
2500 {
2501 try
2502 {
2504 }
2505 catch (ArgumentException)
2506 {
2507 }
2509 {
2510 }
2511 }
2512 return CreateCustomTimeZone("Local", TimeSpan.Zero, "Local", "Local");
2513 }
2514
2515 public static TimeZoneInfo FindSystemTimeZoneById(string id)
2516 {
2517 if (string.Equals(id, "UTC", StringComparison.OrdinalIgnoreCase))
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 {
2528 }
2532 Exception e;
2534 {
2536 }
2537 return timeZoneInfoResult switch
2538 {
2543 };
2544 }
2545
2547 {
2548 isAmbiguousLocalDst = false;
2549 int year = time.Year;
2550 OffsetAndRule oneYearLocalFromUtc = s_cachedData.GetOneYearLocalFromUtc(year);
2552 if (oneYearLocalFromUtc.Rule != null)
2553 {
2554 offset += oneYearLocalFromUtc.Rule.BaseUtcOffsetDelta;
2555 if (oneYearLocalFromUtc.Rule.HasDaylightSaving)
2556 {
2559 }
2560 }
2561 return offset;
2562 }
2563
2565 {
2566 if (timeZoneInformation.StandardDate.Month == 0)
2567 {
2568 transitionTime = default(TransitionTime);
2569 return false;
2570 }
2571 if (readStartDate)
2572 {
2573 if (timeZoneInformation.DaylightDate.Year == 0)
2574 {
2575 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);
2576 }
2577 else
2578 {
2579 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);
2580 }
2581 }
2582 else if (timeZoneInformation.StandardDate.Year == 0)
2583 {
2584 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);
2585 }
2586 else
2587 {
2588 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);
2589 }
2590 return true;
2591 }
2592
2594 {
2595 rules = null;
2596 e = null;
2597 try
2598 {
2599 using RegistryKey registryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones\\" + id + "\\Dynamic DST", writable: false);
2600 if (registryKey == null)
2601 {
2603 if (adjustmentRule != null)
2604 {
2605 rules = new AdjustmentRule[1] { adjustmentRule };
2606 }
2607 return true;
2608 }
2609 int num = (int)registryKey.GetValue("FirstEntry", -1);
2610 int num2 = (int)registryKey.GetValue("LastEntry", -1);
2611 if (num == -1 || num2 == -1 || num > num2)
2612 {
2613 return false;
2614 }
2616 {
2617 return false;
2618 }
2619 if (num == num2)
2620 {
2622 if (adjustmentRule2 != null)
2623 {
2625 }
2626 return true;
2627 }
2630 if (adjustmentRule3 != null)
2631 {
2632 list.Add(adjustmentRule3);
2633 }
2634 for (int i = num + 1; i < num2; i++)
2635 {
2637 {
2638 return false;
2639 }
2641 if (adjustmentRule4 != null)
2642 {
2643 list.Add(adjustmentRule4);
2644 }
2645 }
2647 {
2648 return false;
2649 }
2651 if (adjustmentRule5 != null)
2652 {
2653 list.Add(adjustmentRule5);
2654 }
2655 if (list.Count != 0)
2656 {
2657 rules = list.ToArray();
2658 }
2659 }
2660 catch (InvalidCastException ex)
2661 {
2662 e = ex;
2663 return false;
2664 }
2666 {
2667 e = ex2;
2668 return false;
2669 }
2670 catch (ArgumentException ex3)
2671 {
2672 e = ex3;
2673 return false;
2674 }
2675 return true;
2676 }
2677
2679 {
2680 if (!(key.GetValue(name, null) is byte[] array) || array.Length != sizeof(Interop.Kernel32.REG_TZI_FORMAT))
2681 {
2683 return false;
2684 }
2685 fixed (byte* ptr = &array[0])
2686 {
2688 }
2689 return true;
2690 }
2691
2693 {
2694 if (timeZone.Bias == registryTimeZoneInfo.Bias && timeZone.StandardBias == registryTimeZoneInfo.StandardBias)
2695 {
2696 return timeZone.StandardDate.Equals(in registryTimeZoneInfo.StandardDate);
2697 }
2698 return false;
2699 }
2700
2702 {
2703 dstDisabled = false;
2704 using RegistryKey registryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones\\" + id, writable: false);
2705 if (registryKey == null)
2706 {
2707 return false;
2708 }
2710 {
2711 return false;
2712 }
2714 {
2715 return false;
2716 }
2717 bool flag = dstDisabled || CheckDaylightSavingTimeNotSupported(in timeZone) || (timeZone.DaylightBias == dtzi.DaylightBias && timeZone.DaylightDate.Equals(in dtzi.DaylightDate));
2718 if (flag)
2719 {
2720 string a = registryKey.GetValue("Std", string.Empty) as string;
2721 flag = string.Equals(a, timeZone.GetStandardName(), StringComparison.Ordinal);
2722 }
2723 return flag;
2724 }
2725
2726 private static string GetLocalizedNameByMuiNativeResource(string resource)
2727 {
2729 {
2730 return string.Empty;
2731 }
2732 string[] array = resource.Split(',');
2733 if (array.Length != 2)
2734 {
2735 return string.Empty;
2736 }
2737 if (!int.TryParse(array[1], NumberStyles.Integer, CultureInfo.InvariantCulture, out var result))
2738 {
2739 return string.Empty;
2740 }
2741 result = -result;
2744 string path = $"{array[0].AsSpan().TrimStart('@')}.mui";
2745 try
2746 {
2747 while (cultureInfo.Name.Length != 0)
2748 {
2749 string text = Path.Join(systemDirectory, cultureInfo.Name, path);
2750 if (File.Exists(text))
2751 {
2752 return GetLocalizedNameByNativeResource(text, result);
2753 }
2754 cultureInfo = cultureInfo.Parent;
2755 }
2756 }
2757 catch (ArgumentException)
2758 {
2759 }
2760 return string.Empty;
2761 }
2762
2763 private unsafe static string GetLocalizedNameByNativeResource(string filePath, int resource)
2764 {
2766 try
2767 {
2769 if (intPtr != IntPtr.Zero)
2770 {
2771 char* ptr = stackalloc char[500];
2772 int num = Interop.User32.LoadString(intPtr, (uint)resource, ptr, 500);
2773 if (num != 0)
2774 {
2775 return new string(ptr, 0, num);
2776 }
2777 }
2778 }
2779 finally
2780 {
2781 if (intPtr != IntPtr.Zero)
2782 {
2784 }
2785 }
2786 return string.Empty;
2787 }
2788
2790 {
2791 displayName = string.Empty;
2792 standardName = string.Empty;
2793 daylightName = string.Empty;
2794 string text = key.GetValue("MUI_Display", string.Empty) as string;
2795 string text2 = key.GetValue("MUI_Std", string.Empty) as string;
2796 string text3 = key.GetValue("MUI_Dlt", string.Empty) as string;
2797 if (!string.IsNullOrEmpty(text))
2798 {
2800 }
2801 if (!string.IsNullOrEmpty(text2))
2802 {
2804 }
2805 if (!string.IsNullOrEmpty(text3))
2806 {
2808 }
2809 if (string.IsNullOrEmpty(displayName))
2810 {
2811 displayName = key.GetValue("Display", string.Empty) as string;
2812 }
2813 if (string.IsNullOrEmpty(standardName))
2814 {
2815 standardName = key.GetValue("Std", string.Empty) as string;
2816 }
2817 if (string.IsNullOrEmpty(daylightName))
2818 {
2819 daylightName = key.GetValue("Dlt", string.Empty) as string;
2820 }
2821 }
2822
2824 {
2825 e = null;
2826 using RegistryKey registryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones\\" + id, writable: false);
2827 if (registryKey == null)
2828 {
2829 value = null;
2830 return TimeZoneInfoResult.TimeZoneNotFoundException;
2831 }
2833 {
2834 value = null;
2835 return TimeZoneInfoResult.InvalidTimeZoneException;
2836 }
2837 if (!TryCreateAdjustmentRules(id, in dtzi, out var rules, out e, dtzi.Bias))
2838 {
2839 value = null;
2840 return TimeZoneInfoResult.InvalidTimeZoneException;
2841 }
2843 try
2844 {
2846 return TimeZoneInfoResult.Success;
2847 }
2848 catch (ArgumentException ex)
2849 {
2850 value = null;
2851 e = ex;
2852 return TimeZoneInfoResult.InvalidTimeZoneException;
2853 }
2855 {
2856 value = null;
2857 e = ex2;
2858 return TimeZoneInfoResult.InvalidTimeZoneException;
2859 }
2860 }
2861
2862 private static string GetUtcStandardDisplayName()
2863 {
2865 if (currentUICulture.Name.Length == 0 || currentUICulture.TwoLetterISOLanguageName == "en")
2866 {
2867 return "Coordinated Universal Time";
2868 }
2869 string text = null;
2870 using (RegistryKey registryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones\\UTC", writable: false))
2871 {
2872 if (registryKey != null)
2873 {
2874 string text2 = registryKey.GetValue("MUI_Std", string.Empty) as string;
2875 if (!string.IsNullOrEmpty(text2))
2876 {
2878 }
2879 if (string.IsNullOrEmpty(text))
2880 {
2881 text = registryKey.GetValue("Std", string.Empty) as string;
2882 }
2883 }
2884 }
2885 switch (text)
2886 {
2887 case null:
2888 case "GMT":
2889 case "UTC":
2890 text = "Coordinated Universal Time";
2891 break;
2892 }
2893 return text;
2894 }
2895
2896 private static string GetUtcFullDisplayName(string timeZoneId, string standardDisplayName)
2897 {
2898 return "(UTC) " + standardDisplayName;
2899 }
2900}
static readonly RegistryKey LocalMachine
Definition Registry.cs:9
static unsafe int IanaIdToWindowsId(string ianaId, char *windowsId, int windowsIdLength)
static unsafe int WindowsIdToIanaId(string windowsId, IntPtr region, char *ianaId, int ianaIdLength)
static bool FreeLibrary(IntPtr hModule)
static IntPtr LoadLibraryEx(string libFilename, IntPtr reserved, int flags)
static uint GetTimeZoneInformation(out TIME_ZONE_INFORMATION lpTimeZoneInformation)
static uint GetDynamicTimeZoneInformation(out TIME_DYNAMIC_ZONE_INFORMATION pTimeZoneInformation)
static unsafe int LoadString(IntPtr hInstance, uint uID, char *lpBuffer, int cchBufferMax)
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
void Add(TKey key, TValue value)
static string SystemDirectory
static CultureInfo CurrentUICulture
static CultureInfo InvariantCulture
static bool Exists([NotNullWhen(true)] string? path)
Definition File.cs:97
static string Join(ReadOnlySpan< char > path1, ReadOnlySpan< char > path2)
Definition Path.cs:387
static string Serialization_InvalidData
Definition SR.cs:1880
static string Argument_OutOfOrderDateTimes
Definition SR.cs:838
static string Argument_DateTimeHasTimeOfDay
Definition SR.cs:560
static string ArgumentOutOfRange_UtcOffsetAndDaylightDelta
Definition SR.cs:1122
static string Argument_InvalidId
Definition SR.cs:698
static string TimeZoneNotFound_MissingData
Definition SR.cs:2008
static string Argument_DateTimeOffsetIsNotAmbiguous
Definition SR.cs:572
static string ArgumentOutOfRange_DayParam
Definition SR.cs:1002
static string ArgumentOutOfRange_DayOfWeek
Definition SR.cs:1000
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string Argument_DateTimeHasTicks
Definition SR.cs:558
static string Argument_TransitionTimesAreIdentical
Definition SR.cs:890
static string Argument_InvalidSerializedString
Definition SR.cs:738
static string Argument_DateTimeIsNotAmbiguous
Definition SR.cs:564
static string ArgumentOutOfRange_UtcOffset
Definition SR.cs:1120
static string Argument_DateTimeKindMustBeUnspecifiedOrUtc
Definition SR.cs:568
static string Argument_AdjustmentRulesNoNulls
Definition SR.cs:462
static string ArgumentOutOfRange_Week
Definition SR.cs:1126
static string InvalidTimeZone_InvalidRegistryData
Definition SR.cs:1536
static string Argument_DateTimeIsInvalid
Definition SR.cs:562
static string Serialization_CorruptField
Definition SR.cs:1872
static string Security_CannotReadRegistryData
Definition SR.cs:1856
static string Argument_AdjustmentRulesOutOfOrder
Definition SR.cs:464
static string Argument_ConvertMismatch
Definition SR.cs:540
static string Argument_TimeSpanHasSeconds
Definition SR.cs:884
static string Serialization_InvalidEscapeSequence
Definition SR.cs:1882
static string ArgumentOutOfRange_MonthParam
Definition SR.cs:1062
static string Argument_DateTimeKindMustBeUnspecified
Definition SR.cs:566
Definition SR.cs:7
static StringComparer OrdinalIgnoreCase
static AdjustmentRule CreateAdjustmentRule(DateTime dateStart, DateTime dateEnd, TimeSpan daylightDelta, TransitionTime daylightTransitionStart, TransitionTime daylightTransitionEnd, TimeSpan baseUtcOffsetDelta, bool noDaylightTransitions)
readonly TransitionTime _daylightTransitionEnd
bool Equals([NotNullWhen(true)] AdjustmentRule? other)
readonly TimeSpan _baseUtcOffsetDelta
static readonly TimeSpan DaylightDeltaAdjustment
static void ValidateAdjustmentRule(DateTime dateStart, DateTime dateEnd, TimeSpan daylightDelta, TransitionTime daylightTransitionStart, TransitionTime daylightTransitionEnd, bool noDaylightTransitions)
AdjustmentRule(SerializationInfo info, StreamingContext context)
static AdjustmentRule CreateAdjustmentRule(DateTime dateStart, DateTime dateEnd, TimeSpan daylightDelta, TransitionTime daylightTransitionStart, TransitionTime daylightTransitionEnd, TimeSpan baseUtcOffsetDelta)
readonly TransitionTime _daylightTransitionStart
AdjustmentRule(DateTime dateStart, DateTime dateEnd, TimeSpan daylightDelta, TransitionTime daylightTransitionStart, TransitionTime daylightTransitionEnd, TimeSpan baseUtcOffsetDelta, bool noDaylightTransitions)
static readonly TimeSpan MaxDaylightDelta
static AdjustmentRule CreateAdjustmentRule(DateTime dateStart, DateTime dateEnd, TimeSpan daylightDelta, TransitionTime daylightTransitionStart, TransitionTime daylightTransitionEnd)
static void AdjustDaylightDeltaToExpectedRange(ref TimeSpan daylightDelta, ref TimeSpan baseUtcOffsetDelta)
ReadOnlyCollection< TimeZoneInfo > _readOnlySystemTimeZones
volatile OffsetAndRule _oneYearLocalFromUtc
volatile TimeZoneInfo _localTimeZone
static TimeZoneInfo GetCurrentOneYearLocal()
OffsetAndRule GetOneYearLocalFromUtc(int year)
Dictionary< string, TimeZoneInfo > _systemTimeZones
DateTimeKind GetCorrespondingKind(TimeZoneInfo timeZone)
readonly AdjustmentRule Rule
OffsetAndRule(int year, TimeSpan offset, AdjustmentRule rule)
static TimeZoneInfoResult TryGetTimeZoneFromLocalMachine(string id, bool dstDisabled, out TimeZoneInfo value, out Exception e, CachedData cachedData)
static readonly DateTime s_minDateOnly
static DateTime ConvertTimeToUtc(DateTime dateTime, TimeZoneInfoOptions flags)
static TimeZoneInfoResult TryGetTimeZoneFromLocalMachine(string id, out TimeZoneInfo value, out Exception e)
static TimeZoneInfo CreateUtcTimeZone()
static bool TryCreateAdjustmentRules(string id, in Interop.Kernel32.REG_TZI_FORMAT defaultTimeZoneInformation, out AdjustmentRule[] rules, out Exception e, int defaultBaseUtcOffset)
static DateTime ConvertTimeBySystemTimeZoneId(DateTime dateTime, string sourceTimeZoneId, string destinationTimeZoneId)
static bool TryConvertWindowsIdToIanaId(string windowsId, [NotNullWhen(true)] out string? ianaId)
DateTime ConvertToUtc(DateTime dateTime, TimeSpan daylightDelta, TimeSpan baseUtcOffsetDelta)
static readonly TimeZoneInfo s_utcTimeZone
readonly bool _supportsDaylightSavingTime
static bool GetIsDaylightSavingsFromUtc(DateTime time, int year, TimeSpan utc, AdjustmentRule rule, int? ruleIndex, out bool isAmbiguousLocalDst, TimeZoneInfo zone)
static DateTime ConvertTime(DateTime dateTime, TimeZoneInfo sourceTimeZone, TimeZoneInfo destinationTimeZone)
static string FindIdFromTimeZoneInformation(in Interop.Kernel32.TIME_ZONE_INFORMATION timeZone, out bool dstDisabled)
static readonly TimeSpan MaxOffset
static AdjustmentRule CreateAdjustmentRuleFromTimeZoneInformation(in Interop.Kernel32.REG_TZI_FORMAT timeZoneInformation, DateTime startDate, DateTime endDate, int defaultBaseUtcOffset)
static TimeZoneInfoResult TryGetTimeZoneUsingId(string id, bool dstDisabled, out TimeZoneInfo value, out Exception e, CachedData cachedData, bool alwaysFallbackToLocalMachine)
static TimeZoneInfo FromSerializedString(string source)
bool IsDaylightSavingTime(DateTime dateTime, TimeZoneInfoOptions flags)
static TimeZoneInfo CreateCustomTimeZone(string id, TimeSpan baseUtcOffset, string? displayName, string? standardDisplayName, string? daylightDisplayName, AdjustmentRule[]? adjustmentRules)
static string GetAlternativeId(string id, out bool idIsIana)
static TimeSpan GetUtcOffsetFromUtc(DateTime time, TimeZoneInfo zone, out bool isDaylightSavings, out bool isAmbiguousLocalDst)
readonly TimeSpan _baseUtcOffset
TimeSpan GetUtcOffset(DateTime dateTime, TimeZoneInfoOptions flags)
static DateTimeOffset ConvertTimeBySystemTimeZoneId(DateTimeOffset dateTimeOffset, string destinationTimeZoneId)
static DateTime ConvertTime(DateTime dateTime, TimeZoneInfo sourceTimeZone, TimeZoneInfo destinationTimeZone, TimeZoneInfoOptions flags, CachedData cachedData)
static bool TryCompareStandardDate(in Interop.Kernel32.TIME_ZONE_INFORMATION timeZone, in Interop.Kernel32.REG_TZI_FORMAT registryTimeZoneInfo)
static DateTime ConvertTimeFromUtc(DateTime dateTime, TimeZoneInfo destinationTimeZone)
static DateTime TransitionTimeToDateTime(int year, TransitionTime transitionTime)
AdjustmentRule GetAdjustmentRuleForTime(DateTime dateTime, bool dateTimeisUtc, out int? ruleIndex)
TimeSpan[] GetAmbiguousTimeOffsets(DateTimeOffset dateTimeOffset)
readonly string _standardDisplayName
static TimeZoneInfo GetLocalTimeZoneFromWin32Data(in Interop.Kernel32.TIME_ZONE_INFORMATION timeZoneInformation, bool dstDisabled)
override string ToString()
static DateTime ConvertTimeToUtc(DateTime dateTime, TimeZoneInfo sourceTimeZone)
static string GetUtcStandardDisplayName()
static void GetLocalizedNamesByRegistryKey(RegistryKey key, out string displayName, out string standardName, out string daylightName)
List< TimeZoneInfo > _equivalentZones
AdjustmentRule[] GetAdjustmentRules()
static bool GetIsInvalidTime(DateTime time, AdjustmentRule rule, DaylightTimeStruct daylightTime)
static bool UtcOffsetOutOfRange(TimeSpan offset)
static unsafe string GetLocalizedNameByNativeResource(string filePath, int resource)
static TimeSpan GetDaylightSavingsEndOffsetFromUtc(TimeSpan baseUtcOffset, AdjustmentRule rule)
bool IsDaylightSavingTime(DateTimeOffset dateTimeOffset)
override bool Equals([NotNullWhen(true)] object? obj)
bool IsAmbiguousTime(DateTimeOffset dateTimeOffset)
static TimeZoneInfo CreateCustomTimeZone(string id, TimeSpan baseUtcOffset, string? displayName, string? standardDisplayName)
static ReadOnlyCollection< TimeZoneInfo > GetSystemTimeZones()
bool HasSameRules(TimeZoneInfo other)
readonly string _displayName
static void ClearCachedData()
static DateTime ConvertTime(DateTime dateTime, TimeZoneInfo sourceTimeZone, TimeZoneInfo destinationTimeZone, TimeZoneInfoOptions flags)
static readonly DateTime s_maxDateOnly
TimeSpan GetUtcOffset(DateTimeOffset dateTimeOffset)
static TimeZoneInfo CreateCustomTimeZone(string id, TimeSpan baseUtcOffset, string? displayName, string? standardDisplayName, string? daylightDisplayName, AdjustmentRule[]? adjustmentRules, bool disableDaylightSavingTime)
readonly string _daylightDisplayName
static TimeSpan GetUtcOffsetFromUtc(DateTime time, TimeZoneInfo zone, out bool isDaylightSavings)
AdjustmentRule GetPreviousAdjustmentRule(AdjustmentRule rule, int? ruleIndex)
static bool TryConvertWindowsIdToIanaId(string windowsId, string? region, [NotNullWhen(true)] out string? ianaId)
readonly AdjustmentRule[] _adjustmentRules
TimeZoneInfo(in Interop.Kernel32.TIME_ZONE_INFORMATION zone, bool dstDisabled)
static CachedData s_cachedData
static DateTime ConvertTime(DateTime dateTime, TimeZoneInfo destinationTimeZone)
static readonly TimeSpan MinOffset
static TimeZoneInfo Utc
static TimeSpan GetUtcOffsetFromUtc(DateTime time, TimeZoneInfo zone)
AdjustmentRule GetAdjustmentRuleForTime(DateTime dateTime, out int? ruleIndex)
static bool TryCompareTimeZoneInformationToRegistry(in Interop.Kernel32.TIME_ZONE_INFORMATION timeZone, string id, out bool dstDisabled)
static TimeZoneInfo GetLocalTimeZone(CachedData cachedData)
static TimeSpan GetLocalUtcOffset(DateTime dateTime, TimeZoneInfoOptions flags)
static TimeZoneInfo FindSystemTimeZoneById(string id)
TimeSpan GetDaylightSavingsStartOffsetFromUtc(TimeSpan baseUtcOffset, AdjustmentRule rule, int? ruleIndex)
static unsafe bool TryConvertWindowsIdToIanaId(string windowsId, string region, bool allocate, out string ianaId)
static bool IsValidAdjustmentRuleOffset(TimeSpan baseUtcOffset, AdjustmentRule adjustmentRule)
static bool CheckDaylightSavingTimeNotSupported(in Interop.Kernel32.TIME_ZONE_INFORMATION timeZone)
DaylightTimeStruct GetDaylightTime(int year, AdjustmentRule rule, int? ruleIndex)
static bool CheckIsDst(DateTime startTime, DateTime time, DateTime endTime, bool ignoreYearAdjustment, AdjustmentRule rule)
bool IsAmbiguousTime(DateTime dateTime)
static DateTime ConvertUtcToTimeZone(long ticks, TimeZoneInfo destinationTimeZone, out bool isAmbiguousLocalDst)
static unsafe bool TryConvertIanaIdToWindowsId(string ianaId, bool allocate, out string windowsId)
override int GetHashCode()
bool IsDaylightSavingTime(DateTime dateTime)
TimeSpan GetUtcOffset(DateTime dateTime, TimeZoneInfoOptions flags, CachedData cachedData)
TimeZoneInfo(string id, TimeSpan baseUtcOffset, string displayName, string standardDisplayName, string daylightDisplayName, AdjustmentRule[] adjustmentRules, bool disableDaylightSavingTime, bool hasIanaId=false)
TimeSpan GetUtcOffset(DateTime dateTime)
TimeSpan[] GetAmbiguousTimeOffsets(DateTime dateTime)
static bool GetIsDaylightSavings(DateTime time, AdjustmentRule rule, DaylightTimeStruct daylightTime)
DateTime ConvertToFromUtc(DateTime dateTime, TimeSpan daylightDelta, TimeSpan baseUtcOffsetDelta, bool convertToUtc)
bool Equals([NotNullWhen(true)] TimeZoneInfo? other)
static void PopulateAllSystemTimeZones(CachedData cachedData)
static TimeSpan GetUtcOffset(TimeSpan baseUtcOffset, AdjustmentRule adjustmentRule)
readonly string _id
bool IsAmbiguousTime(DateTime dateTime, TimeZoneInfoOptions flags)
static bool GetIsAmbiguousTime(DateTime time, AdjustmentRule rule, DaylightTimeStruct daylightTime)
static bool TryConvertIanaIdToWindowsId(string ianaId, [NotNullWhen(true)] out string? windowsId)
bool IsDaylightSavingTime(DateTime dateTime, TimeZoneInfoOptions flags, CachedData cachedData)
static string GetUtcFullDisplayName(string timeZoneId, string standardDisplayName)
static DateTimeOffset ConvertTime(DateTimeOffset dateTimeOffset, TimeZoneInfo destinationTimeZone)
static TimeSpan GetUtcOffset(DateTime time, TimeZoneInfo zone)
static void ValidateTimeZoneInfo(string id, TimeSpan baseUtcOffset, AdjustmentRule[] adjustmentRules, out bool adjustmentRulesSupportDst)
static TimeZoneInfoResult TryGetTimeZone(string id, bool dstDisabled, out TimeZoneInfo value, out Exception e, CachedData cachedData, bool alwaysFallbackToLocalMachine=false)
static bool TransitionTimeFromTimeZoneInformation(in Interop.Kernel32.REG_TZI_FORMAT timeZoneInformation, out TransitionTime transitionTime, bool readStartDate)
DateTime ConvertFromUtc(DateTime dateTime, TimeSpan daylightDelta, TimeSpan baseUtcOffsetDelta)
bool IsInvalidTime(DateTime dateTime)
static DateTime ConvertTimeToUtc(DateTime dateTime)
TimeZoneInfo(SerializationInfo info, StreamingContext context)
static DateTime ConvertTimeBySystemTimeZoneId(DateTime dateTime, string destinationTimeZoneId)
int CompareAdjustmentRuleToDateTime(AdjustmentRule rule, AdjustmentRule previousRule, DateTime dateTime, DateTime dateOnly, bool dateTimeisUtc)
static string GetLocalizedNameByMuiNativeResource(string resource)
AdjustmentRule GetAdjustmentRuleForAmbiguousOffsets(DateTime adjustedTime, out int? ruleIndex)
static unsafe bool TryGetTimeZoneEntryFromRegistry(RegistryKey key, string name, out Interop.Kernel32.REG_TZI_FORMAT dtzi)
static TimeSpan GetDateTimeNowUtcOffsetFromUtc(DateTime time, out bool isAmbiguousLocalDst)
void GetObjectData(SerializationInfo info, StreamingContext context)
DayOfWeek
Definition DayOfWeek.cs:4
static readonly DateTimeOffset MaxValue
static readonly DateTimeOffset MinValue
override int GetHashCode()
Definition DateTime.cs:886
static readonly DateTime MaxValue
Definition DateTime.cs:37
static readonly DateTime MinValue
Definition DateTime.cs:35
DateTime AddYears(int value)
Definition DateTime.cs:515
DayOfWeek DayOfWeek
Definition DateTime.cs:76
static bool TryParseExact([NotNullWhen(true)] string? s, [NotNullWhen(true)] string? format, IFormatProvider? provider, DateTimeStyles style, out DateTime result)
Definition DateTime.cs:1171
DateTimeKind Kind
Definition DateTime.cs:83
static int DaysInMonth(int year, int month)
Definition DateTime.cs:624
bool IsAmbiguousDaylightSavingTime()
Definition DateTime.cs:892
DateTime AddDays(double value)
Definition DateTime.cs:432
static readonly IntPtr Zero
Definition IntPtr.cs:18
static readonly TimeSpan Zero
Definition TimeSpan.cs:21
int CompareTo(object? value)
Definition TimeSpan.cs:126
static TimeSpan FromHours(double value)
Definition TimeSpan.cs:200
static void SerializeTransitionTime(TransitionTime time, ref ValueStringBuilder serializedText)
static void VerifyIsEscapableCharacter(char c)
static TimeZoneInfo GetDeserializedTimeZoneInfo(string source)
AdjustmentRule[] GetNextAdjustmentRuleArrayValue()
static void SerializeSubstitute(string text, ref ValueStringBuilder serializedText)
static string GetSerializedString(TimeZoneInfo zone)
DateTime GetNextDateTimeValue(string format)
static TransitionTime CreateFixedDateRule(DateTime timeOfDay, int month, int day)
override bool Equals([NotNullWhen(true)] object? obj)
bool Equals(TransitionTime other)
static void ValidateTransitionTime(DateTime timeOfDay, int month, int week, int day, DayOfWeek dayOfWeek)
static TransitionTime CreateFloatingDateRule(DateTime timeOfDay, int month, int week, DayOfWeek dayOfWeek)
TransitionTime(SerializationInfo info, StreamingContext context)
TransitionTime(DateTime timeOfDay, int month, int week, int day, DayOfWeek dayOfWeek, bool isFixedDateRule)
static bool operator!=(TransitionTime t1, TransitionTime t2)
static bool operator==(TransitionTime t1, TransitionTime t2)