tryParseTimeSpanUnit function

List<TimeSpanUnit> tryParseTimeSpanUnit(
  1. dynamic input
)

Implementation

List<TimeSpanUnit> tryParseTimeSpanUnit(input) {
  if (input is TimeSpanUnit) return [input];
  var lc = "$input".toLowerCase();
  if (lc.isEmpty == true) return [];
  final knownUnit = knownSpanUnits[lc];
  if (knownUnit != null) return [knownUnit];
  if (lc == "m") {
    return [TimeSpanUnit.minute];
  }
  if (lc.length > 3) lc.trimEnd("s");
  final timeSpan = timeSpanUnitOf(input);
  if (timeSpan != null) return [timeSpan];

  return [
    ...TimeSpanUnit.values.where((unit) {
      return unit.index < 7 &&
          (unit.label.startsWith(lc) || unit.shortLabel!.startsWith(lc));
    })
  ];
}