02 - Date Range Picker/smart-date-picker/ReportDateRangeBumper.cs
/// <summary>
/// Bumps the given start and end dates into a valid data report range
/// </summary>
/// <param name="start">Selected start date</param>
/// <param name="end">Selected end date</param>
/// <param name="dataAvailability">Dates the system has data for</param>
/// <param name="periodType">Period Type</param>
/// <returns></returns>
Bumps the given start and end dates into a valid data report range
Bumps the given start and end dates into a valid data report range
public static DateRange BumpDates(DateTime start, DateTime end, DateRange dataAvailability, PeriodType periodType)
        {
            var constrainedDataAvailability = GetConstrainedDataAvailability(dataAvailability, periodType);
            if (constrainedDataAvailability == null)
                return dataAvailability;
            var finalStart = start;
            var finalEnd = (end < start) ? start : end;
            finalStart = finalStart.ToStart(periodType);
            finalEnd = finalEnd.ToEnd(periodType);
            if (finalStart > constrainedDataAvailability.Value.EndDate)
            {
                finalStart = constrainedDataAvailability.Value.EndDate.ToStart(periodType);
                finalEnd = constrainedDataAvailability.Value.EndDate;
            }
            if (finalEnd < constrainedDataAvailability.Value.StartDate)
            {
                finalStart = constrainedDataAvailability.Value.StartDate;
                finalStart = constrainedDataAvailability.Value.StartDate.ToEnd(periodType);
            }
            if (finalStart < constrainedDataAvailability.Value.StartDate)
            {
                finalStart = constrainedDataAvailability.Value.StartDate;
            }
            if (finalEnd > constrainedDataAvailability.Value.EndDate)
            {
                finalEnd = constrainedDataAvailability.Value.EndDate;
            }
            return new DateRange(finalStart, finalEnd);
        }
public static DateRange BumpDates ( DateTime start , DateTime end , DateRange dataAvailability , PeriodType periodType ) { var constrainedDataAvailability = GetConstrainedDataAvailability ( dataAvailability , periodType ) ; if ( constrainedDataAvailability == null ) return dataAvailability ; var finalStart = start ; var finalEnd = ( end < start ) ? start : end ; finalStart = finalStart . ToStart ( periodType ) ; finalEnd = finalEnd . ToEnd ( periodType ) ; if ( finalStart > constrainedDataAvailability . Value . EndDate ) { finalStart = constrainedDataAvailability . Value . EndDate . ToStart ( periodType ) ; finalEnd = constrainedDataAvailability . Value . EndDate ; } if ( finalEnd < constrainedDataAvailability . Value . StartDate ) { finalStart = constrainedDataAvailability . Value . StartDate ; finalStart = constrainedDataAvailability . Value . StartDate . ToEnd ( periodType ) ; } if ( finalStart < constrainedDataAvailability . Value . StartDate ) { finalStart = constrainedDataAvailability . Value . StartDate ; } if ( finalEnd > constrainedDataAvailability . Value . EndDate ) { finalEnd = constrainedDataAvailability . Value . EndDate ; } return new DateRange ( finalStart , finalEnd ) ; }
Bumps the given start and end dates into a valid data report range
Bumps the given start and end dates into a valid data report range
//Abort efforts if dataAvailability won't fit in our period at all //TODO: Determine which date the user selected as I'm currently assuming the start date takes precedence.
None
start
DateTime
Selected start date
Selected start date
end
DateTime
Selected end date
Selected end date
dataAvailability
DateRange
Dates the system has data for
Dates the system has data for
periodType
PeriodType
None