firstDayNextMonth static method
Returns the first day of the month following the given month and year,
or null if month is invalid.
The result is local midnight on the 1st; December rolls into January of the following year. It is built from calendar fields, so daylight-saving changes cannot shift it into the wrong month.
Example:
DateTimeUtils.firstDayNextMonth(month: 12, year: 2023); // 2024-01-01
Audited: 2026-06-12 11:26 EDT
Implementation
@useResult
static DateTime? firstDayNextMonth({required int month, required int year}) {
// ref: https://stackoverflow.com/questions/61881850/sort-list-based-on-boolean
// ref: https://stackoverflow.com/questions/67144785/flutter-dart-datetime-max-min-value
if (month < DateConstants.minMonth || month > DateConstants.maxMonth) {
// invalid
return null;
}
// Field arithmetic (month 13 rolls into January). Adding fixed 24-hour days
// to the 28th landed on the 31st at 23:00 across a late-month DST fall-back
// and returned the 1st of the SAME month.
return DateTime(year, month + 1);
}