Exemplo n.º 1
0
        /// <summary>
        /// If the effective TZRule structure's lBias, lStandardBias, lDaylightBias,
        /// stStandardDate, and stDaylightDate fields are not equal to the corresponding
        /// fields in the PidLidTimeZoneStruct property,
        /// the PidLidAppointmentTimeZoneDefinitionRecur and PidLidTimeZoneStruct properties
        /// are considered inconsistent.
        /// </summary>
        public bool IsConsistent(TimeZoneStructure structure)
        {
            TimeZoneRuleStructure effectiveTimeZoneRule = null;

            foreach (TimeZoneRuleStructure timeZoneRule in TZRules)
            {
                if (timeZoneRule.IsEffectiveTimeZoneRule)
                {
                    effectiveTimeZoneRule = timeZoneRule;
                    break;
                }
            }

            if (effectiveTimeZoneRule == null)
            {
                return(false);
            }
            else
            {
                return(effectiveTimeZoneRule.lBias == structure.lBias &&
                       effectiveTimeZoneRule.lStandardBias == structure.lStandardBias &&
                       effectiveTimeZoneRule.lDaylightBias == structure.lDaylightBias &&
                       effectiveTimeZoneRule.stStandardDate == structure.stStandardDate &&
                       effectiveTimeZoneRule.stDaylightDate == structure.stDaylightDate);
            }
        }
        public static TimeZoneStructure FromTimeZoneInfo(TimeZoneInfo staticTimeZone)
        {
            TimeZoneInfo.AdjustmentRule[] rules = staticTimeZone.GetAdjustmentRules();
            if (rules.Length > 1)
            {
                throw new ArgumentException("Cannot create TimeZoneStructure from a time zone with multiple DST rules");
            }

            TimeZoneStructure structure = new TimeZoneStructure();

            if (rules.Length == 0)
            {
                // no daylight saving
                structure.SetBias(staticTimeZone.BaseUtcOffset, new TimeSpan());
                structure.stStandardDate = new SystemTime();
                structure.stDaylightDate = new SystemTime();
            }
            else
            {
                TimeZoneInfo.AdjustmentRule rule = rules[0];
                structure.SetBias(staticTimeZone.BaseUtcOffset, rule.DaylightDelta);
                structure.stStandardDate = AdjustmentRuleHelper.GetStandardDate(rule);
                structure.stDaylightDate = AdjustmentRuleHelper.GetDaylightDate(rule);
            }

            return(structure);
        }
        /// <param name="dynamicTimeZone">can be set to null if not available</param>
        public override void SetOriginalTimeZone(TimeZoneInfo staticTimeZone, TimeZoneInfo dynamicTimeZone, int effectiveYear)
        {
            this.TimeZoneStructure   = TimeZoneStructure.FromTimeZoneInfo(staticTimeZone);
            this.TimeZoneDescription = staticTimeZone.DisplayName;
            if (this.File.WriterCompatibilityMode >= WriterCompatibilityMode.Outlook2003SP3)
            {
                TimeZoneInfo.AdjustmentRule effectiveRule = AdjustmentRuleUtils.GetFirstRule(staticTimeZone);
                TimeZoneInfo definitionTimezone           = (dynamicTimeZone == null) ? staticTimeZone : dynamicTimeZone;
                TimeZoneDefinitionStructure timeZoneDefinitionStartDisplay = TimeZoneDefinitionStructure.FromTimeZoneInfo(definitionTimezone, effectiveRule, effectiveYear, false);
                this.TimeZoneDefinitionStartDisplay = timeZoneDefinitionStartDisplay;
                // We do not set TimeZoneDefinitionEndDisplay, so Outlook will use TimeZoneDefinitionStartDisplay.

                // Only Outlook 2007 uses PidLidAppointmentTimeZoneDefinitionRecur
                if (this.File.WriterCompatibilityMode >= WriterCompatibilityMode.Outlook2007RTM &&
                    this.File.WriterCompatibilityMode < WriterCompatibilityMode.Outlook2010RTM)
                {
                    TimeZoneDefinitionStructure timeZoneDefinitionRecurStructure = TimeZoneDefinitionStructure.FromTimeZoneInfo(definitionTimezone, effectiveRule, effectiveYear, true);
                    this.TimeZoneDefinitionRecurStructure = timeZoneDefinitionRecurStructure;
                }
            }
        }