Req #45509 [Asn->Csd]: create_date_from_format() cannot parse negative (BC) dates

From: Date: Fri, 13 May 2022 10:24:07 +0000
Subject: Req #45509 [Asn->Csd]: create_date_from_format() cannot parse negative (BC) dates
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-241477@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=45509&edit=1

 ID:                 45509
 Updated by:         git@php.net
 Reported by:        tj at systisoft dot com
 Summary:            create_date_from_format() cannot parse negative (BC)
                     dates
-Status:             Assigned
+Status:             Closed
 Type:               Feature/Change Request
 Package:            Date/time related
 Operating System:   *
 PHP Version:        5.3CVS-2008-11-11
 Assigned To:        derick
 Block user comment: N
 Private report:     N

 New Comment:

Automatic comment on behalf of derickr
Revision: https://github.com/php/doc-en/commit/8cc12de858cd2dd0f655fe3c826ba8b66b85d8cb
Log: Fixed bug #45509: Clarify ocumentation for DateTime::format and
DateTime::createFromFormat's 'Y' character


Previous Comments:
------------------------------------------------------------------------
[2021-08-06 17:09:02] cmb@php.net

Might as well argue that the documentation is in error, or that
date() is buggy regarding this behavior.  Anyway, doesn't matter
until someone actually attempts to fix/improve it.

------------------------------------------------------------------------
[2018-12-05 14:15:54] bjoern dot fischer at dezem dot de

The documentation of 'create_date_from_format()' says that the identifiers behave like the
ones of 'date()'. In 'date()' when format the timestamp for the year 10000, date
will output '10000' and not '0000'. So 'Y' is actually a *at least*
four-digit year. See: https://3v4l.org/iOHWa

Because of this, I would argue that this actually is a bug.

------------------------------------------------------------------------
[2015-08-28 01:11:52] cmb@php.net

Well, the "Y" format specifier expects a four-digit year – so
actually this is not a bug. I'm changing to feature request.

------------------------------------------------------------------------
[2008-07-14 13:29:21] tj at systisoft dot com

Description:
------------
While the constructor of DateTime can handle negaive dates (BC dates), create_date_from_format
cannot.

Reproduce code:
---------------
$d = new DateTime("-4000-01-31"); echo $d->format("Y-m-d"), PHP_EOL;
$d = date_create_from_format("Y-m-d", "4000-01-31"); echo
$d->format("Y-m-d"), PHP_EOL;
$d = date_create_from_format("Y-m-d", "-4000-01-31"); echo
$d->format("Y-m-d"), PHP_EOL;

Expected result:
----------------
-4000-01-31
4000-01-31
-4000-01-31

Actual result:
--------------
-4000-01-31
4000-01-31
PHP Fatal error:  Call to a member function format() on a non-object in Command line code on line 3


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=45509&edit=1


Thread (6 messages)

« previous php.bugs (#241477) next »