findByUnit static method

DurationInterval findByUnit(
  1. int unitValue,
  2. DurationUnit unit
)

Returns DurationInterval based on value and unit.

DurationUnit.microsecond and DurationUnit.millisecond will return

Implementation

static DurationInterval findByUnit(int unitValue, DurationUnit unit) {
  final bool singular = unitValue == 1;

  switch (unit) {
    case DurationUnit.microsecond:
    case DurationUnit.millisecond:
      return DurationInterval.lessThanASecond;
    case DurationUnit.second:
      return singular ? DurationInterval.aSecond : DurationInterval.seconds;
    case DurationUnit.minute:
      return singular ? DurationInterval.aMinute : DurationInterval.minutes;
    case DurationUnit.hour:
      return singular ? DurationInterval.anHour : DurationInterval.hours;
    case DurationUnit.day:
      return singular ? DurationInterval.aDay : DurationInterval.days;
    case DurationUnit.week:
      return singular ? DurationInterval.aWeek : DurationInterval.weeks;
    case DurationUnit.month:
      return singular ? DurationInterval.aMonth : DurationInterval.months;
    case DurationUnit.year:
      return singular ? DurationInterval.aYear : DurationInterval.years;
  }
}