Doc #54402 [Bgs]: Format string not documented correctly for %I minutes and $S seconds
| From: | salathe@php.net | Date: | Mon, 02 May 2011 19:56:11 +0000 |
| Subject: | Doc #54402 [Bgs]: Format string not documented correctly for %I minutes and $S seconds | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-6336@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=54402&edit=1
ID: 54402
Updated by: salathe@php.net
Reported by: tom dot haws at gmail dot com
Summary: Format string not documented correctly for %I
minutes and $S seconds
Status: Bogus
Type: Documentation Problem
Package: Documentation problem
Operating System: Ubuntu
PHP Version: 5.3SVN-2011-03-27 (snap)
Block user comment: N
Private report: N
New Comment:
No, it does not. The description of the format parameter for
DateTime::format()
is correct. The description of the format parameter for
DateInterval::format() is
also correct.
It appears that you think you are calling DateTime::format() in your
example code,
when in fact you are calling DateInterval::format().
Previous Comments:
------------------------------------------------------------------------
[2011-05-02 20:42:36] tom dot haws at gmail dot com
The statement at http://www.php.net/datetime.format#Parameters
that the
format string for the time diff is a "format accepted by date()" needs
to be replaced with a link to the correct page
http://www.php.net/manual/en/dateinterval.format.php
------------------------------------------------------------------------
[2011-04-26 22:12:39] salathe@php.net
The DateTime::diff() method returns a DateInterval object, whose
format() method you then call. The format characters are listed
on the page for DateInterval::format() [1] which are different
to the format characters available for date() and DateTime::format().
[1] http://www.php.net/manual/en/dateinterval.format.php
------------------------------------------------------------------------
[2011-03-27 18:29:19] tom dot haws at gmail dot com
The case is worse than I stated. I was not precise about the results
vs. expected. Following the documentation strictly gives the following
result:
// Result: Y-m-d H:i:s
// Expected: 25-02-25 04:00:00 from the documented format string.
------------------------------------------------------------------------
[2011-03-27 18:25:10] tom dot haws at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/datetime.format#Parameters
---
Note about the time diff format string:
As far as I can tell, the datetime diff format string I ended up using
is not documented anywere. The PHP manual says that the format string
for the time diff is a "format accepted by date()". That would look like
'Y-m-d H:i:s', but that did not work. The other documented format I
could find is the one accepted by strftime. That would look like
'%Y-%M-%D %H:%i:%s', but that did not give leading zeroes for minutes
and seconds.
$my_birth_tz=new DateTimeZone('America/Phoenix');
$my_birth=new DateTime('1956-09-19 08:38:00',$my_birth_tz);
$my_marriage_tz=new DateTimeZone('America/Los_Angeles');
$my_marriage=new DateTime('1981-12-14 11:38:00', $my_marriage_tz);
$my_marriage_age=$my_marriage->diff($my_birth);
echo $my_marriage_age->;format('%Y-%M-%D %H:%I:%S');
// Result: 25-02-25 04:00:00
Test script:
---------------
$my_birth_tz=new DateTimeZone('America/Phoenix');
$my_birth=new DateTime('1956-09-19 08:38:00',$my_birth_tz);
$my_marriage_tz=new DateTimeZone('America/Los_Angeles');
$my_marriage=new DateTime('1981-12-14 11:38:00', $my_marriage_tz);
$my_marriage_age=$my_marriage->diff($my_birth);
echo $my_marriage_age->;format('%Y-%M-%D %H:%I:%S');
// Result: 25-02-25 04:00:00
// Note the non-documented format() string.
echo $my_marriage_age->;format('%Y-%M-%D %H:%i:%s');
// Result: 25-02-25 04:0:0
// Expected 25-02-25 04:00:00 from the documented format string.
Expected result:
----------------
// Expected 25-02-25 04:00:00 from the documented format string.
I wanted leading zeros.
Actual result:
--------------
// Result: 25-02-25 04:0:0
No leading zeros.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=54402&edit=1