dateTimes function

Generator<DateTime> dateTimes({
  1. DateTime? min,
  2. DateTime? max,
})

Generates dates and times between min and max inclusive.

UTC DateTimes, to microsecond precision, which both sides agree on. They carry no zone in any meaningful sense -- the engine draws a naive date and time, and UTC is how Dart says "no zone applied". A generator of instants in a particular zone is this one mapped into it.

The bounds are read the same way dates reads them: as the wall clock a DateTime displays, not as the instant it stands for. A local bound and a UTC one that show the same numbers mean the same bound here, and two that show different numbers are different bounds even where they name the same instant. Anything else would put a generator's meaning at the mercy of the machine's time zone, which is not a thing a counterexample should depend on.

Values shrink toward 2000-01-01 midnight.

Implementation

Generator<DateTime> dateTimes({DateTime? min, DateTime? max}) {
  final low = min == null
      ? (date: _earliestDate, time: _startOfDay)
      : _dateTimeOf(min);
  final high = max == null
      ? (date: _latestDate, time: _lastMicrosecond)
      : _dateTimeOf(max);
  // The encoded pair rather than the arguments, and whether or not both were
  // given. What the engine is handed is the wall clock, so that is what has
  // to be in order: comparing the instants instead lets a UTC minimum and a
  // local maximum pass here and invert there. And a single bound is still a
  // bound -- a minimum past year 9999 inverts the range against the default
  // maximum, with no second argument to compare it to.
  if (_dateTimeValue(low).compareTo(_dateTimeValue(high)) > 0) {
    throw ArgumentError.value(min, 'min', 'exceeds max ($max)');
  }
  return _DateTimeGenerator(low, high);
}