For years where the 28th of December of the previous year falls on a Monday (i.e. 2010) the date_iso_week_range() function is off by a week. Example:

$d = date_make_date('2010-12-28');
print $d->format('W') . "\n";
list($begin, $end) = date_iso_week_range(52, 2010);
print $begin->format('r') . "\n";
print $end->format('r') . "\n";

Which prints:

52
Mon, 20 Dec 2010 00:00:00 -0800
Mon, 27 Dec 2010 00:00:00 -0800

According to this helpful page we can calculate the 1st week of the ISO year "as being the week which contains the first Thursday of the Calendar year"

I've attached a patch which uses that logic and it now returns correct dates:

52
Mon, 27 Dec 2010 00:00:00 -0800
Sun, 02 Jan 2011 23:59:59 -0800

The patch, as you notice from the above output, also makes sure the end date is the last second of the last day of the week which seems more accurate than midnight on the monday of the next week.

Comments

maarten.delbaere’s picture

Issue summary: View changes
StatusFileSize
new946 bytes

This issue still exists in 7.x-2.8. When the 28 December is on a Monday it gives problems because of the function:

date_modify('+1 Monday');

When 28 December is a Monday, this should be:

date_modify('Next Week Monday');

I fixed it with the added patch.

medkg15’s picture

The fix in #1 works as expected. Without it, ISO week ranges for all of 2016 are off by one because 12/28/2015 is a Monday.

The underlying cause may be that "+1 Monday" is not a properly formed Relative Format in PHP (although it appears to get the expected result - the next Monday after the date - for all non-Mondays). http://php.net/manual/en/datetime.formats.relative.php The notation being used: "number space? (unit | 'week')" only allows "unit" symbols, which do not include "dayname" symbols such as "Monday".

damienmckenna’s picture

Status: Needs review » Closed (won't fix)

Unfortunately the D6 version of this module is no longer supported, but we appreciate the time you put into this. If this problem is relevant for D7 too, please reopen the issue. Thanks.