Bug #72425 [Com]: strtotime() doesn't return false when string contains white space

From: Date: Tue, 21 Jun 2016 22:10:38 +0000
Subject: Bug #72425 [Com]: strtotime() doesn't return false when string contains white space
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-201782@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=72425&edit=1

 ID:                 72425
 Comment by:         mtanalin at yandex dot ru
 Reported by:        alex at itc77 dot com
 Summary:            strtotime() doesn't return false when string
                     contains white space
 Status:             Open
 Type:               Bug
 Package:            Date/time related
 PHP Version:        7.0.7
 Block user comment: N
 Private report:     N

 New Comment:

To cmb@php.net:

It looks like just common sense that whitespace is not a valid date or time — because it’s
not a date, it’s…, well, whitespace. ;-)

The “Date Formats” page [1] does not mention whitespace at all, the “Time
Formats” page [2] lists space ([ \t]) as a possible value, but I’m not sure
it is not about just a non-self-contained _token_ intended to be a part of a full valid date/time
string containing _not_ just whitespace.

Anyway, interpreting whitespace as a current date looks confusing, so this behavior probably
deserves changing.

[1] http://php.net/manual/en/datetime.formats.date.php
[2] http://php.net/manual/en/datetime.formats.time.php


Previous Comments:
------------------------------------------------------------------------
[2016-06-17 09:35:06] cmb@php.net

> Obviously, invalid should be whitespace-ONLY arguments (in other
> words, becoming empty string after trim()), not arguments
> _containing_ whitespace.

Indeed, thanks. However, where is this documented?

------------------------------------------------------------------------
[2016-06-16 22:46:24] mtanalin at yandex dot ru

To cmb@php.net:

Obviously, invalid should be whitespace-ONLY arguments (in other words, becoming empty string after
trim()), not arguments _containing_ whitespace.

'2016-06-16 11:23' does not become an empty (zero-length) string after trimming
whitespace.

------------------------------------------------------------------------
[2016-06-16 11:34:26] cmb@php.net

I can confirm this behavior: <https://3v4l.org/HNaaY>.

> According to the documentation white space should be treated as
> invalid format and return false.

Where is this documented? That would actually be wrong; consider

  strtotime('2016-06-16 11:23')

which is supposed to be acceptable.

------------------------------------------------------------------------
[2016-06-15 20:44:36] alex at itc77 dot com

Please accept this patch:

https://github.com/php/php-src/pull/615

------------------------------------------------------------------------
[2016-06-15 20:42:44] alex at itc77 dot com

Description:
------------
strtotime() doesn't return false when string contains white space

According to the documentation white space should be treated as invalid format and  return false.

Test script:
---------------
strtotime(" ")



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



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


Thread (8 messages)

« previous php.bugs (#201782) next »