Bug #77896 [Asn]: DateInterval::createFromDateString() no longer supports relative formats

From: Date: Mon, 15 Apr 2019 15:48:01 +0000
Subject: Bug #77896 [Asn]: DateInterval::createFromDateString() no longer supports relative formats
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-220467@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77896&edit=1

 ID:                 77896
 Updated by:         requinix@php.net
 Reported by:        renan-sub at protonmail dot com
 Summary:            DateInterval::createFromDateString() no longer
                     supports relative formats
 Status:             Assigned
 Type:               Bug
 Package:            Date/time related
 PHP Version:        7.3.4
 Assigned To:        derick
 Block user comment: N
 Private report:     N

 New Comment:

"and" (where the parsing fails) should probably then be added to the docs as a
supported/ignored word.


Previous Comments:
------------------------------------------------------------------------
[2019-04-15 13:06:52] renan-sub at protonmail dot com

It also fails in 7.2.17

------------------------------------------------------------------------
[2019-04-15 12:59:11] 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)


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



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


Thread (6 messages)

« previous php.bugs (#220467) next »