getWeekNumber static method
Returns the week number of the given DateTime within the year.
Implementation
static int getWeekNumber(DateTime date) {
final firstDayOfYear = DateTime(date.year, 1, 1);
final firstSundayOfYear = firstDayOfYear.roundToLastDayOfWeek();
final lastWeekDay = date.roundToLastDayOfWeek();
final diff = lastWeekDay.difference(firstSundayOfYear).inDays;
return (diff ~/ 7) + 1;
}