Bug #67706 [Asn->Dup]: strtotime goes wrong for "last day of February next year"

[email protected]
Newsgroups php.bugs
Message-ID <[email protected]>
Edit report at https://bugs.php.net/bug.php?id=67706&edit=1

 ID:                 67706
 Updated by:         [email protected]
 Reported by:        greenrover33 at gmail dot com
 Summary:            strtotime goes wrong for "last day of February next
                     year"
-Status:             Assigned
+Status:             Duplicate
 Type:               Bug
 Package:            Date/time related
 Operating System:   Linux/Independent
 PHP Version:        5.6Git-2014-07-29 (Git)
-Assigned To:        derick
+Assigned To:        
 Block user comment: N
 Private report:     N

 New Comment:

Long since fixed with bug #69336.


Previous Comments:
------------------------------------------------------------------------
[2017-03-29 20:13:28] php-bugs at allenjb dot me dot uk

This issue appears to be fixed as of 5.6.8: https://3v4l.org/a1CVu

------------------------------------------------------------------------
[2014-07-29 11:54:00] greenrover33 at gmail dot com

Workaround in PHP

$string = 'last day of february next year';
$matches = array();
if (preg_match('/ of (?<month_name>january|february|march|april|may|june|july|august|september|october|november|december|jan|feb|mar|apr|may|jun|jul|aug|sep|sept|oct|nov|dec)\s*(?<year>(([0-9]{2,4})|((last|this|next|(\-[0-9]+)|(\+[0-9]+)) years?)?))?/i', $string, $matches)) {
    if (empty($matches['year'])) {
        $string .= ' ' . date('Y');
    } elseif (!is_numeric($matches['year'])) {
        if ($now > 0) {
            $string = str_replace($matches['year'], date('Y', strtotime($matches['year'], $now)), $string);
        } else {
            $string = str_replace($matches['year'], date('Y', strtotime($matches['year'])), $string);
        }
    }
}

------------------------------------------------------------------------
[2014-07-29 10:39:57] [email protected]

You're right - this needs looking at.

------------------------------------------------------------------------
[2014-07-29 09:48:17] greenrover33 at gmail dot com

I have seen this Report:
https://bugs.php.net/bug.php?id=50048

But different to them is, that i give a relative year.

Normaly it should translate the date first before it tries to resolve the day.

------------------------------------------------------------------------
[2014-07-29 09:42:40] greenrover33 at gmail dot com

Description:
------------
strtotime goes wrong for "last day of February next year"

"last day of February next year"  got the 31.03 the last day of march as result.

Test script:
---------------
$bug_from = 1406625924; // 29.07.2014 11:25
echo strftime('%d.%m.%Y %H:%M:%S', strtotime('last day of February next year', $bug_from));
echo ' != ';
echo strftime('%d.%m.%Y %H:%M:%S', strtotime('last day of February 2015', $bug_from));
die();

Expected result:
----------------
28.02.2015 00:00:00 != 28.02.2015 00:00:00

Actual result:
--------------
31.03.2015 00:00:00 != 28.02.2015 00:00:00


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=67706&edit=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.