Bug #65730 [Opn->Nab]: DateTime::format('W') returns wrong week number
| From: | rasmus@php.net | Date: | Sat, 21 Sep 2013 14:33:53 +0000 |
| Subject: | Bug #65730 [Opn->Nab]: DateTime::format('W') returns wrong week number | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-181727@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=65730&edit=1
ID: 65730
Updated by: rasmus@php.net
Reported by: glavic at gmail dot com
Summary: DateTime::format('W') returns wrong week number
-Status: Open
+Status: Not a bug
Type: Bug
Package: Date/time related
Operating System: ALL
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
PHP uses the ISO 8601 standard for day, month and week numbers. This is pretty
clearly documented and if you read ISO 8601 it states that the first week of the
year is "the week with the year's first Thursday in it" and since ISO 8601 weeks
start on Mondays, it is quite normal for the first ISO week to contain days from
a previous year. If they didn't then it would be impossible to consistently start
weeks on Mondays since Jan.1 is not always a Monday. If you apply the ISO 8601
definition to the dates in question here you will find PHP is quite correct here.
Previous Comments:
------------------------------------------------------------------------
[2013-09-21 11:04:29] glavic at gmail dot com
Description:
------------
DateTime::format('W') returns wrong week number when date is 2013-12-30 or 2013-12-31.
Test script:
---------------
<?php
$dt = new DateTime;
for ($w = 52; $w <= 54; $w++) {
$dt->setISODate(2013, $w);
print_r($dt);
echo $dt->format('Y W') . "\n\n";
}
# see this script running on all php versions http://3v4l.org/9aua5
Expected result:
----------------
DateTime Object
(
[date] => 2013-12-23 11:02:12
[timezone_type] => 3
[timezone] => UTC
)
2013 52
DateTime Object
(
[date] => 2013-12-30 11:02:12
[timezone_type] => 3
[timezone] => UTC
)
2014 01 # or 2013 53, but surely not 2013 01 !!!
DateTime Object
(
[date] => 2014-01-06 11:02:12
[timezone_type] => 3
[timezone] => UTC
)
2014 02
Actual result:
--------------
DateTime Object
(
[date] => 2013-12-23 11:02:12
[timezone_type] => 3
[timezone] => UTC
)
2013 52
DateTime Object
(
[date] => 2013-12-30 11:02:12
[timezone_type] => 3
[timezone] => UTC
)
2013 01
DateTime Object
(
[date] => 2014-01-06 11:02:12
[timezone_type] => 3
[timezone] => UTC
)
2014 02
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=65730&edit=1