private void AddRulesToRuleGroup(ExTimeZoneRuleGroup timeZoneRuleGroup, TimeZoneDefinition.Transition transition, TimeZoneDefinition.TransitionsGroup transitions) { if (transition.To.Kind != TimeZoneDefinition.TransitionTargetKindType.Group) { throw new TimeZoneException((Strings.IDs) 2265146620U, transitions, transition); } foreach (TimeZoneDefinition.TransitionsGroup transitionsGroup in this.transitionsGroups) { if (transitionsGroup.Id == transition.To.Value) { int num = transitionsGroup.Transitions.Length; for (int j = 0; j < num; j++) { int num2 = (j + 1) % num; TimeZoneDefinition.Transition transition2 = transitionsGroup.Transitions[j]; TimeZoneDefinition.Transition transitionFromPeriod = transitionsGroup.Transitions[num2]; if (transition2.To.Kind != TimeZoneDefinition.TransitionTargetKindType.Period) { throw new TimeZoneException(Strings.IDs.MessageInvalidTimeZoneReferenceToPeriod, transitionsGroup, transition2); } this.AddRuleToRuleGroup(timeZoneRuleGroup, transition2, transitionFromPeriod, transitionsGroup); } return; } } throw new TimeZoneException(Strings.IDs.MessageInvalidTimeZoneMissedGroup, transitions, transition); }
private void AddRuleToRuleGroup(ExTimeZoneRuleGroup timeZoneRuleGroup, TimeZoneDefinition.Transition transitionToPeriod, TimeZoneDefinition.Transition transitionFromPeriod, TimeZoneDefinition.TransitionsGroup transitionToGroup) { TimeZoneDefinition.RecurringDayTransition recurringDayTransition = transitionFromPeriod as TimeZoneDefinition.RecurringDayTransition; TimeZoneDefinition.RecurringDateTransition recurringDateTransition = transitionFromPeriod as TimeZoneDefinition.RecurringDateTransition; if (!this.periodsDictionary.ContainsKey(transitionToPeriod.To.Value)) { throw new TimeZoneException((Strings.IDs) 3865092385U, transitionToGroup, transitionToPeriod); } TimeZoneDefinition.PeriodType periodType = this.periodsDictionary[transitionToPeriod.To.Value]; TimeSpan bias = XmlConvert.ToTimeSpan(periodType.Bias); bias = bias.Negate(); ExYearlyRecurringTime observanceEnd; if (recurringDateTransition != null) { TimeSpan timeSpan = TimeZoneDefinition.ConvertOffsetToTimeSpan(recurringDateTransition.TimeOffset, transitionToPeriod, transitionToGroup); try { observanceEnd = new ExYearlyRecurringDate(recurringDateTransition.Month, recurringDateTransition.Day, timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds, timeSpan.Milliseconds); goto IL_16C; } catch (ArgumentOutOfRangeException ex) { throw new TimeZoneException((Strings.IDs) 3961981453U, ex, transitionToGroup, transitionToPeriod, "ParameterName", ex.ParamName); } } if (recurringDayTransition != null) { TimeSpan timeSpan2 = TimeZoneDefinition.ConvertOffsetToTimeSpan(recurringDayTransition.TimeOffset, transitionToPeriod, transitionToGroup); DayOfWeek?dayOfWeek = this.ConvertToDayOfWeek(recurringDayTransition.DayOfWeek); if (dayOfWeek == null) { throw new TimeZoneException(Strings.IDs.MessageInvalidTimeZoneDayOfWeekValue, transitionToGroup, transitionToPeriod); } try { observanceEnd = new ExYearlyRecurringDay(recurringDayTransition.Occurrence, dayOfWeek.Value, recurringDayTransition.Month, timeSpan2.Hours, timeSpan2.Minutes, timeSpan2.Seconds, timeSpan2.Milliseconds); goto IL_16C; } catch (ArgumentOutOfRangeException ex2) { throw new TimeZoneException((Strings.IDs) 3961981453U, ex2, transitionToGroup, transitionToPeriod, "ParameterName", ex2.ParamName); } } observanceEnd = null; IL_16C: ExTimeZoneRule ruleInfo = new ExTimeZoneRule(periodType.Id, periodType.Name, bias, observanceEnd); timeZoneRuleGroup.AddRule(ruleInfo); }
private void ConvertToExTimeZone() { ExTimeZoneInformation exTimeZoneInformation = new ExTimeZoneInformation("tzone://Microsoft/Custom", this.name); exTimeZoneInformation.AlternativeId = this.id; if (this.transitions.Transitions[0].GetType() != typeof(TimeZoneDefinition.Transition)) { throw new TimeZoneException((Strings.IDs) 3332140560U, this.transitions, this.transitions.Transitions[0]); } for (int i = 0; i < this.transitions.Transitions.Length; i++) { DateTime?endTransition; if (i != this.transitions.Transitions.Length - 1) { TimeZoneDefinition.AbsoluteDateTransition absoluteDateTransition = this.transitions.Transitions[i + 1] as TimeZoneDefinition.AbsoluteDateTransition; if (absoluteDateTransition == null) { throw new TimeZoneException((Strings.IDs) 3644766027U, this.transitions, this.transitions.Transitions[i + 1]); } endTransition = new DateTime?(absoluteDateTransition.DateTime); } else { endTransition = null; } ExTimeZoneRuleGroup exTimeZoneRuleGroup = new ExTimeZoneRuleGroup(endTransition); this.AddRulesToRuleGroup(exTimeZoneRuleGroup, this.transitions.Transitions[i], this.transitions); if (exTimeZoneRuleGroup.Rules.Count != 0) { exTimeZoneInformation.AddGroup(exTimeZoneRuleGroup); } } try { this.timeZone = new ExTimeZone(exTimeZoneInformation); } catch (ArgumentException exception) { throw new TimeZoneException(exception); } catch (NotImplementedException exception2) { throw new TimeZoneException(exception2); } catch (InvalidOperationException exception3) { throw new TimeZoneException(exception3); } }
private static ExTimeZone LoadGmtTimeZone() { ExTimeZone result; if (!ExTimeZoneEnumerator.Instance.TryGetTimeZoneByName("Greenwich Standard Time", out result)) { ExTimeZoneInformation exTimeZoneInformation = new ExTimeZoneInformation("Greenwich Standard Time", "Greenwich Standard Time"); ExTimeZoneRuleGroup exTimeZoneRuleGroup = new ExTimeZoneRuleGroup(null); ExTimeZoneRule ruleInfo = new ExTimeZoneRule("Standard", "Standard", new TimeSpan(0L), null); exTimeZoneRuleGroup.AddRule(ruleInfo); exTimeZoneInformation.AddGroup(exTimeZoneRuleGroup); result = new ExTimeZone(exTimeZoneInformation); } return(result); }
internal static REG_TIMEZONE_INFO RegTimeZoneInfoFromExTimeZoneRuleGroup(ExTimeZoneRuleGroup group) { REG_TIMEZONE_INFO result = default(REG_TIMEZONE_INFO); ExTimeZoneRule exTimeZoneRule = group.Rules[0]; ExTimeZoneRule exTimeZoneRule2 = (group.Rules.Count > 1) ? group.Rules[1] : null; if (exTimeZoneRule2 != null && exTimeZoneRule.Bias > exTimeZoneRule2.Bias) { ExTimeZoneRule exTimeZoneRule3 = exTimeZoneRule; exTimeZoneRule = exTimeZoneRule2; exTimeZoneRule2 = exTimeZoneRule3; } result.Bias = (int)(-(int)exTimeZoneRule.Bias.TotalMinutes); result.StandardBias = 0; if (exTimeZoneRule2 != null) { result.DaylightBias = (int)(exTimeZoneRule.Bias.TotalMinutes - exTimeZoneRule2.Bias.TotalMinutes); result.StandardDate = TimeZoneHelper.Win32SystemTimeFromRecurringTime(exTimeZoneRule2.ObservanceEnd); result.DaylightDate = TimeZoneHelper.Win32SystemTimeFromRecurringTime(exTimeZoneRule.ObservanceEnd); } return(result); }
public static REG_TIMEZONE_INFO RegTimeZoneInfoFromExTimeZone(ExTimeZone timeZone, ExDateTime effectiveTime) { DateTime t = (DateTime)effectiveTime.ToUtc(); ExTimeZoneRuleGroup exTimeZoneRuleGroup = null; foreach (ExTimeZoneRuleGroup exTimeZoneRuleGroup2 in timeZone.TimeZoneInformation.Groups) { if (exTimeZoneRuleGroup == null) { exTimeZoneRuleGroup = exTimeZoneRuleGroup2; } if (exTimeZoneRuleGroup2.EffectiveUtcStart <= t && exTimeZoneRuleGroup2.EffectiveUtcEnd > t) { exTimeZoneRuleGroup = exTimeZoneRuleGroup2; break; } } if (exTimeZoneRuleGroup.Rules.Count > 2) { throw new NotImplementedException(); } return(TimeZoneHelper.RegTimeZoneInfoFromExTimeZoneRuleGroup(exTimeZoneRuleGroup)); }