Doc #76569 [Com]: Description of “!” And “|” of DateTime::createFromFormat

From: Date: Sat, 10 Nov 2018 16:33:17 +0000
Subject: Doc #76569 [Com]: Description of “!” And “|” of DateTime::createFromFormat
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-16133@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76569&edit=1

 ID:                 76569
 Comment by:         salmanarshad2000 at yahoo dot com
 Reported by:        manabu dot matsui at gmail dot com
 Summary:            Description of “!” And “|” of
                     DateTime::createFromFormat
 Status:             Open
 Type:               Documentation Problem
 Package:            Documentation problem
 Operating System:   Irrelevant
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

I have noticed the same behavior and agree that the documentation needs to be corrected. The
documentation seems to suggest that including ! or | inside the format string will result in a
datetime with UTC / +00:00 timezone e.g.:

object(DateTime)#1 (3) {
  ["date"]=>
  string(26) "2000-01-01 00:00:00.000000"
  ["timezone_type"]=>
  int(1)
  ["timezone"]=>
  string(6) "+00:00"
}

Or:

object(DateTime)#1 (3) {
  ["date"]=>
  string(26) "2000-01-01 00:00:00.000000"
  ["timezone_type"]=>
  int(2)
  ["timezone"]=>
  string(3) "UTC"
}

But it does not produce the result I assumed by reading the documentation.

Other: the documentation also examples of using "|" and how it differs from "!".


Previous Comments:
------------------------------------------------------------------------
[2018-07-02 22:59:27] 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.



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



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


Thread (4 messages)

« previous php.doc.bugs (#16133) next »