php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #70154 date_parse() not returning false for missing time components
Submitted: 2015-07-27 14:05 UTC Modified: 2021-11-23 11:33 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: abodera at gmail dot com Assigned:
Status: Closed Package: Date/time related
PHP Version: 5.6.11 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
27 - 11 = ?
Subscribe to this entry?

 
 [2015-07-27 14:05 UTC] abodera at gmail dot com
Description:
------------
date_parse() is expected to return false for missing values.

For example: 

    date_parse('1st Aug')['year'] === false;

As soon as you provide day of week, the hour, minute, second components magically become 0 (as in 00:00:00) even though they do not exist:

    date_parse('Sat 1st Aug')['hour'] === 0; // expected: false
    date_parse('Sat 1st Aug')['minute'] === 0; // expected: false
    date_parse('Sat 1st Aug')['second'] === 0; // expected: false


See: http://3v4l.org/HvND2

Test script:
---------------
<?php

print_r(date_parse('Sat 1st Aug'));


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-07-27 16:48 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2015-07-27 16:48 UTC] cmb@php.net
I can confirm the different behavior.

It occurs to me that this might be an issue with
TIMELIB_UNHAVE_TIME[1], where h, i, s and f might have to be set
to TIMELIB_UNSET.

[1] <https://github.com/derickr/timelib/blob/2015.01/parse_date.re#L116>
 [2021-11-23 11:33 UTC] cmb@php.net
-Type: Bug +Type: Documentation Problem
 [2021-11-23 11:33 UTC] cmb@php.net
Given the long standing behavior which exists since the function
has been introduced, changing the behavior would be a pretty big
BC break. And given there has been no more traction on this ticket
for more than six years, I'm changing it to documentation issue.
 [2022-06-02 09:41 UTC] git@php.net
Automatic comment on behalf of derickr
Revision: https://github.com/php/doc-en/commit/cf25abe5d089fc9486b98576671f8b90b357cf31
Log: Fixed bug #70154: date_parse() not returning false for missing time components
 [2022-06-02 09:41 UTC] git@php.net
-Status: Verified +Status: Closed
 [2022-06-03 18:02 UTC] git@php.net
Automatic comment on behalf of mumumu
Revision: https://github.com/php/doc-ja/commit/57f83db14bbe38b64aef71a12e3cedfac80c2e9f
Log: Fixed bug #70154: date_parse() not returning false for missing time components
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 21:01:29 2024 UTC