weekdayOf method
Returns the DateTime for day of the week of the selected week for the
given year and month.
Implementation
DateTime weekdayOf({
required int year,
required int month,
required Weekday day,
bool utc = true,
}) {
late final DateTime firstDayOfMonth;
if (utc) {
firstDayOfMonth = DateTime.utc(year, month);
} else {
firstDayOfMonth = DateTime(year, month);
}
var weekDay = firstDayOfMonth.nextWeekday(day);
for (final week in [first, second, third, fourth]) {
if (week == this) {
return weekDay;
} else {
weekDay = weekDay.addDays(1).nextWeekday(day);
}
}
if (weekDay.compareTo(firstDayOfMonth.lastDayOfMonth) <= 0) {
return weekDay;
} else {
return weekDay.subtractDays(1).previousWeekday(day);
}
}