php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79403 DateTime::construct inconsistent results with "first day of"
Submitted: 2020-03-22 02:52 UTC Modified: -
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: nfoskett at internode dot on dot net Assigned:
Status: Open Package: Date/time related
PHP Version: 7.4.4 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: nfoskett at internode dot on dot net
New email:
PHP Version: OS:

 

 [2020-03-22 02:52 UTC] 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


Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-04-07 12:23 UTC] 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-04-08 08:15 UTC] alexinbeijing at gmail dot com
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
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sun Sep 20 02:01:25 2020 UTC