Bug #63222 [Opn->Nab]: DateTime::createFromFormat() wrong with reset and D,l

From: Date: Wed, 14 Jul 2021 11:09:06 +0000
Subject: Bug #63222 [Opn->Nab]: DateTime::createFromFormat() wrong with reset and D,l
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-235021@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=63222&edit=1 ID: 63222 Updated by: cmb@php.net Reported by: gron1987 at gmail dot com Summary: DateTime::createFromFormat() wrong with reset and D,l -Status: Open +Status: Not a bug Type: Bug Package: Date/time related Operating System: Linux PHP Version: 5.4.7 -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: > in 1970 year, php don't change day of week ("Wed"), it change > day("05"). Well, garbage in – garbage out. Obviously, 1970-10-05 is not a Wednesday (but a Monday) so there is no single correct solution; either the day of the week is adjusted, or the the day of the month. Another option would be to fail. However, the date parser is quite liberal, and chooses to adjust the day of the month as of PHP 5.3.9. Previous Comments: ------------------------------------------------------------------------ [2012-10-05 12:28:05] gron1987 at gmail dot com Description: ------------ We found that createFromFormat work incorrect. If we use reset in format ("!") and don't send year then we will receive new date in 1970 year, php don't change day of week ("Wed"), it change day("05"). It work correct in 5.3.8 Maybe you broke this when fix this: https://bugs.php.net/bug.php?id=54851 Test script: --------------- <?php $str = "6:15 pm Wed, Oct 5"; $date = DateTime::createFromFormat("!g:i a D, M d", $str); var_dump($date); Expected result: ---------------- class DateTime#1 (3) { public $date => string(19) "1970-10-05 18:15:00" public $timezone_type => int(3) public $timezone => string(13) "Europe/Berlin" } (php 5.3.8) Actual result: -------------- object(DateTime)#1 (3) { ["date"]=> string(19) "1970-10-07 18:15:00" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "Europe/Helsinki" } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=63222&edit=1

« previous php.bugs (#235021) next »