Bug #76945 [Opn]: DateTime modify with decimals
| From: | wijnand at samson-it dot nl | Date: | Fri, 28 Sep 2018 15:22:26 +0000 |
| Subject: | Bug #76945 [Opn]: DateTime modify with decimals | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-217269@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=76945&edit=1
ID: 76945
User updated by: wijnand at samson-it dot nl
Reported by: wijnand at samson-it dot nl
Summary: DateTime modify with decimals
Status: Open
Type: Bug
Package: Date/time related
PHP Version: 7.2.10
Block user comment: N
Private report: N
New Comment:
Ah! Well, I never would have figured that the dot would be interpreted as a delimiter in such a
string.
I'd say that this is confusing enough that it warrants an example in the documentation about
how "+1.5 hours" works, but yields an unexpected result.
Previous Comments:
------------------------------------------------------------------------
[2018-09-28 15:06:17] salathe@php.net
> Then it's still not correct, because the "+1." part of the string is dropped,
> instead of it saying that this is not recognised.
The "+1" is being interpreted as a timezone correction (see tzcorrection at http://php.net/manual/en/datetime.formats.time.php).
As far as I'm aware, the "." is just being ignored in this case (as would a few other
characters, which I'm not sure we do document well [or at all]).
The intro page for those formats (http://php.net/manual/en/datetime.formats.php) also mentions
"In most cases formats from different sections [of the Supported Date and Time Formats
documentation] can be used in the same date/time string."
Does that help?
------------------------------------------------------------------------
[2018-09-28 13:17:45] wijnand at samson-it dot nl
I suppose you're referring to this:
[+-]?[0-9]+
Then it's still not correct, because the "+1." part of the string is dropped, instead
of it saying that this is not recognised.
------------------------------------------------------------------------
[2018-09-28 12:13:05] salathe@php.net
> It's not documented
The relative date/time statements (and how they behave with non-relative statements) are documented
at http://php.net/manual/en/datetime.formats.relative.php
------------------------------------------------------------------------
[2018-09-28 11:43:49] wijnand at samson-it dot nl
Description:
------------
---
From manual page: http://www.php.net/datetime.modify
---
Let's modify a DateTime object, say "add one-and-a-half hour". The expected result is
that 1 hour and 30 minutes are added. The actual result is that 5 hours are added.
It's not necessarily a problem that the decimal syntax is not supported, however there's
no warning that this doesn't work. It's not documented and the call is happily accepted. I
would say that the regex should be "\+\d+" or something along those lines.
Test script:
---------------
(new DateTime('2000-01-01 0:00'))->modify('+1.5 hours');
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76945&edit=1