Bug #81569 [Opn->Nab]: Relative time with decimal value
| From: | requinix@php.net | Date: | Sat, 30 Oct 2021 19:31:36 +0000 |
| Subject: | Bug #81569 [Opn->Nab]: Relative time with decimal value | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-237441@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=81569&edit=1
ID: 81569
Updated by: requinix@php.net
Reported by: tm8544 at hotmail dot com
Summary: Relative time with decimal value
-Status: Open
+Status: Not a bug
Type: Bug
Package: Date/time related
Operating System: Windows 10 x64
PHP Version: 8.1.0RC5
Block user comment: N
Private report: N
New Comment:
You aren't seeing the full picture with just the date portion.
https://3v4l.org/gMsML
As with other miscellaneous inputs that don't have meaning to the parser, the decimal point
acts as a separator, so "+1.5 year" means "+1" and then "5 year".
"+1" is a tzcorrection. https://www.php.net/manual/en/datetime.formats.time.php
"5 year" is a relative amount. https://www.php.net/manual/en/datetime.formats.relative.php
The result is +1 or -1 hour for the timezone correction and 5 years added to the date.
Previous Comments:
------------------------------------------------------------------------
[2021-10-30 10:25:40] tm8544 at hotmail dot com
Description:
------------
In PHP Manual
âºSupported Date and Time Formats
âºRelative Formats
number format is
[+-]?[0-9]+
, no decimal point included.
If number is given with decimal value, number should be cut before decimal point, eg
"+1.5" should be read as "+1"
Now, it is read as "5"
Test script:
---------------
<?php
// in examples below, this script was run at 30.10.2021
echo date("j.n.Y", strtotime("+1.5 year", time()));
echo date("j.n.Y", strtotime("-1.5 year", time()));
?>
Expected result:
----------------
30.10.2022
// 1 year ahead
30.10.2020
// 1 year backwards
Actual result:
--------------
30.10.2026
// This is 5 years ahead, not 1.5 years ahead
30.10.2026
// This is 5 years ahead, not 1.5 years backwards
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=81569&edit=1