private static NativeMethods.SystemTime Win32SystemTimeFromRecurringTime(ExYearlyRecurringTime recurring) { NativeMethods.SystemTime result = default(NativeMethods.SystemTime); ExYearlyRecurringDate exYearlyRecurringDate = recurring as ExYearlyRecurringDate; ExYearlyRecurringDay exYearlyRecurringDay = recurring as ExYearlyRecurringDay; if (exYearlyRecurringDate != null) { result.Year = (ushort)ExDateTime.Now.Year; result.Month = (ushort)exYearlyRecurringDate.Month; result.Day = (ushort)exYearlyRecurringDate.Day; result.Hour = (ushort)exYearlyRecurringDate.Hour; result.Minute = (ushort)exYearlyRecurringDate.Minute; result.Second = (ushort)exYearlyRecurringDate.Second; result.Milliseconds = (ushort)exYearlyRecurringDate.Milliseconds; } else { if (exYearlyRecurringDay == null) { throw new InvalidOperationException(); } result.Year = 0; result.Month = (ushort)exYearlyRecurringDay.Month; result.Day = (ushort)((exYearlyRecurringDay.Occurrence == -1) ? 5 : exYearlyRecurringDay.Occurrence); result.DayOfWeek = (ushort)exYearlyRecurringDay.DayOfWeek; result.Hour = (ushort)exYearlyRecurringDay.Hour; result.Minute = (ushort)exYearlyRecurringDay.Minute; result.Second = (ushort)exYearlyRecurringDay.Second; result.Milliseconds = (ushort)exYearlyRecurringDay.Milliseconds; } return(result); }
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 RenderTransitionToPeriod(XmlElement xmlTransitionsGroup, ExTimeZoneRule rule, ExTimeZoneRule nextRule, int ruleGroupIds) { ExYearlyRecurringTime observanceEnd = rule.ObservanceEnd; ExYearlyRecurringDate exYearlyRecurringDate = rule.ObservanceEnd as ExYearlyRecurringDate; ExYearlyRecurringDay exYearlyRecurringDay = rule.ObservanceEnd as ExYearlyRecurringDay; string localName; if (exYearlyRecurringDay != null) { localName = "RecurringDayTransition"; } else if (exYearlyRecurringDate != null) { localName = "RecurringDateTransition"; } else { if (observanceEnd != null) { return; } localName = "Transition"; } XmlElement xmlElement = TimeZoneDefinition.XmlHelper.CreateElement(xmlTransitionsGroup, this.typePrefix, localName, this.typeNameSpace); XmlElement parentElement = TimeZoneDefinition.XmlHelper.CreateTextElement(xmlElement, this.typePrefix, "To", nextRule.Id, this.typeNameSpace); TimeZoneDefinition.XmlHelper.CreateAttribute(parentElement, "Kind", "Period"); if (observanceEnd != null) { this.RenderExYearlyRecurringTime(xmlElement, observanceEnd); if (exYearlyRecurringDay != null) { TimeZoneDefinition.XmlHelper.CreateTextElement(xmlElement, this.typePrefix, "DayOfWeek", exYearlyRecurringDay.DayOfWeek.ToString(), this.typeNameSpace); TimeZoneDefinition.XmlHelper.CreateTextElement(xmlElement, this.typePrefix, "Occurrence", exYearlyRecurringDay.Occurrence.ToString(), this.typeNameSpace); return; } if (exYearlyRecurringDate != null) { TimeZoneDefinition.XmlHelper.CreateTextElement(xmlElement, this.typePrefix, "Day", exYearlyRecurringDate.Day.ToString(), this.typeNameSpace); } } }