timeDifference property

TimeDifference get timeDifference

Calculates the difference in time by converting it into a valid time unit and returns a TimeDifference.

Implementation

TimeDifference get timeDifference {
  // If the closest time unit is second
  if (validUnitSecond) {
    final unit = LitTimeUnit.second;

    return TimeDifference(
      value: _calcTimeDiffValue(unit),
      unit: unit,
    );
  }
  // If the closest time unit is minute
  if (validUnitMinute) {
    final unit = LitTimeUnit.minute;

    return TimeDifference(
      value: _calcTimeDiffValue(unit),
      unit: unit,
    );
  }
  // If the closest time unit is hour
  if (validUnitHour) {
    final unit = LitTimeUnit.hour;

    return TimeDifference(
      value: _calcTimeDiffValue(unit),
      unit: unit,
    );
  }
  // If the closest time unit is day
  if (validUnitDay) {
    final unit = LitTimeUnit.day;

    return TimeDifference(
      value: _calcTimeDiffValue(unit),
      unit: unit,
    );
  }
  // If the closest time unit is week
  if (validUnitWeek) {
    final unit = LitTimeUnit.week;

    return TimeDifference(
      value: _calcTimeDiffValue(unit),
      unit: unit,
    );
  }
  // If the closest time unit is month
  if (validUnitMonth) {
    final unit = LitTimeUnit.month;

    return TimeDifference(
      value: _calcTimeDiffValue(unit),
      unit: unit,
    );
  }

  // Else the closest time unit is year
  final unit = LitTimeUnit.year;

  return TimeDifference(
    value: _calcTimeDiffValue(unit),
    unit: unit,
  );
}