php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61599 Wrong Day of Week
Submitted: 2012-04-02 06:08 UTC Modified: 2013-11-28 16:35 UTC
Votes:7
Avg. Score:4.0 ± 0.9
Reproduced:6 of 7 (85.7%)
Same Version:5 (83.3%)
Same OS:4 (66.7%)
From: grom358_spamkill at yahoo dot com dot au Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 5.3.10 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: grom358_spamkill at yahoo dot com dot au
New email:
PHP Version: OS:

 

 [2012-04-02 06:08 UTC] grom358_spamkill at yahoo dot com dot au
Description:
------------
The 15th October 1582 is a Friday (see 
http://en.wikipedia.org/wiki/Gregorian_calendar). Testing with Python and Java 
confirms this as well. Also checked the Gnome calendar.

The Proleptic Gregorian Calendar (see 
http://en.wikipedia.org/wiki/Proleptic_Gregorian_calendar) just extends the 
Gregorian calendar backwards. I'm assuming PHP is using proleptic calendar, which 
would make 4th october 1582 a monday. But again DateTime gets it wrong.

I made a script to find the breaking point, and it occurs at 31st December 1599. 
It returns it as a Saturday when in fact its a Friday.



Test script:
---------------
<?php
$date = new DateTime();
$date->setDate(1582, 10, 15);
echo $date->format('l, jS F Y') . PHP_EOL;

$date->setDate(1599, 12, 31);
echo $date->format('l, jS F Y') . PHP_EOL;

Expected result:
----------------
Friday, 15th October 1582
Friday, 31st December 1599

Actual result:
--------------
Saturday, 15th October 1582
Saturday, 31st December 1599

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-05-11 15:54 UTC] zhanglijiu at gmail dot com
According to your code,my results is "Saturday, 15th October 1582 Saturday, 31st 
December 1599", there is nothing wrong.

My system is Mac 10.6.8 PHP 5.3.1
 [2012-05-12 23:57 UTC] grom358_spamkill at yahoo dot com dot au
@zhanglijiu it should return Friday so your results confirm this bug
 [2012-05-13 22:29 UTC] grom358_spamkill at yahoo dot com dot au
Just to make it clearer, run the following:
<?php
$date = new DateTime();
$date->setDate(1599, 12, 31);
echo $date->format('l, jS F Y') . PHP_EOL;
$date->setDate(1600, 1, 1);
echo $date->format('l, jS F Y') . PHP_EOL;

You will see there is two saturdays in a row :O
 [2013-05-28 19:47 UTC] paul at paul-robinson dot us
I can confirm this bug, which I originally thought was in Wikimedia.

<?php
 $h = mktime(0, 0, 0, 1, 1, 1600);
 $d = date("F dS, Y", $h) ;
 $w= date("l", $h) ;
 Echo "$d is on a $w<br>";
 $h = mktime(0, 0, 0, 1, 1, 1599);
 $d = date("F dS, Y", $h) ;
 $w= date("l", $h) ;
 Echo "$d is on a $w<br>";
 ?>

Returns:

January 01st, 1600 is on a Saturday
January 01st, 1599 is on a Saturday


January 1, 1599 was a Friday.

I did a few other tests for Wikimedia, you can see how they show up there.

http://en.wikipedia.org/w/index.php?title=Template:X8&oldid=557212409

Another version:

<?php
 $h = mktime(0, 0, 0, 5, 28, 2013);
 $d = date("F dS, Y", $h) ;
 $w= date("l", $h) ;
 Echo "$d is on a $w, ";
 $h = mktime(0, 0, 0, 1, 1, 2013);
 $d = date("F dS, Y", $h) ;
 $w= date("l", $h) ;
 Echo "$d is on a $w, ";
 $h = mktime(0, 0, 0, 1, 1, 1901);
 $d = date("F dS, Y", $h) ;
 $w= date("l", $h) ;
 Echo "$d is on a $w, ";
 $h = mktime(0, 0, 0, 1, 1, 1900);
 $d = date("F dS, Y", $h) ;
 $w= date("l", $h) ;
 Echo "$d is on a $w, ";
 $h = mktime(0, 0, 0, 1, 1, 1601);
 $d = date("F dS, Y", $h) ;
 $w= date("l", $h) ;
 Echo "$d is on a $w, ";
 $h = mktime(0, 0, 0, 1, 1, 1600);
 $d = date("F dS, Y", $h) ;
 $w= date("l", $h) ;
 Echo "$d is on a $w<br>";
 $h = mktime(0, 0, 0, 1, 1, 1599);
 $d = date("F dS, Y", $h) ;
 $w= date("l", $h) ;
 Echo "$d is on a $w, ";
 $h = mktime(0, 0, 0, 1, 1, 1598);
 $d = date("F dS, Y", $h) ;
 $w= date("l", $h) ;
 Echo "$d is on a $w<br>";

 ?>

Results:
May 28th, 2013 is on a Tuesday, January 01st, 2013 is on a Tuesday, January 01st, 1901 is on a Tuesday, January 01st, 1900 is on a Monday, January 01st, 1601 is on a Monday, January 01st, 1600 is on a Saturday
January 01st, 1599 is on a Saturday, January 01st, 1598 is on a Friday

Today, 2013, 1901, 1900, 1601 and 1600 are correct.
1599 and 1598 are incorrect. 1599 was a Friday, 1598 was a Thursday.
 [2013-05-28 19:50 UTC] paul at paul-robinson dot us
This was reported (in error) to Wikimedia for their Wikipedia software, the bug number is 48907:

https://bugzilla.wikimedia.org/show_bug.cgi?id=48907
 [2013-11-28 16:35 UTC] derick@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: derick
 [2013-11-28 16:35 UTC] derick@php.net
The fix for this bug has been committed.

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/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Nov 23 08:01:28 2024 UTC