next method
Returns the next date that fits the dayInYear.
- If the current
date- DayInYear.dayInYear is less than the dayInYear, it's returned the same year with the DayInYear.dayInYear being the dayInYear. - If the current
date- DayInYear.dayInYear is greater than the dayInYear, it's returned the next year with the DayInYear.dayInYear being the dayInYear.
Implementation
@override
DateTime next(DateTime date) {
final thisYearDay = date.firstDayOfYear
.add(Duration(days: dayInYear - 1))
.clamp(max: date.lastDayOfYear)
.add(date.exactTimeOfDay);
if (date.dayInYear < dayInYear) return thisYearDay;
return date
.copyWith(year: date.year + 1)
.firstDayOfYear
.add(Duration(days: dayInYear - 1))
.clamp(max: date.copyWith(year: date.year + 1).lastDayOfYear)
.add(date.exactTimeOfDay);
}