Bug #66980 [Nab]: Last day of Fenruary
| From: | ab@php.net | Date: | Wed, 02 Apr 2014 15:34:18 +0000 |
| Subject: | Bug #66980 [Nab]: Last day of Fenruary | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-185045@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=66980&edit=1
ID: 66980
Updated by: ab@php.net
Reported by: tm8544 at hotmail dot com
Summary: Last day of Fenruary
Status: Not a bug
Type: Bug
Package: Date/time related
Operating System: Windows 7
PHP Version: 5.5.10
Block user comment: N
Private report: N
New Comment:
It makes more sense to use the 1st of a month, so here's your snippet modified to work
correctly
<?php
$months = array("january", "february", "march", "april",
"may", "june", "july", "august", "september",
"october", "november", "december");
foreach ($months as $i => $month) {
$string = "last day of " . $month;
echo $month ." - " . date("j.n.Y", strtotime($string,
mktime(0,0,0,($i+1),1,2014))) . "\r\n";
}
Previous Comments:
------------------------------------------------------------------------
[2014-04-02 15:28:45] ab@php.net
Wait a minute, but that is correct. It just moves up to the next valid "last day of ". The
same way if you try
echo date("j.n.Y", mktime(0,0,0,2,29,2014)) . "\r\n";
you will get
1.3.2014
because Feb 2014 has 28 days, not 29.
Btw. the behavior is consistent with Linux as well.
Thanks
------------------------------------------------------------------------
[2014-04-02 15:05:56] ab@php.net
Yes, now I can reproduce it with the change you mentioned, thanks.
<?php
$months = array("january", "february", "march", "april",
"may", "june", "july", "august", "september",
"october", "november", "december");
foreach ($months as $month) {
$string = "last day of " . $month;
echo $month ." - " . date("j.n.Y", strtotime($string,
mktime(0,0,0,3,29,2014))) . "\n";
}
------------------------------------------------------------------------
[2014-04-02 12:59:02] tm8544 at hotmail dot com
This bug depends on the date when you run the snippet.
Optional second parameter of strtotime ( string $time [, int $now = time() ] ) plays key role in
this bug.
As I wrote in the first comment, I noticed this bug at 29th of March.
If I run the code today, there seems to be no problem.
Try these two ways to test this bug:
1) change your computer's date to 29.3.2014 and run the snippet, or
2) replace line 6 of the snippet with the following:
echo $month ." - " . date("j.n.Y", strtotime($string,
mktime(0,0,0,3,29,2014)));
You might also be interested to test with changing line 6 to
echo $month ." - " . date("j.n.Y", strtotime($string, mktime(0,0,0,3,31,2014)));
Besides February, note also April, June, September and November.
------------------------------------------------------------------------
[2014-04-02 12:07:54] ab@php.net
Hi, thanks for reporting. I cannot reproduce it with 5.5.10 or 5.5-dev branch with your snippet.
Both first and last day look correct. Could you please give some more details on how you invoke it,
maybe timezone and so on? To exclude it's a configuration error maybe you could try it on some
other machine.
Thanks.
------------------------------------------------------------------------
[2014-03-29 08:43:23] tm8544 at hotmail dot com
As you can see, this problem was produced on 29.3.2014.
I assume that if it was tested on 31.3.2014, also last days of april, june, september and november
would have been wrong.
It is possible to get around this by using
strtotime($string, mktime(0,0,0,date("n"),1)) instead of strtotime($string) in line 6 of
the test script, but my point is that "last day of february" is a known fact for each
year, and the result of the code shall not depend on the date when it is executed.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=66980
--
Edit this bug report at https://bugs.php.net/bug.php?id=66980&edit=1