tryParseTime static method
Attempts to parse a string representation of a time.
Implementation
static XPathDateTime? tryParseTime(String value) {
final match = _timeRegExp.firstMatch(value);
if (match == null) return null;
final tz = _parseTimezoneGroup(match);
if (!tz.valid) return null;
final hr = int.parse(match.namedGroup('hour')!);
final mn = int.parse(match.namedGroup('minute')!);
final scDouble = double.parse(match.namedGroup('second')!);
final (:second, :millisecond, :microsecond) = _splitSeconds(scDouble);
if (!_validateDateTime(1970, 1, 1, hr, mn, scDouble)) return null;
if (hr == 24) {
return XPathDateTime.time(0, 0, 0, 0, 0, tz.offset);
}
return XPathDateTime.time(
hr,
mn,
second,
millisecond,
microsecond,
tz.offset,
);
}