Exemplo n.º 1
0
        public override bool Equals(object obj)
        {
            VTimeZoneInfo tzi = obj as VTimeZoneInfo;

            if (tzi != null)
            {
                return(object.Equals(TimeZoneName, tzi.TimeZoneName) &&
                       object.Equals(OffsetFrom, tzi.OffsetFrom) &&
                       object.Equals(OffsetTo, tzi.OffsetTo));
            }
            return(base.Equals(obj));
        }
Exemplo n.º 2
0
        private static ITimeZoneInfo CreateTimeZoneInfo(List <ZoneInterval> matchedIntervals, List <ZoneInterval> intervals, bool isRRule = true, bool isOnlyInterval = false)
        {
            if (matchedIntervals == null || !matchedIntervals.Any())
            {
                throw new ArgumentException("No intervals found in matchedIntervals");
            }

            var oldestInterval = matchedIntervals.OrderBy(x => x.Start).FirstOrDefault();

            if (oldestInterval == null)
            {
                throw new InvalidOperationException("oldestInterval was not found");
            }

            var previousInterval = intervals.SingleOrDefault(x => x.End == oldestInterval.Start);

            var delta = new TimeSpan(1, 0, 0);

            if (previousInterval != null)
            {
                delta = (previousInterval.WallOffset - oldestInterval.WallOffset).ToTimeSpan();
            }
            else if (isOnlyInterval)
            {
                delta = new TimeSpan();
            }

            var utcOffset = oldestInterval.StandardOffset.ToTimeSpan();

            var timeZoneInfo = new VTimeZoneInfo();

            var isDaylight = oldestInterval.Savings.Ticks > 0;

            if (isDaylight)
            {
                timeZoneInfo.Name       = "DAYLIGHT";
                timeZoneInfo.OffsetFrom = new UtcOffset(utcOffset);
                timeZoneInfo.OffsetTo   = new UtcOffset(utcOffset - delta);
            }
            else
            {
                timeZoneInfo.Name       = "STANDARD";
                timeZoneInfo.OffsetFrom = new UtcOffset(utcOffset + delta);
                timeZoneInfo.OffsetTo   = new UtcOffset(utcOffset);
            }

            timeZoneInfo.TimeZoneName = oldestInterval.Name;

            var start = oldestInterval.IsoLocalStart.ToDateTimeUnspecified() + delta;

            timeZoneInfo.Start = new CalDateTime(start)
            {
                HasTime = true
            };

            if (isRRule)
            {
                PopulateTimeZoneInfoRecurrenceRules(timeZoneInfo, oldestInterval);
            }
            else
            {
                PopulateTimeZoneInfoRecurrenceDates(timeZoneInfo, matchedIntervals, delta);
            }

            return(timeZoneInfo);
        }