PHP :: Bug #61599 :: Wrong Day of Week
| Bug #61599 | Wrong Day of Week | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Submitted: | 2012-04-02 06:08 UTC | Modified: | 2013-11-28 16:35 UTC |
|
||||||||||
| 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 | |||||||||||
[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 commits
[2012-05-11 15:54 UTC] zhanglijiu at gmail dot com
[2012-05-12 23:57 UTC] grom358_spamkill at yahoo dot com dot au
[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-11-28 16:35 UTC] derick@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: derick