Esempio n. 1
0
                /// <summary>
                /// Creates a hash table node with all the information for this period.
                /// We start off by finding the interval for the start of the period, and
                /// then repeatedly check whether that interval ends after the end of the
                /// period - at which point we're done. If not, find the next interval, create
                /// a new node referring to that interval and the previous interval, and keep going.
                /// </summary>
                internal static HashCacheNode CreateNode(int period, IZoneIntervalMap map)
                {
                    var periodStart = new Instant((long)period << PeriodShift);
                    var periodEnd   = new Instant((long)(period + 1) << PeriodShift);

                    var interval = map.GetZoneInterval(periodStart);
                    var node     = new HashCacheNode(interval, period, null);

                    // Keep going while the current interval ends before the period.
                    while (interval.End < periodEnd)
                    {
                        interval = map.GetZoneInterval(interval.End);
                        node     = new HashCacheNode(interval, period, node);
                    }

                    return(node);
                }
Esempio n. 2
0
                public ZoneInterval GetZoneInterval(Instant instant)
                {
                    var interval = originalMap.GetZoneInterval(instant);

                    return(interval.Name == daylightName
                        ? new ZoneInterval(daylightName, interval.RawStart, interval.RawEnd, interval.WallOffset, Offset.FromHours(1))
                        : interval);
                }
 // TODO: Consider making this part of the NodaTime assembly.
 // It's just a copy from DateTimeZone, with the interval taken out.
 // It could be an extension method on IZoneIntervalMap, with optional interval.
 // On the other hand, IZoneIntervalMap is internal, so it would only be used by us.
 private static IEnumerable<ZoneInterval> GetZoneIntervals(IZoneIntervalMap map)
 {
     var current = Instant.MinValue;
     while (current < Instant.AfterMaxValue)
     {
         var zoneInterval = map.GetZoneInterval(current);
         yield return zoneInterval;
         // If this is the end of time, this will just fail on the next comparison.
         current = zoneInterval.RawEnd;
     }
 }
                /// <summary>
                /// Creates a hash table node with all the information for this period.
                /// We start off by finding the interval for the start of the period, and
                /// then repeatedly check whether that interval ends after the end of the
                /// period - at which point we're done. If not, find the next interval, create
                /// a new node referring to that interval and the previous interval, and keep going.
                /// </summary>
                internal static HashCacheNode CreateNode(int period, IZoneIntervalMap map)
                {
                    var days                = period << PeriodShift;
                    var periodStart         = new Instant(new Duration(Math.Max(days, Instant.MinDays), 0L));
                    var nextPeriodStartDays = days + (1 << PeriodShift);

                    var interval = map.GetZoneInterval(periodStart);
                    var node     = new HashCacheNode(interval, period, null);

                    // Keep going while the current interval ends before the period.
                    // (We only need to check the days, as every period lands on a
                    // day boundary.)
                    // If the raw end is the end of time, the condition will definitely
                    // evaluate to false.
                    while (interval.RawEnd.DaysSinceEpoch < nextPeriodStartDays)
                    {
                        interval = map.GetZoneInterval(interval.End);
                        node     = new HashCacheNode(interval, period, node);
                    }

                    return(node);
                }
        // TODO: Consider making this part of the NodaTime assembly.
        // It's just a copy from DateTimeZone, with the interval taken out.
        // It could be an extension method on IZoneIntervalMap, with optional interval.
        // On the other hand, IZoneIntervalMap is internal, so it would only be used by us.
        private static IEnumerable <ZoneInterval> GetZoneIntervals(IZoneIntervalMap map)
        {
            var current = Instant.MinValue;

            while (current < Instant.AfterMaxValue)
            {
                var zoneInterval = map.GetZoneInterval(current);
                yield return(zoneInterval);

                // If this is the end of time, this will just fail on the next comparison.
                current = zoneInterval.RawEnd;
            }
        }
Esempio n. 6
0
 /// <inheritdoc />
 public override ZoneInterval GetZoneInterval(Instant instant)
 {
     return(map.GetZoneInterval(instant));
 }
                /// <summary>
                /// Creates a hash table node with all the information for this period.
                /// We start off by finding the interval for the start of the period, and
                /// then repeatedly check whether that interval ends after the end of the
                /// period - at which point we're done. If not, find the next interval, create
                /// a new node referring to that interval and the previous interval, and keep going.
                /// </summary>
                internal static HashCacheNode CreateNode(int period, IZoneIntervalMap map)
                {
                    var days = period << PeriodShift;
                    var periodStart = new Instant(new Duration(Math.Max(days, Instant.MinDays), 0L));
                    var nextPeriodStartDays = days + (1 << PeriodShift);

                    var interval = map.GetZoneInterval(periodStart);
                    var node = new HashCacheNode(interval, period, null);

                    // Keep going while the current interval ends before the period.
                    // (We only need to check the days, as every period lands on a
                    // day boundary.)
                    // If the raw end is the end of time, the condition will definitely
                    // evaluate to false.
                    while (interval.RawEnd.DaysSinceEpoch < nextPeriodStartDays)
                    {
                        interval = map.GetZoneInterval(interval.End);
                        node = new HashCacheNode(interval, period, node);
                    }

                    return node;
                }