HourPeriod constructor

HourPeriod({
  1. required DateTime start,
  2. required DateTime end,
})

A class that implements a period type of an hour.

Implementation

HourPeriod({required super.start, required super.end})
    : assert(
        end.difference(start) ==
            const Duration(
              minutes: 59,
              seconds: 59,
              milliseconds: 999,
              microseconds: 999,
            ),
        'The difference between start and end must be 59 minutes, 59 '
        'seconds, 999 milliseconds and 999 microseconds',
      ) {
  const microsecond = Duration(microseconds: 1);
  if (duration != const Duration(hours: 1) ||
      !start.isAtSameHourAs(end) ||
      end.add(microsecond).isAtSameHourAs(start)) {
    throw ArgumentError.value(
      end,
      'end',
      'End must be at the same hour as start and must be the last '
          'microsecond of the hour',
    );
  }
}