php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76785 DateTime construction with a negative year argument shows different behaviours
Submitted: 2018-08-23 15:29 UTC Modified: 2020-01-20 17:35 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: thijs at tsjeng dot nl Assigned: derick (profile)
Status: Assigned Package: Date/time related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
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.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Tue Aug 04 18:01:24 2020 UTC