Bug #62353 [Opn->Nab]: strtotime fails to interpret time correctly, uses character after decimal point
| From: | cmb@php.net | Date: | Fri, 17 Jun 2016 18:13:18 +0000 |
| Subject: | Bug #62353 [Opn->Nab]: strtotime fails to interpret time correctly, uses character after decimal point | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-201704@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=62353&edit=1
ID: 62353
Updated by: cmb@php.net
Reported by: mike dot mackintosh at angrystatic dot com
Summary: strtotime fails to interpret time correctly, uses
character after decimal point
-Status: Open
+Status: Not a bug
Type: Bug
Package: Date/time related
Operating System: Ubuntu 12.04 x86_64
PHP Version: 5.4Git-2012-06-18 (snap)
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
For reference: <https://3v4l.org/qb1jp>.
As omg00dness already explained, this is expected behavior.
Previous Comments:
------------------------------------------------------------------------
[2012-07-11 02:17:39] omg00dness at yahoo dot com
I don't see this as a bug. I don't even see how you would want to rely on FRACTION units.
You always have leap seconds, leap years, localization, etc. How do you measure half a year? The
<# of days> / 2? 6 months? <# of seconds> / 2? One day does not always equal 86,400
seconds.
Besides, the documentation clearly shows this is not supported.
**Go to: http://us.php.net/manual/en/function.strtotime.php
**Under the <time> parameter, click on Date and Time Formats, or go to: http://www.php.net/manual/en/datetime.formats.php
**Click on Relative Formats.
It seems like you are trying to do the row with:
Format: number space? (unit | 'week')
Description: Handles relative time items where the value is a number.
Examples: "+5 weeks", "12 day", "-7 weekdays"
If you look up <number> at the top of that same page, you have the regex: [+-]?[0-9]+
which clearly DOES NOT accept a decimal point. It accepts +, -, or nothing, followed by one or more
DIGITS.
Sorry if my formatting/caps seem a bit awkward or harsh, but I don't have the liberty to add
tags here.
------------------------------------------------------------------------
[2012-06-18 17:03:39] pajoye@php.net
fix cat
------------------------------------------------------------------------
[2012-06-18 16:51:12] mike dot mackintosh at angrystatic dot com
On 6/18/2012 12:50 PM Est, when running:
echo date("m/d/y H:i", strtotime("-1.0 day"));
The following is returned:
06/18/12 09:50
(Minus 3 hours).
------------------------------------------------------------------------
[2012-06-18 16:48:54] mike dot mackintosh at angrystatic dot com
The following behavior is also present:
echo date("m/d/y H:i", strtotime("1.5 days ago"));
Results in -5 days, 5 hours.
It would be expected to return -1 day and 12 hours, being relative.
------------------------------------------------------------------------
[2012-06-18 16:32:25] mike dot mackintosh at angrystatic dot com
Description:
------------
PHP fails to interpret correctly the relative time string when a decimal is used. PHP will use the
character after the decimal point as the multiplier/value in timelib_relative_time. Using an integer
of 1.0, results in no change.
Test script:
---------------
echo date("m/d/y", strtotime("+1.5 years"));
echo date("m/d/y", strtotime("+1.0 years"));
Expected result:
----------------
12/18/13
06/18/13
Actual result:
--------------
06/18/17
06/18/12
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=62353&edit=1