of method

WeekPeriod of(
  1. int year,
  2. int month, {
  3. Weekday firstDayOfWeek = Weekday.monday,
  4. bool utc = true,
})

Returns a WeekPeriod for the week of the given year and month.

Implementation

WeekPeriod of(
  int year,
  int month, {
  Weekday firstDayOfWeek = Weekday.monday,
  bool utc = true,
}) {
  final firstDayOfMonth =
      utc ? DateTime.utc(year, month) : DateTime(year, month);
  switch (this) {
    case first:
      return firstDayOfWeek.weekGenerator.of(firstDayOfMonth);
    case second:
      return firstDayOfWeek.weekGenerator.of(firstDayOfMonth.addDays(7));
    case third:
      return firstDayOfWeek.weekGenerator.of(firstDayOfMonth.addDays(14));
    case fourth:
      return firstDayOfWeek.weekGenerator.of(firstDayOfMonth.addDays(21));
    case last:
      final fourthWeek =
          fourth.of(year, month, firstDayOfWeek: firstDayOfWeek, utc: utc);
      if (fourthWeek.end.date.isBefore(firstDayOfMonth.lastDayOfMonth)) {
        return firstDayOfWeek.weekGenerator
            .of(firstDayOfMonth.lastDayOfMonth);
      } else {
        return fourthWeek;
      }
  }
}