Bug #68495 [Opn->Nab]: Weekday calculated incorrectly using $weekDay = date('N', strtotime($date));
| From: | requinix@php.net | Date: | Tue, 25 Nov 2014 08:36:47 +0000 |
| Subject: | Bug #68495 [Opn->Nab]: Weekday calculated incorrectly using $weekDay = date('N', strtotime($date)); | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-188784@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=68495&edit=1
ID: 68495
Updated by: requinix@php.net
Reported by: 8f181bd2 at opayq dot com
Summary: Weekday calculated incorrectly using $weekDay =
date('N', strtotime($date));
-Status: Open
+Status: Not a bug
Type: Bug
Package: Date/time related
Operating System: Windows
PHP Version: 5.5Git-2014-11-25 (Git)
Block user comment: N
Private report: N
New Comment:
Congratulations, you've discovered the limitations of using 32-bit integers for timestamps.
http://en.wikipedia.org/wiki/Year_2038_problem
Unfortunately 64-bit builds for PHP on Windows are currently experimental so there is only one good
solution: use just the DateTime family of classes for dealing with dates in the far future, as they
do not have the problem that haunts the "normal" functions like strtotime() and date().
Previous Comments:
------------------------------------------------------------------------
[2014-11-25 06:40:42] 8f181bd2 at opayq dot com
(edited title)
------------------------------------------------------------------------
[2014-11-25 06:39:20] 8f181bd2 at opayq dot com
Exact PHP version is 5.5.11 (built: Apr 8 2014 15:07:14)
------------------------------------------------------------------------
[2014-11-25 06:25:45] 8f181bd2 at opayq dot com
Description:
------------
Weekday calculated incorrectly for dates in the far future, using $weekDay = date('N',
strtotime($date));
Test script:
---------------
function getWeekday($date)
{
$dateTime = \DateTime::createFromFormat('m/d/Y', $date);
$date = date_format($dateTime, 'm/d/Y');
$weekDay = date('N', strtotime($date));
return $weekDay;
}
$arr = ['01/04/2050' => 'Sun',
'01/09/2050' => 'Tues',
'07/04/2050' => 'Mon',
'04/06/2014' => 'Sun',
'10/22/2014' => 'Wed',
'10/25/2014' => 'Sat',
'11/23/2014' => 'Sun'];
foreach($arr as $date => $shouldBe)
{
echo $date.' is on weekday '.getWeekday($date).' - This should be
'.$shouldBe.'<br/>';
}
Expected result:
----------------
01/04/2050 is on weekday 0 - This should be Sun
01/09/2050 is on weekday 2 - This should be Tues
07/04/2050 is on weekday 1 - This should be Mon
04/06/2014 is on weekday 7 - This should be Sun
10/22/2014 is on weekday 3 - This should be Wed
10/25/2014 is on weekday 6 - This should be Sat
11/23/2014 is on weekday 7 - This should be Sun
Actual result:
--------------
01/04/2050 is on weekday 4 - This should be Sun
01/09/2050 is on weekday 4 - This should be Tues
07/04/2050 is on weekday 4 - This should be Mon
04/06/2014 is on weekday 7 - This should be Sun
10/22/2014 is on weekday 3 - This should be Wed
10/25/2014 is on weekday 6 - This should be Sat
11/23/2014 is on weekday 7 - This should be Sun
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=68495&edit=1