DatepickerDateRange.fromProtoBuf constructor

DatepickerDateRange.fromProtoBuf(
  1. Clock clock,
  2. DatepickerDateRange pb
)

Construct from the protocol buffer format defined in date_range.proto.

Implementation

factory DatepickerDateRange.fromProtoBuf(
    Clock clock, proto.DatepickerDateRange pb) {
  if (pb.hasAllTimeRange()) {
    return allTime;
  } else if (pb.hasDaysAgo()) {
    return SingleDayRange.daysAgo(clock, pb.daysAgo);
  } else if (pb.hasLastNDays()) {
    return LastNDaysRange.beforeToday(clock, pb.lastNDays);
  } else if (pb.hasLastNDaysToToday()) {
    return LastNDaysToTodayRange.beforeToday(clock, pb.lastNDaysToToday);
  } else if (pb.hasWeeksAgo()) {
    if (pb.hasStartWeekday()) {
      return WeekRange.weeksAgo(clock, pb.weeksAgo,
          startWeekday: pb.startWeekday);
    } else {
      return WeekRange.weeksAgo(clock, pb.weeksAgo);
    }
  } else if (pb.hasMonthsAgo()) {
    return MonthRange.monthsAgo(clock, pb.monthsAgo);
  } else if (pb.hasBroadcastMonthsAgo()) {
    return BroadcastMonthRange.monthsAgo(clock, pb.broadcastMonthsAgo);
  } else if (pb.hasYearsAgo()) {
    return YearRange.yearsAgo(clock, pb.yearsAgo);
  }

  return DatepickerDateRange.custom(
      _convertToDate(pb.dateRange.start), _convertToDate(pb.dateRange.end));
}