startDate method
Returns the next date that fits the dayInYear.
- If the current
date- DayInYear.dayInYear is equal tozero,dateis returned. - 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 startDate(DateTime date) {
if (valid(date)) return date;
final thisYearDay = date.firstDayOfYear
.add(Duration(days: dayInYear - 1))
.clamp(max: date.lastDayOfYear);
if (date.dayInYear <= dayInYear) return thisYearDay;
return next(date);
}