php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #76785 DateTime construction with a negative year argument shows different behaviours
Submitted: 2018-08-23 15:29 UTC Modified: 2022-06-05 14:25 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: thijs at tsjeng dot nl Assigned: derick (profile)
Status: Wont fix Package: Date/time related
PHP Version: Irrelevant OS:
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: thijs at tsjeng dot nl
New email:
PHP Version: OS:

 

 [2018-08-23 15:29 UTC] thijs at tsjeng dot nl
Description:
------------
DateTime object instantiation with negative input string via 
'createFromFormat' and same argument just as construction argument display weird behaviour. 

Test script:
---------------
var_dump(DateTime::createFromFormat('Y-m-d', '0045-01-01')); // works
var_dump(DateTime::createFromFormat('Y-m-d', '-0045-01-01')); //  false
var_dump(DateTime::createFromFormat('-Y-m-d', '-0045-01-01')); // works, but year is positive instead of negative

var_dump(new DateTime('0045-01-01')); // works
var_dump(new DateTime('-0045-01-01')); // works
var_dump(new DateTime('0045/01/01')); // works

var_dump(new DateTime('-0045/01/01')); // exception



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-08-23 17:10 UTC] requinix@php.net
Fortunately 'U' already supports signed numbers so extending that to 'Y' shouldn't be difficult.
 [2018-11-28 14:19 UTC] bjoern dot fischer at dezem dot de
We are affected by this issue too.

It can be easily reproduced here:
https://3v4l.org/LY6FJ
 [2020-01-20 17:35 UTC] girgias@php.net
-Assigned To: +Assigned To: derick
 [2020-01-20 17:35 UTC] girgias@php.net
This maybe should be reclassified as a Feature request, leaving Derick to decide about it.
 [2021-04-06 18:40 UTC] derick@php.net
-Type: Bug +Type: Feature/Change Request
 [2022-06-05 14:25 UTC] derick@php.net
-Status: Assigned +Status: Wont fix
 [2022-06-05 14:25 UTC] derick@php.net
I am marking this as "won't fix". If you are still interested in having this feature, please file a new issue at https://github.com/php/php-src/issues/ with a well defined and explained use case.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 02:01:28 2024 UTC