Beispiel #1
0
        /// <summary>
        /// Retrieves the recurrence, after applying the specified name format.
        /// </summary>
        /// <remarks>
        /// Multiple zones may apply the same set of rules as to when they change into/out of
        /// daylight saving time, but with different names.
        /// </remarks>
        /// <param name="zone">The zone for which this rule is being considered.</param>
        public IEnumerable <ZoneRecurrence> GetRecurrences(ZoneLine zone)
        {
            string name = zone.FormatName(recurrence.Savings, daylightSavingsIndicator);

            if (Type == null)
            {
                yield return(recurrence.WithName(name));
            }
            else
            {
                Predicate <int> yearPredicate = GetYearPredicate();
                // Apply a little sanity...
                if (recurrence.IsInfinite || recurrence.ToYear - recurrence.FromYear > 1000)
                {
                    throw new NotSupportedException("Noda Time does not support 'typed' rules over large periods");
                }
                for (int year = recurrence.FromYear; year <= recurrence.ToYear; year++)
                {
                    if (yearPredicate(year))
                    {
                        yield return(recurrence.ForSingleYear(year).WithName(name));
                    }
                }
            }
        }
Beispiel #2
0
        private string FormatName(ZoneLine zone)
        {
            string nameFormat = zone.Format;
            int    index      = nameFormat.IndexOf("/", StringComparison.Ordinal);

            if (index > 0)
            {
                return(recurrence.Savings == Offset.Zero ? nameFormat.Substring(0, index) : nameFormat.Substring(index + 1));
            }
            index = nameFormat.IndexOf("%s", StringComparison.Ordinal);
            if (index >= 0)
            {
                var left  = nameFormat.Substring(0, index);
                var right = nameFormat.Substring(index + 2);
                return(left + daylightSavingsIndicator + right);
            }
            index = nameFormat.IndexOf("%z", StringComparison.Ordinal);
            if (index >= 0)
            {
                var wallOffset = zone.StandardOffset + recurrence.Savings;
                var left       = nameFormat.Substring(0, index);
                var right      = nameFormat.Substring(index + 2);
                return(left + PercentZPattern.Format(wallOffset) + right);
            }
            return(nameFormat);
        }
Beispiel #3
0
 /// <summary>
 /// Adds the given zone line to the database, creating a new list for
 /// that zone ID if necessary.
 /// </summary>
 /// <param name="zone">The zone to add.</param>
 internal void AddZone(ZoneLine zone)
 {
     if (!Zones.TryGetValue(zone.Name, out var zoneSet))
     {
         zoneSet          = new List <ZoneLine>();
         Zones[zone.Name] = zoneSet;
     }
     zoneSet.Add(zone);
 }