tryParseYearMonth static method

XPathDateTime? tryParseYearMonth(
  1. String value
)

Attempts to parse a string representation of a gYearMonth.

Implementation

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

  final tz = _parseTimezoneGroup(match);
  if (!tz.valid) return null;

  final yr = int.tryParse(match.namedGroup('year')!);
  if (yr == null) return null;

  final mo = int.parse(match.namedGroup('month')!);

  if (!_validateDateTime(yr, mo, 1, 0, 0, 0.0)) return null;

  return XPathDateTime.yearMonth(yr, mo, tz.offset);
}