ID: 24683 Comment by: russell+php dot net at loosenut dot com Reported By: s dot vanvelthem at ibelgique dot com Status: Bogus Bug Type: Date/time related Operating System: Redhat Linux 9 PHP Version: 4.3.2 New Comment:
The PHP documentation on this (ie. date( "W" ) ) says: "ISO-8601 week number of year, weeks starting on Monday (added in PHP 4.1.0)" At best, this is deceptive and should be better documented. Realistically, I think it's really a bug in PHP, at least for the idea that returning "week 1" for Dec 28-31 of AN ENUMERATED YEAR is clearly contradictory to "Jan 1" of that very same year. Here's what PHP returns for 2003/12, sequential days: 26th: DOW = Fri WOY = 52 DOW # 5 27th: DOW = Sat WOY = 52 DOW # 6 28th: DOW = Sun WOY = 52 DOW # 0 29th: DOW = Mon WOY = 1 DOW # 1 30th: DOW = Tue WOY = 1 DOW # 2 31st: DOW = Wed WOY = 1 DOW # 3 ...also, this now makes date math difficult, as try to find the difference (in weeks) between 12/30/2003 and 12/23/2003, for example, would seem to be "-51" instead of "1" as you might expect. Furthermore, ISO8601 would seem to state: "Week date is [...] an alternative date representation used in many commercial and industrial applications. It is: YYYY-Www-D where YYYY is the Year in the Gregorian calendar, ww is the week of the year between 01 (the first week) and 52 or 53 (the last week), and D is the day in the week between 1 (Monday) and 7 (Sunday). Example: 2003-W14-2 represents the second day of the fourteenth week of 2003. " ref: http://www.iso.org/iso/en/prods-services/popstds/datesandtime.html ...seeming to clearly indicate, at a minimum: 1) The week of a given year can/should roll to "53" 2) Sunday should be "7" rather than "0" Previous Comments: ------------------------------------------------------------------------ [2003-07-17 10:34:00] [EMAIL PROTECTED] The result from date() is correct -- the date() formats do not include one for the year corresponding to the ISO8601 week number (perhaps this should be a feature request?). However, strftime() does -- see http://www.php.net/strftime, and look for the %g and %G conversion specifiers. ------------------------------------------------------------------------ [2003-07-17 05:13:21] s dot vanvelthem at ibelgique dot com My english is too bad to understand thoroughly the document (http://www.cl.cam.ac.uk/~mgk25/iso-time.html). But I suspect the function date is incorrect : date ('Y-W', '2003-12-31') returns "2003-1". Ok for week 1, but should return "2004-1", isn't it? In PHP4.2.3 this function returned "2003-53". If you take a look at Mysql doc (http://www.mysql.com/doc/en/Date_and_time_functions.html) and the function week, I've tested : select week('2003-12-31', 3); -> 1 (as PHP does) select date_format('2003-12-31', '%Y-%v') -> returns '2003-1' (it's not what I want to have) select date_format('2003-12-31', '%x-%v') -> returns '2004-1' (OK that's what I wanted!!!). In MySQL you have a supplementary 'format' character for year -> %x used in conjunction with %v (ISO8601 week number). Maybe it would be nice if we have it too in PHP. I've looked in the manual but I didn't find this feature. ------------------------------------------------------------------------ [2003-07-16 21:16:55] [EMAIL PROTECTED] It actually works correctly now. >From http://www.cl.cam.ac.uk/~mgk25/iso-time.html : "In commercial and industrial applications (delivery times, production plans, etc.), especially in Europe, it is often required to refer to a week of a year. Week 01 of a year is per definition the first week that has the Thursday in this year, which is equivalent to the week that contains the fourth day of January. In other words, the first week of a new year is the week that has the majority of its days in the new year. Week 01 might also contain days from the previous year and the week before week 01 of a year is the last week (52 or 53) of the previous year even if it contains days from the new year. A week starts with Monday (day 1) and ends with Sunday (day 7). For example, the first week of the year 1997 lasts from 1996-12-30 to 1997-01-05 and can be written in standard notation as.." ------------------------------------------------------------------------ [2003-07-16 12:08:50] s dot vanvelthem at ibelgique dot com Description: ------------ In PHP4.3.2, the function date('W', $timestamp) behaves differently from PHP4.2.3 concerning the ISO8601 dates For example (timestamps has been written in simple form for readablility), date('W', '2003-12-31') reports 1 in PHP4.3.2 (incorrect? Mysql returns the same result) reports 53 in PHP4.2.3 (should be the correct behaviour?) (ISO8601 weeks starting on Monday, so i think you could sometimes have a 53rd week in the year?). It's difficult to differenciate same week between years as date('Y-W', '2003-12-31') reports '2003-1' Sorry for my english, Thanks for your time. Seb Reproduce code: --------------- $timestamp = strtotime("2003-12-31"); echo date('Y-W', $timestamp); > outputs '2003-1' ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=24683&edit=1