Beispiel #1
0
        private static IEnumerable <string> ResolveDateAgainstConstraint(TimexProperty timex, DateRange constraint)
        {
            if (timex.Month != null && timex.DayOfMonth != null)
            {
                var result = new List <string>();
                for (var year = constraint.Start.Year; year <= constraint.End.Year; year++)
                {
                    var t = timex.Clone();
                    t.Year = year;
                    result.AddRange(ResolveDefiniteAgainstConstraint(t, constraint));
                }

                return(result);
            }

            if (timex.DayOfWeek != null)
            {
                // convert between ISO day of week and .NET day of week
                var day    = timex.DayOfWeek == 7 ? DayOfWeek.Sunday : (DayOfWeek)timex.DayOfWeek;
                var dates  = TimexDateHelpers.DatesMatchingDay(day, constraint.Start, constraint.End);
                var result = new List <string>();

                foreach (var d in dates)
                {
                    var t = timex.Clone();
                    t.DayOfWeek  = null;
                    t.Year       = d.Year;
                    t.Month      = d.Month;
                    t.DayOfMonth = d.Day;
                    result.Add(t.TimexValue);
                }

                return(result);
            }

            if (timex.Hour != null)
            {
                var      result = new List <string>();
                DateTime day    = constraint.Start;
                while (day <= constraint.End)
                {
                    var t = timex.Clone();
                    t.Year       = day.Year;
                    t.Month      = day.Month;
                    t.DayOfMonth = day.Day;
                    result.AddRange(ResolveDefiniteAgainstConstraint(t, constraint));
                    day = day.AddDays(1);
                }

                return(result);
            }

            return(Enumerable.Empty <string>());
        }