php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #76009 Cant parse v
Submitted: 2018-02-26 01:18 UTC Modified: 2021-10-26 11:42 UTC
Votes:7
Avg. Score:4.4 ± 0.5
Reproduced:7 of 7 (100.0%)
Same Version:1 (14.3%)
Same OS:1 (14.3%)
From: rparker at kodama dot design Assigned: cmb (profile)
Status: Closed Package: Date/time related
PHP Version: 7.1.14 OS: Windows
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: rparker at kodama dot design
New email:
PHP Version: OS:

 

 [2018-02-26 01:18 UTC] rparker at kodama dot design
Description:
------------
`\DateTime::createFromFormat('Y-m-d\TH:i:sP', '2015-06-09T14:00:00-07:00')` works but `\DateTime::createFromFormat('Y-m-d\TH:i:s.vP', '2015-06-09T14:00:00.000-07:00')` doesnt.

`var_dump(\DateTime::getLastErrors())` outputs `array(4) { ["warning_count"]=> int(0) ["warnings"]=> array(0) { } ["error_count"]=> int(2) ["errors"]=> array(2) { [26]=> string(35) "The format separator does not match" [27]=> string(13) "Trailing data" } }`

It is being triggered by the `v` option which should be supported.

Test script:
---------------
\DateTime::createFromFormat('Y-m-d\TH:i:s.vP', '2015-06-09T14:00:00.000-07:00');
var_dump(\DateTime::getLastErrors());


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-02-26 01:57 UTC] requinix@php.net
-Type: Bug +Type: Feature/Change Request
 [2018-02-26 07:25 UTC] derick@php.net
Looks like this got missed out when we added 'v' to formatting. However, this has recently been added to timelib (the library behind the functionality). Parsing 'v' should make it into PHP 7.3.
 [2018-06-18 20:52 UTC] auroraeosrose at gmail dot com
This should be changed into a Documentation bug if v is not present in 7.2 - docs say it was added in PHP 7.0.0 currently
 [2019-08-15 06:55 UTC] php at sirdiego dot de
Hey guys, please update the docs accordingly.
I was trying stuff like a mad man and thought I was slowly going crazy.

I made this test script, that shows that 'v' does NOT work in 7.1 or 7.2 even tho the documentation states that it was added in 7.0.

Test: https://3v4l.org/qUpGv
Docs: https://www.php.net/manual/en/function.date.php

I will have to work around this problem, because the JavaScript Date.toISOString() method returns a string exactly like in the test script, would have been nice to be able to just use it like that.

Thanks for all the hard work.
 [2020-06-16 16:44 UTC] jacob at jacobweber dot com
This really should be removed from the documentation; it's very confusing.
 [2021-10-26 11:42 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2021-10-26 11:42 UTC] cmb@php.net
*Parsing* v is indeed supported as of PHP 7.3.0, and the
changelog[1] has apparently been fixed in the meantime.

*Formatting* v is actually supported as of PHP 7.0.0[2].

> This really should be removed from the documentation; it's very
> confusing.

It is only confusing, if you assume that *parsing* and
*formatting* support the same specifiers, what you should not.

[1] <https://www.php.net/manual/en/datetime.createfromformat.php#refsect1-datetime.createfromformat-changelog>
[2] <https://3v4l.org/p6h59>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 17:01:31 2024 UTC