php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77896 DateInterval::createFromDateString() no longer supports relative formats
Submitted: 2019-04-15 12:59 UTC Modified: 2019-04-18 10:02 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: renan-sub at protonmail dot com Assigned: derick (profile)
Status: Assigned Package: Date/time related
PHP Version: 7.3.4 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: renan-sub at protonmail dot com
New email:
PHP Version: OS:

 

 [2019-04-15 12:59 UTC] renan-sub at protonmail dot com
Description:
------------
When calling DateInterval::createFromDateString() with "6 years and 4 months" as argument, it generates a warning. (See https://3v4l.org/sQjh2)

Note: as a workaround (for the case mentioned) I'm using new \DateInterval('P6Y4M')

Test script:
---------------
<?php

var_dump(\DateInterval::createFromDateString('6 years and 4 months'));


Expected result:
----------------
object(DateInterval)#1 (16) {
    ["y"]=> int(6)
    ["m"]=> int(4)
    ["d"]=> int(0)
    ["h"]=> int(0)
    ["i"]=> int(0)
    ["s"]=> int(0)
    ["f"]=> float(0)
    ["weekday"]=> int(0)
    ["weekday_behavior"]=> int(0)
    ["first_last_day_of"]=> int(0)
    ["invert"]=> int(0)
    ["days"]=> bool(false)
    ["special_type"]=> int(0)
    ["special_amount"]=> int(0)
    ["have_weekday_relative"]=> int(0)
    ["have_special_relative"]=> int(0)
}


Actual result:
--------------
Warning: DateInterval::createFromDateString(): Unknown or bad format (6 years and 4 months) at position 8 (a)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-04-15 13:02 UTC] nikic@php.net
-Assigned To: +Assigned To: derick
 [2019-04-15 13:06 UTC] renan-sub at protonmail dot com
It also fails in 7.2.17
 [2019-04-15 15:48 UTC] requinix@php.net
"and" (where the parsing fails) should probably then be added to the docs as a supported/ignored word.
 [2019-04-18 10:02 UTC] cmb@php.net
It's not particularly about "and", see <https://3v4l.org/cVbcv>.
 [2019-04-19 08:12 UTC] a at b dot c dot de
But leaving it out entirely is fine:

https://3v4l.org/cSDRW
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sat Oct 19 12:01:27 2019 UTC