firstSundayFromWeekInYear function

DateTime firstSundayFromWeekInYear(
  1. int weekNumber,
  2. int year
)

Gets the date of the sunday of a week in a year.

Implementation

DateTime firstSundayFromWeekInYear(int weekNumber, int year) {
  final DateTime weekDay = DateTime(2022).add(Duration(days: (weekNumber - 2) * 7));
  return weekDay.add(Duration(days: (DateTime.sunday - weekDay.weekday) % DateTime.daysPerWeek));
}