getIsoWeekNumber function
Implementation
int getIsoWeekNumber(DateTime date) {
// Get the Thursday of the current week (ISO week starts near the closest Thursday)
DateTime thursdayOfCurrentWeek = date.add(Duration(days: (4 - date.weekday)));
// Get January 4th of the year (since ISO weeks always start around this date)
DateTime firstThursdayOfYear = DateTime(thursdayOfCurrentWeek.year, 1, 4);
// Find the Thursday of the first week of the year
DateTime firstWeekThursday = firstThursdayOfYear.add(Duration(days: (4 - firstThursdayOfYear.weekday)));
// Calculate the difference in days between the current week's Thursday and the year's first week Thursday
int weekNumber = ((thursdayOfCurrentWeek.difference(firstWeekThursday).inDays) ~/ 7) + 1;
return weekNumber;
}