toTimeSpan method
Implementation
TimeSpan toTimeSpan(num amount) {
switch (this) {
case TimeSpanUnit.year:
return TimeSpan(years: amount.toIntSafe());
case TimeSpanUnit.month:
return TimeSpan(months: amount.toIntSafe());
case TimeSpanUnit.week:
return TimeSpan(weeks: amount.toIntSafe());
case TimeSpanUnit.day:
return TimeSpan(days: amount.toIntSafe());
case TimeSpanUnit.hour:
return TimeSpan(hours: amount.toIntSafe());
case TimeSpanUnit.minute:
return TimeSpan(minutes: amount.toIntSafe());
case TimeSpanUnit.second:
return TimeSpan.ofParts(
_newTimeSpanList(TimeSpanUnit.second, amount.toDouble()));
case TimeSpanUnit.millisecond:
final amt = _secondsDecimal(millis: amount);
return TimeSpan.ofParts(
_newTimeSpanList(TimeSpanUnit.second, amt.toDouble()));
case TimeSpanUnit.microsecond:
final amt = _secondsDecimal(micros: amount);
return TimeSpan.ofParts(
_newTimeSpanList(TimeSpanUnit.second, amt.toDouble()));
default:
return (throw Exception("Invalid time span unit: ${this}"));
}
}