formatRange function

String formatRange(
  1. DateRange? range
)

Implementation

String formatRange(DateRange? range) {
  if (range == null) return '';
  if (range.start == null && range.end == null) {
    return _DateFormatterMessages._allTimeMsg;
  }
  if (range.start == range.end) return formatDate(range.start, _dateFormat);

  if (range.start == null ||
      range.end == null ||
      range.start!.year != range.end!.year) {
    final format = _rangeEndpointFormat(Intl.defaultLocale);
    return _DateFormatterMessages._formatArbitraryRange(
        formatDate(range.start, format), formatDate(range.end, format));
  }
  if (range.start!.month != range.end!.month) {
    return _DateFormatterMessages._formatSameYearRange(
        range.start!.format(_monthFormat),
        range.start!.format(_dayFormat),
        range.end!.format(_monthFormat),
        range.end!.format(_dayFormat),
        range.start!.format(_yearFormat));
  }
  return _DateFormatterMessages._formatSameMonthRange(
      range.start!.format(_monthFormat),
      range.start!.format(_dayFormat),
      range.end!.format(_dayFormat),
      range.start!.format(_yearFormat));
}