Exemplo n.º 1
0
        internal ExTimeZone Promote()
        {
            ExTimeZone         result        = null;
            TimeZoneRule       timeZoneRule  = null;
            TimeZoneRule       timeZoneRule2 = null;
            SortedSet <ushort> sortedSet     = new SortedSet <ushort>();

            VTimeZone.CollectAllRuleYears(this.standardRules, sortedSet);
            VTimeZone.CollectAllRuleYears(this.daylightRules, sortedSet);
            List <RegistryTimeZoneRule> list = new List <RegistryTimeZoneRule>(sortedSet.Count);

            foreach (ushort num in sortedSet)
            {
                TimeZoneRule timeZoneRule3 = VTimeZone.UpdateAndGetCurrentRule(num, this.daylightRules, ref timeZoneRule2);
                TimeZoneRule timeZoneRule4 = VTimeZone.UpdateAndGetCurrentRule(num, this.standardRules, ref timeZoneRule);
                if (timeZoneRule3 != null || timeZoneRule4 != null)
                {
                    list.Add(new RegistryTimeZoneRule((int)num, this.GetNativeTimeZoneRule(timeZoneRule4, timeZoneRule3)));
                }
            }
            try
            {
                result = TimeZoneHelper.CreateCustomExTimeZoneFromRegRules(list[0].RegTimeZoneInfo, this.timeZoneId, this.timeZoneId, list);
            }
            catch (InvalidTimeZoneException ex)
            {
                ExTraceGlobals.ICalTracer.TraceDebug <string>((long)this.GetHashCode(), "ToExTimeZone::ToExTimeZone. Following error found when construct customized time zone: {0}", ex.Message);
                base.Context.AddError(ServerStrings.InvalidICalElement("VTIMEZONE"));
            }
            return(result);
        }
Exemplo n.º 2
0
        private REG_TIMEZONE_INFO GetNativeTimeZoneRule(TimeZoneRule standard, TimeZoneRule daylight)
        {
            if (standard != null && daylight != null && standard.Offset == daylight.Offset)
            {
                daylight = null;
            }
            REG_TIMEZONE_INFO result = default(REG_TIMEZONE_INFO);

            if (standard == null)
            {
                result.Bias         = -daylight.Offset;
                result.DaylightBias = 0;
            }
            else
            {
                result.Bias         = -standard.Offset;
                result.StandardBias = 0;
                if (daylight != null)
                {
                    result.StandardDate = standard.TransitionDate;
                    result.DaylightDate = daylight.TransitionDate;
                    result.DaylightBias = standard.Offset - daylight.Offset;
                }
            }
            return(result);
        }
Exemplo n.º 3
0
        protected override bool ProcessSubComponent(CalendarComponentBase calendarComponent)
        {
            bool         result       = true;
            TimeZoneRule timeZoneRule = calendarComponent as TimeZoneRule;

            if (timeZoneRule != null)
            {
                ushort      year        = timeZoneRule.Year;
                ComponentId componentId = calendarComponent.ComponentId;
                if (componentId != ComponentId.Standard)
                {
                    if (componentId == ComponentId.Daylight)
                    {
                        if (this.daylightRules.ContainsKey(year))
                        {
                            ExTraceGlobals.ICalTracer.TraceError <ushort>(0L, "VTimeZone::ProcessSubComponent:ComponentId.Daylight. Ignoring the repeated year timezone definition. Year: {0}", year);
                        }
                        else
                        {
                            this.daylightRules.Add(year, timeZoneRule);
                        }
                    }
                }
                else if (this.standardRules.ContainsKey(year))
                {
                    ExTraceGlobals.ICalTracer.TraceError <ushort>(0L, "VTimeZone::ProcessSubComponent:ComponentId.Standard. Ignoring the repeated year timezone definition. Year: {0}", year);
                }
                else
                {
                    this.standardRules.Add(year, timeZoneRule);
                }
            }
            return(result);
        }
Exemplo n.º 4
0
 private static TimeZoneRule ValidateRecentRule(TimeZoneRule recentRule, ushort currentYear)
 {
     if (recentRule == null)
     {
         return(null);
     }
     if (!recentRule.RuleHasRecurrenceUntilField || recentRule.RecurrenceRule.UntilDateTime.Year >= (int)currentYear)
     {
         return(recentRule);
     }
     return(null);
 }
Exemplo n.º 5
0
 private static void CollectAllRuleYears(Dictionary <ushort, TimeZoneRule> rules, SortedSet <ushort> allRuleYears)
 {
     foreach (ushort num in rules.Keys)
     {
         allRuleYears.Add(num);
         TimeZoneRule timeZoneRule = rules[num];
         if (timeZoneRule.RuleHasRecurrenceUntilField && timeZoneRule.RecurrenceRule.UntilDateTime.Year < DateTime.MaxValue.Year)
         {
             allRuleYears.Add((ushort)(timeZoneRule.RecurrenceRule.UntilDateTime.Year + 1));
         }
     }
 }
Exemplo n.º 6
0
        private static TimeZoneRule UpdateAndGetCurrentRule(ushort currentYear, Dictionary <ushort, TimeZoneRule> rules, ref TimeZoneRule recentRule)
        {
            TimeZoneRule timeZoneRule;

            if (!rules.TryGetValue(currentYear, out timeZoneRule))
            {
                timeZoneRule = VTimeZone.ValidateRecentRule(recentRule, currentYear);
            }
            recentRule = timeZoneRule;
            return(timeZoneRule);
        }