weekOfYear method

int weekOfYear ()

Week number in year. Week 1 has the first Thursday.

Implementation

int weekOfYear() {
  assert((1 <= month) && (month <= 12));
  assert((1 <= day) && (day <= 31));
  int woy = (dayOfYear() + 10 - weekday) ~/ 7;
  if (woy < 1) {
    return DateTime(year - 1, 12, 31).weekOfYear();
  }
  if (woy == 53) {
    if (DateTime(year + 1, 1, 1).weekday <= 4) {
      return 1;
    }
  }
  return woy;
}