getUnitByName function
Implementation
Unit? getUnitByName(String? name, [Unit? def]) {
if (name == null) return def;
name = name.toLowerCase().trim();
if (name.isEmpty) return def;
switch (name) {
case 'y':
case 'year':
case 'years':
return Unit.years;
case 'q':
case 'quarter':
case 'quarters':
return Unit.quarters;
case 'month':
case 'months':
return Unit.months;
case 'w':
case 'week':
case 'weeks':
return Unit.weeks;
case 'd':
case 'day':
case 'days':
return Unit.days;
case 'h':
case 'hr':
case 'hrs':
case 'hour':
case 'hours':
return Unit.hours;
case 'm':
case 'min':
case 'minute':
case 'minutes':
return Unit.minutes;
case 's':
case 'sec':
case 'second':
case 'seconds':
return Unit.seconds;
case 'ms':
case 'milli':
case 'millis':
case 'millisecond':
case 'milliseconds':
return Unit.milliseconds;
case 'µs':
case 'µsec':
case 'us':
case 'usec':
case 'micro':
case 'micros':
case 'microsecond':
case 'microseconds':
return Unit.microseconds;
default:
return def;
}
}