SecondPeriod constructor

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

A class that implements a period type of a second.

Implementation

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