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

 ID:               33957
 User updated by:  paul at stunning-stuff dot com
 Reported by:      paul at stunning-stuff dot com
 Summary:          gmdate('W')/date('W') sometimes returns wrong week
                   number.
 Status:           Closed
 Type:             Bug
 Package:          Date/time related
 Operating System: *
 PHP Version:      5CVS-2005-08-02
 Assigned To:      derick

 New Comment:

Hi Warwick,



The 1st week of a year does not necessarily start on the first of
January 

under the rules of ISO8601. I checked your examples and they seemed
fine. 

Please read up on ISO8601.



-Paul


Previous Comments:
------------------------------------------------------------------------
[2010-05-19 04:06:11] wps at wwe dot com

date('W', $timestamp) fails to return "01" for some January 1st years on
PHP version 5.3.2 and 5.2.8 on CentOS and Windows.





$year = 1970;

$month = 1;

$day = 1;



while ($year <= 2028) {

  $timestamp = mktime(12, 0, 0, $month, $day, $year);

  print $year . " :: " . date('W', $timestamp). " :: " . date('D',
$timestamp) . "\n</br>";

  $year++;

}



Expect 01 for every year

but instead get

1970 :: 01 :: Thu

1971 :: 53 :: Fri

1972 :: 52 :: Sat

1973 :: 01 :: Mon

1974 :: 01 :: Tue

1975 :: 01 :: Wed

1976 :: 01 :: Thu

1977 :: 53 :: Sat

1978 :: 52 :: Sun

...

2020 :: 01 :: Wed

2021 :: 53 :: Fri

2022 :: 52 :: Sat

2023 :: 52 :: Sun

2024 :: 01 :: Mon

2025 :: 01 :: Wed

2026 :: 01 :: Thu

2027 :: 53 :: Fri

2028 :: 52 :: Sat



1st falling on Friday returns 53 

1st falling on Saturday/Sunday return 52





Checked dates using

http://www.tuxgraphics.org/toolbox/cal_year.html





Warwick Shaw

------------------------------------------------------------------------
[2005-08-31 16:31:52] der...@php.net

This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.



------------------------------------------------------------------------
[2005-08-02 16:45:08] paul at stunning-stuff dot com

Thanks for your quick reply and thanks for doing such a great job on
PHP. You dev's really make this the best open source language today.



I hope you are able to solve this problem (I'm sure you will). One more
note though: This problem should reoccur every 28 years before and after
1992. This might help you in your testing.



Thanks,



Paul van der Maas

---

www.stunning-stuff.com

------------------------------------------------------------------------
[2005-08-02 16:22:09] der...@php.net

Indeed a bug, will have a look at it - thanks for the reproducable case.

------------------------------------------------------------------------
[2005-08-02 16:19:09] paul at stunning-stuff dot com

Here is some example code to reproduce the problem:



<?php



$timestamp = gmmktime(12, 0, 0, 12, 28, 1992);

echo 'Week number for ' . gmdate('D M d, Y H:i:s', $timestamp) . ': ' .
gmdate('W', $timestamp) . '<br>';



$timestamp = gmmktime(12, 0, 0, 12, 29, 1992);

echo 'Week number for ' . gmdate('D M d, Y H:i:s', $timestamp) . ': ' .
gmdate('W', $timestamp) . '<br>';



$timestamp = gmmktime(12, 0, 0, 12, 30, 1992);

echo 'Week number for ' . gmdate('D M d, Y H:i:s', $timestamp) . ': ' .
gmdate('W', $timestamp) . '<br>';



$timestamp = gmmktime(12, 0, 0, 12, 31, 1992);

echo 'Week number for ' . gmdate('D M d, Y H:i:s', $timestamp) . ': ' .
gmdate('W', $timestamp) . '<br>';



$timestamp = gmmktime(12, 0, 0, 12, 28, 2020);

echo 'Week number for ' . gmdate('D M d, Y H:i:s', $timestamp) . ': ' .
gmdate('W', $timestamp) . '<br>';



$timestamp = gmmktime(12, 0, 0, 12, 29, 2020);

echo 'Week number for ' . gmdate('D M d, Y H:i:s', $timestamp) . ': ' .
gmdate('W', $timestamp) . '<br>';



$timestamp = gmmktime(12, 0, 0, 12, 30, 2020);

echo 'Week number for ' . gmdate('D M d, Y H:i:s', $timestamp) . ': ' .
gmdate('W', $timestamp) . '<br>';



$timestamp = gmmktime(12, 0, 0, 12, 31, 2020);

echo 'Week number for ' . gmdate('D M d, Y H:i:s', $timestamp) . ': ' .
gmdate('W', $timestamp) . '<br>';



?>



Expected result:



Week number for Mon Dec 28, 1992 12:00:00: 53

Week number for Tue Dec 29, 1992 12:00:00: 53

Week number for Wed Dec 30, 1992 12:00:00: 53

Week number for Thu Dec 31, 1992 12:00:00: 53

Week number for Mon Dec 28, 2020 12:00:00: 53

Week number for Tue Dec 29, 2020 12:00:00: 53

Week number for Wed Dec 30, 2020 12:00:00: 53

Week number for Thu Dec 31, 2020 12:00:00: 53



Actual result:



Week number for Mon Dec 28, 1992 12:00:00: 1

Week number for Tue Dec 29, 1992 12:00:00: 1

Week number for Wed Dec 30, 1992 12:00:00: 1

Week number for Thu Dec 31, 1992 12:00:00: 1

Week number for Mon Dec 28, 2020 12:00:00: 1

Week number for Tue Dec 29, 2020 12:00:00: 1

Week number for Wed Dec 30, 2020 12:00:00: 1

Week number for Thu Dec 31, 2020 12:00:00: 1



Check
http://www.timeanddate.com/calendar/custom.html?year=1992&month=12&typ=1&display=1&wno=1
and
http://www.timeanddate.com/calendar/custom.html?year=2020&month=12&typ=1&display=1&wno=1
to see these expected results confirmed.



Sorry for the bulky post, but this way there is no room for
misinterpretation.



Thanks,



Paul van der Maas

---

www.stunning-stuff.com

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


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    http://bugs.php.net/bug.php?id=33957


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

Reply via email to