|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 04:00:02 2025 UTC |
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 :OI 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.