parseDateRange static method

Map<String, String> parseDateRange(
  1. Object? value
)

Validates and defensively copies an ordered, inclusive date range.

Implementation

static Map<String, String> parseDateRange(Object? value) {
  if (value is! Map ||
      value.length != 2 ||
      !value.containsKey('start') ||
      !value.containsKey('end')) {
    throw const FormatException('Expected a range with start and end dates.');
  }
  final start = parseDate(value['start']);
  final end = parseDate(value['end']);
  if (end.isBefore(start)) {
    throw const FormatException('Range end cannot be before start.');
  }
  return Map<String, String>.unmodifiable({
    'start': value['start'] as String,
    'end': value['end'] as String,
  });
}