Right now if you call date_iso_week_range(2, 2016) it would return the range [ 04.Jan, 11.Jan ], while this is the FIRST week actually. Looking at the code makes more questions:

$min_date = new DateObject(($year - 1) . '-12-28 00:00:00'); — why 28?
date_modify($min_date, '+1 Monday'); — why monday?

The first week of a year is the first week with Thursday.

I should say, that our calendar on a production website has been broken due to this.

Comments

OnkelTem created an issue.

OnkelTem’s picture

What is about? :

function date_iso_week_range($week, $year) {
  // The start of the year
  $min_date = new DateObject(($year) . '-01-01 00:00:00');
  date_timezone_set($min_date, date_default_timezone_object());

  // Find the first Thursday of the year
  date_modify($min_date, '+1 Thursday');
  // Rewind to the Monday
  date_modify($min_date, '-1 Monday');

  // Jump ahead to the desired week for the beginning of the week range.
  if ($week > 1) {
    date_modify($min_date, '+ ' . ($week - 1) . ' weeks');
  }

  // Move forwards to the last day of the week.
  $max_date = clone($min_date);
  date_modify($max_date, '+6 days');
  return array($min_date, $max_date);
}
OnkelTem’s picture

Also, I don't know where it came from, but +6 is also breaking our website data:

 date_modify($max_date, '+6 days');

Setting back to +7 fixing the issue.