コード例 #1
0
        /// <summary>Returns first days in range.</summary>
        /// <param name="range">The date range.</param>
        /// <returns>First days of months in range</returns>
        public static IEnumerable <DateTime> DaysBetween(this Range <DateTime> range)
        {
            range = range.MakeInclusive();
            if (range.IsEmpty)
            {
                yield break;
            }

            var startDate = range.FromValue;
            var endDate   = range.ToValue;

            while (startDate <= endDate)
            {
                yield return(startDate);

                startDate = startDate.NextDay();
            }
        }
コード例 #2
0
        /// <summary>Returns first days of years in range.</summary>
        /// <param name="range">The date range.</param>
        /// <returns>First days of years in range</returns>
        public static IEnumerable <DateTime> YearsBetween(this Range <DateTime> range)
        {
            range = range.MakeInclusive();
            if (range.IsEmpty)
            {
                yield break;
            }

            var startDate = range.FromValue.FirstDayOfYear();
            var endDate   = range.ToValue;

            // if range.FromValue is not first date of year, the years is skipped.
            if (startDate < range.FromValue)
            {
                startDate = startDate.NextYear();
            }
            while (startDate <= endDate)
            {
                yield return(startDate);

                startDate = startDate.NextYear();
            }
        }
コード例 #3
0
 /// <summary>Returns delta between two dates measured in months.</summary>
 /// <param name="range">The date range.</param>
 /// <returns>Delta between two dates measured in months.</returns>
 public static int DifferenceInMonths(this Range <DateTime> range)
 {
     range = range.MakeInclusive();
     return(DifferenceInMonths(range.FromValue, range.ToValue));
 }
コード例 #4
0
 /// <summary>Replaces exclusive boundaries with inclusive ones.</summary>
 /// <param name="range">The date range.</param>
 /// <returns>A range with inclusive boundaries.</returns>
 public static Range <DateTime> MakeInclusive(this Range <DateTime> range) =>
 range.MakeInclusive(d => d.NextDay(), d => d.PrevDay());