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

From: Date: Tue, 07 Apr 2020 12:23:21 +0000
Subject: Bug #79403 [Com]: DateTime::construct inconsistent results with "first day of"
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-226457@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
 Comment by:         alexinbeijing at gmail dot 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:

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")


Previous Comments:
------------------------------------------------------------------------
[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


Thread (4 messages)

« previous php.bugs (#226457) next »