dvParseSchemaDuration function
5s, 500ms, 2m, 1h, 1d.
Implementation
Duration dvParseSchemaDuration(String text) {
final RegExpMatch? match = RegExp(
r'^\s*(\d+(?:\.\d+)?)\s*(ms|s|m|h|d)\s*$',
).firstMatch(text);
if (match == null) throw FormatException('Not a duration', text);
final double amount = double.parse(match.group(1)!);
const Map<String, int> micros = <String, int>{
'ms': 1000,
's': 1000000,
'm': 60000000,
'h': 3600000000,
'd': 86400000000,
};
return Duration(microseconds: (amount * micros[match.group(2)]!).round());
}