Bug #79403 [PATCH]: DateTime::construct inconsistent results with "first day of"

From: Date: Wed, 08 Apr 2020 08:15:29 +0000
Subject: Bug #79403 [PATCH]: DateTime::construct inconsistent results with "first day of"
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-226473@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79403&edit=1 ID: 79403 Patch added by: alexinbeijing@gmail.com Reported by: nfoskett at internode dot on dot net Summary: DateTime::construct inconsistent results with "first day of" Status: Open Type: Bug Package: Date/time related Operating System: Linux PHP Version: 7.4.4 Block user comment: N Private report: N New Comment: The following pull request has been associated: Patch Name: Fix #79403: DateTime::construct inconsistent results with "first day of" On GitHub: https://github.com/php/php-src/pull/5360 Patch: https://github.com/php/php-src/pull/5360.patch Previous Comments: ------------------------------------------------------------------------ [2020-04-07 12:23:21] alexinbeijing at gmail dot com Interesting little bug. Looking at the date parsing code, it appears that this code only works by accident: new DateTime("first day of this month") This actually returns the exact same result: new DateTime("first day of this year") ------------------------------------------------------------------------ [2020-03-22 02:52:17] nfoskett at internode dot on dot net Description: ------------ When using "first day of" relative time formats, the constructor gives inconsistent values for what ought to be the same. Results shown below are all as of 2020-03-22 03:49:52. Test script: --------------- $month_start = new DateTime("first day of this month"); echo $month_start->format('Y-m-d H:i:s') . "\n"; $month_start = new DateTime("first day of March"); echo $month_start->format('Y-m-d H:i:s') . "\n"; https://3v4l.org/lG3GL Expected result: ---------------- 2020-03-01 00:00:00 2020-03-01 00:00:00 or possibly 2020-03-01 03:49:52 2020-03-01 03:49:52 Actual result: -------------- 2020-03-01 03:49:52 2020-03-01 00:00:00 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=79403&edit=1

« previous php.bugs (#226473) next »