php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #76945 DateTime modify with decimals
Submitted: 2018-09-28 11:43 UTC Modified: 2018-10-02 15:44 UTC
From: wijnand at samson-it dot nl Assigned: cmb (profile)
Status: Closed Package: Date/time related
PHP Version: 7.2.10 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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: wijnand at samson-it dot nl
New email:
PHP Version: OS:

 

 [2018-09-28 11:43 UTC] 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');


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-09-28 12:13 UTC] 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 13:17 UTC] 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 15:06 UTC] 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 15:22 UTC] wijnand at samson-it dot nl
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.
 [2018-10-02 15:30 UTC] cmb@php.net
-Status: Open +Status: Verified -Type: Bug +Type: Documentation Problem -Assigned To: +Assigned To: cmb
 [2018-10-02 15:43 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&revision=345766
Log: Fix #76945: DateTime modify with decimals
 [2018-10-02 15:44 UTC] cmb@php.net
-Status: Verified +Status: Closed
 [2018-10-02 15:44 UTC] cmb@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.
 [2020-02-07 06:05 UTC] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=ebce4934361fdf543c4ddb95d646764b982f1925
Log: Fix #76945: DateTime modify with decimals
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 12:01:29 2024 UTC