tryParseYearMonth static method

XPathDuration? tryParseYearMonth(
  1. String value
)

Attempts to parse a string representation of a yearMonthDuration.

Implementation

static XPathDuration? tryParseYearMonth(String value) {
  final match = _yearMonthDurationRegExp.firstMatch(value);
  if (match == null) return null;

  if (match.group(2) == null && match.group(3) == null) return null;

  final negative = match.group(1) == '-';
  final years = int.tryParse(match.group(2) ?? '0') ?? 0;
  final months = int.tryParse(match.group(3) ?? '0') ?? 0;
  final total = (years * 12 + months) * (negative ? -1 : 1);
  return XPathDuration.yearMonth(total);
}