ID:               40271
 Updated by:       [EMAIL PROTECTED]
 Reported By:      slomo at sonarkollektiv dot de
 Status:           Feedback
 Bug Type:         Date/time related
 Operating System: Mac OS X 10.4.8
 PHP Version:      5.2.0
 New Comment:

You can also just use "strtotime('2007W011')"; for Monday "1", of Week
1 ("01") of year 2007 ("2007").


Previous Comments:
------------------------------------------------------------------------

[2007-01-29 11:33:36] [EMAIL PROTECTED]

And please do not forget about expected and actual results.
Thank you.

------------------------------------------------------------------------

[2007-01-29 11:32:05] [EMAIL PROTECTED]

Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.



------------------------------------------------------------------------

[2007-01-29 11:20:44] slomo at sonarkollektiv dot de

Description:
------------
I was looking for a neat solution for the task "get the date 
for a given weeknumber and weekyear". I thought I got it, but 
there is a strange behaviour if (and only if) week no. is 1 
and 4th of January is already a monday. See my code to 
reproduce the results, it's quite confusing.

The idea was:
- 4th of January is always in week no. 1
- add the missing weeks
- make it a monday of that week acording to the GNU Date Input 
Formats syntax descibed at http://www.gnu.org/software/tar/
manual/html_node/tar_114.html#SEC114

So either me or PHP still does not get it right.

Reproduce code:
---------------
function MondayOfWeek($year, $week) { 
        return strtotime("$year-01-04 UTC + " . ($week-1) . ' week last
monday');
} 

for ($y = 1998; $y < 2012; $y++) {
        for ($w = 1; $w < 53; $w++) {
                $start = MondayOfWeek($y, $w);
                $end   = strtotime("+6 day", $start);
                
                echo "KW $w/$y: " . gmstrftime('%A, %x %X', $start) . ' - ' .
gmstrftime('%A, %x %X', $end) . " ";
                echo '- reverse check (week/year): ' . gmstrftime('%V/%G', 
$start) .
"\n";
                
                if ($w != gmstrftime('%V', $start) || $y != gmstrftime('%G', 
$start))
{
                        echo "ERROR!\n";
                }
        }
        echo "<hr>\n";
}

Expected result:
----------------
accurate results for every week number and year with always 
the same behaviour ...

Actual result:
--------------
if week no. is 1 and 4th of January is already a monday, the 
function returns timestamps for the "previous week".


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=40271&edit=1

Reply via email to