02 - Date Range Picker/smart-date-picker/ReportDateRangeBumper.cs
/// <summary>
/// Extension method for DateTime to get the end of a particular period type.
/// </summary>
/// <param name="date"></param>
/// <param name="periodType"></param>
/// <returns></returns>
Extension method for DateTime to get the end of a particular period type.
Extension method for DateTime to get the end of a particular period type .
public static DateTime ToEnd(this DateTime date, PeriodType periodType)
        {
            switch (periodType)
            {
                case PeriodType.Weeks:
                    var difference = DayOfWeek.Saturday - date.DayOfWeek;
                    return date.AddDays(difference);
                case PeriodType.Months:
                    return new DateTime(date.Year, date.Month, DateTime.DaysInMonth(date.Year, date.Month));
                case PeriodType.Quarters:
                    for (int month = 4; month <= 10; month += 3)
                    {
                        if (date.Month < month)
                        {
                            return new DateTime(date.Year, month, 1).AddDays(-1);
                        }
                    }
                    return new DateTime(date.Year, 12, 31);
                default:
                    return date;
            }
        }
public static DateTime ToEnd ( this DateTime date , PeriodType periodType ) { switch ( periodType ) { case PeriodType . Weeks : var difference = DayOfWeek . Saturday - date . DayOfWeek ; return date . AddDays ( difference ) ; case PeriodType . Months : return new DateTime ( date . Year , date . Month , DateTime . DaysInMonth ( date . Year , date . Month ) ) ; case PeriodType . Quarters : for ( int month = 4 ; month <= 10 ; month += 3 ) { if ( date . Month < month ) { return new DateTime ( date . Year , month , 1 ) . AddDays ( - 1 ) ; } } return new DateTime ( date . Year , 12 , 31 ) ; default : return date ; } }
Extension method for DateTime to get the end of a particular period type.
Extension method for DateTime to get the end of a particular period type .
None
DateTime
this
periodType
PeriodType
None
date
None