tryParseDayTime static method
Attempts to parse a string representation of a dayTimeDuration.
Implementation
static XPathDuration? tryParseDayTime(String value) {
final match = _dayTimeDurationRegExp.firstMatch(value);
if (match == null) return null;
if (match.group(2) == null &&
match.group(3) == null &&
match.group(4) == null &&
match.group(5) == null) {
return null;
}
final negative = match.group(1) == '-';
final days = int.tryParse(match.group(2) ?? '0') ?? 0;
final hours = int.tryParse(match.group(3) ?? '0') ?? 0;
final minutes = int.tryParse(match.group(4) ?? '0') ?? 0;
final secondsDouble = double.tryParse(match.group(5) ?? '0') ?? 0.0;
final duration = Duration(
days: days,
hours: hours,
minutes: minutes,
microseconds: (secondsDouble * Duration.microsecondsPerSecond).round(),
);
final totalUs = duration.inMicroseconds * (negative ? -1 : 1);
return XPathDuration.dayTime(totalUs);
}