yearOfISOWeek property
int
yearOfISOWeek
Returns the year for this Date ISO week
Implementation
int get yearOfISOWeek {
final woy = (_ordinalDate - weekday + 10) ~/ 7;
// If the week number equals zero, it means that the given date belongs to the preceding (week-based) year.
if (woy == 0) {
// The 28th of December is always in the last week of the year
return year - 1;
}
// If the week number equals 53, one must check that the date is not actually in week 1 of the following year
if (woy == 53 &&
DateTime(year).weekday != DateTime.thursday &&
DateTime(year, 12, 31).weekday != DateTime.thursday) {
return year + 1;
}
return year;
}