getDateTimeRange function

Pair<DateTime> getDateTimeRange(
  1. DateRangeType rangeType, [
  2. DateTime? time,
  3. DateTimeWeekDay? weekFirstDay
])

Returns start and end of date range rangeType.

weekFirstDay the desired first day of week for computation behavior. time if null uses DateTime.now .

Implementation

Pair<DateTime> getDateTimeRange(DateRangeType rangeType,
    [DateTime? time, DateTimeWeekDay? weekFirstDay]) {
  time ??= getDateTimeNow();

  var nowStart = getDateTimeDayStart(time);
  var nowEnd = getDateTimeDayEnd(time);

  switch (rangeType) {
    case DateRangeType.today:
      return Pair(nowStart, nowEnd);
    case DateRangeType.yesterday:
      {
        var timeYesterday = getDateTimeYesterday(time);
        return Pair(timeYesterday, getDateTimeDayEnd(timeYesterday));
      }

    case DateRangeType.last7Days:
      return getDateTimeLastNDays(6, nowEnd);
    case DateRangeType.thisWeek:
      return getDateTimeThisWeek(weekFirstDay, nowStart);
    case DateRangeType.lastWeek:
      return getDateTimeLastWeek(weekFirstDay, nowStart);

    case DateRangeType.last30Days:
      return getDateTimeLastNDays(29, time);
    case DateRangeType.last60Days:
      return getDateTimeLastNDays(59, time);
    case DateRangeType.last90Days:
      return getDateTimeLastNDays(89, time);
    case DateRangeType.lastMonth:
      return getDateTimeLastMonth(time);
    case DateRangeType.thisMonth:
      return getDateTimeThisMonth(time);
  }
}