MonthPeriod constructor

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

A class that implements a period type of a month.

Implementation

MonthPeriod({required super.start, required super.end})
    : assert(
        end.difference(start) <=
            const Duration(
              days: 30,
              hours: 23,
              minutes: 59,
              seconds: 59,
              milliseconds: 999,
              microseconds: 999,
            ),
        'The difference between start and end must be 30 days, 23 hours, '
        '59 minutes, 59 seconds, 999 milliseconds and 999 microseconds',
      ) {
  const microsecond = Duration(microseconds: 1);
  if (!start.isAtSameMonthAs(end) ||
      end.add(microsecond).isAtSameMonthAs(start) ||
      (start.exactTimeOfDay != Duration.zero) ||
      (end.exactTimeOfDay != end.endOfDay.exactTimeOfDay) ||
      (start.day != 1) ||
      (end.day != end.lastDayOfMonth.day)) {
    throw ArgumentError.value(
      end,
      'end',
      'End must be at the same month as start and must be the last '
          'microsecond of the month',
    );
  }
}