PHP :: Doc Bug #76569 :: Description of “!” And “|” of DateTime::createFromFormat
php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #76569 Description of “!” And “|” of DateTime::createFromFormat
Submitted: 2018-07-02 22:59 UTC Modified: -
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: manabu dot matsui at gmail dot com Assigned:
Status: Open Package: Documentation problem
PHP Version: Irrelevant OS: Irrelevant
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: manabu dot matsui at gmail dot com
New email:
PHP Version: OS:

 

 [2018-07-02 22:59 UTC] manabu dot matsui at gmail dot com
Description:
------------
At http://php.net/manual/en/datetime.createfromformat.php, description of format character “!” And “|” are as follows:

“!”
Resets all fields (year, month, day, hour, minute, second, fraction and timezone information) to the Unix Epoch

“|”
Resets all fields (year, month, day, hour, minute, second, fraction and timezone information) to the Unix Epoch if they have not been parsed yet

And in the rest of this document, the UNIX epoch is explained as follows:

> The Unix epoch is 1970-01-01 00:00:00 UTC.

But actually, they appear to reset to 1970-01-01 00:00:00 in the resulting timezone, not UTC.

% php -d date.timezone=Asia/Tokyo -r 'var_dump(DateTime::createFromFormat("!", ""));'
object(DateTime)#1 (3) {
  ["date"]=>
  string(26) "1970-01-01 00:00:00.000000"
  ["timezone_type"]=>
  int(3)
  ["timezone"]=>
  string(10) "Asia/Tokyo"
}
% php -d date.timezone=Asia/Tokyo -r 'var_dump(DateTime::createFromFormat("!", "")->getTimestamp());'
int(-32400)
% php -r 'var_dump(DateTime::createFromFormat("!", "", new DateTimeZone("Asia/Tokyo")));'
object(DateTime)#2 (3) {
  ["date"]=>
  string(26) "1970-01-01 00:00:00.000000"
  ["timezone_type"]=>
  int(3)
  ["timezone"]=>
  string(10) "Asia/Tokyo"
}

Since the current behavior is more useful, I think this is a problem of documentation.


Patches

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Fri Aug 17 06:01:24 2018 UTC