Example #1
0
        private static bool InDayOfMonthRange(IrIntegerRange range, int year, int month, int dayOfMonth)
        {
            if (range.Start < 0 || (range.IsRange && range.End < 0))
            {
                // one of the range values is negative, so we need to convert it to a positive by counting back from the end of the month
                var daysInMonth = DateTime.DaysInMonth(year, month);
                range = range.CloneWithRevisedRange(
                    range.Start < 0 ? daysInMonth + range.Start + 1 : range.Start,
                    range.End < 0 ? daysInMonth + range.End + 1 : range.End
                );
            }

            return InIntegerRange(range, dayOfMonth, DaysInPreviousMonth(year, month), 1);
        }
Example #2
0
        private static bool InIntegerRange(IrIntegerRange range, int value, int lengthOfUnit, int min = 0)
        {
            if (!range.IsRange)
            {
                return value == range.Start;
            }

            if (range.IsHalfOpen && value == range.End)
                return false;

            if (range.IsSplit) // range spans across the max value and loops back around
            {
                if (value <= range.End || value >= range.Start)
                {
                    if (range.HasInterval)
                    {
                        if (value >= range.Start)
                            return (value - range.Start) % range.Interval == 0;

                        return (value + lengthOfUnit - range.Start) % range.Interval == 0;
                    }

                    return true;
                }
            }
            else // not a split range (easier case)
            {
                if (value >= range.Start && value <= range.End)
                {
                    if (range.HasInterval)
                        return (value - range.Start) % range.Interval == 0;

                    return true;
                }
            }

            return false;
        }
Example #3
0
 private static bool InDayOfYearRange(IrIntegerRange range, int year, int month, int dayOfYear)
 {
     if (range.Start < 0 || (range.IsRange && range.End < 0))
     {
         // one of the range values is negative, so we need to convert it to a positive
         var daysInYear = DateTime.IsLeapYear(year) ? 366 : 365;
         range = range.CloneWithRevisedRange(
             range.Start < 0 ? daysInYear + range.Start + 1 : range.Start,
             range.End < 0 ? daysInYear + range.End + 1 : range.End
         );
     }
     var daysInPrevYear = DateTime.IsLeapYear(year-1) ? 366 : 365;
     return InIntegerRange(range, dayOfYear, daysInPrevYear);
 }