durationOf function
Implementation
Duration? durationOf(final TimeUnit? timeUnit, int? timeAmount) {
if (timeUnit == null && timeAmount == null) {
return null;
} else {
timeAmount ??= 1;
switch (timeUnit?.value) {
case "DAYS":
return Duration(days: timeAmount);
case "HOURS":
return Duration(hours: timeAmount);
case "MINUTES":
return Duration(minutes: timeAmount);
case "SECONDS":
return Duration(seconds: timeAmount);
case "MILLISECONDS":
return Duration(milliseconds: timeAmount);
case "MICROSECONDS":
return Duration(microseconds: timeAmount);
default:
throw Exception("Unable to convert from $timeUnit units");
}
}
}