Bug #79403 [Opn->Nab]: DateTime::construct inconsistent results with "first day of"

From: Date: Fri, 22 Jul 2022 16:41:13 +0000
Subject: Bug #79403 [Opn->Nab]: DateTime::construct inconsistent results with "first day of"
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-241988@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
 Updated by:         derick@php.net
 Reported by:        nfoskett at internode dot on dot net
 Summary:            DateTime::construct inconsistent results with "first
                     day of"
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            Date/time related
 Operating System:   Linux
 PHP Version:        7.4.4
 Block user comment: N
 Private report:     N

 New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php

I'm going to mark this as "expected behaviour". The parser simply can't
understand everything. If you still find the need to want to add this support, file a new ticket at
our GitHub repository.


Previous Comments:
------------------------------------------------------------------------
[2020-04-08 08:15:29] 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

------------------------------------------------------------------------
[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


Thread (4 messages)

« previous php.bugs (#241988) next »