php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74645 DateTime::format() and DateTimeInterval %i %s Leading Zeros and Documentation
Submitted: 2017-05-24 14:08 UTC Modified: 2017-05-24 14:15 UTC
From: jimgkraai at gmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.6.30 OS: redhat 2.6.32-696.1.1.el6.x86_64
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: jimgkraai at gmail dot com
New email:
PHP Version: OS:

 

 [2017-05-24 14:08 UTC] jimgkraai at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/datetime.format
---
DateTime::format() does not add leading zeros for the %i and %s format characters as documented.

https://secure.php.net/manual/en/datetime.format.php "Parameters/format" states "Format accepted by date()."  

https://secure.php.net/manual/en/datetime.format.php states 
- "I (capital i)	Whether or not the date is in daylight saving time" which is not minutes with leading zero
- 'S' is not in the list of format characters

The actual behavior of DateTime::format() is not properly documented.

Note that similar behavior/documentation dissonance exists for DateTimeInterval::format()


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

$time_start = new DateTime('now');
sleep(60*2+3.1415926535897961646);
$time_end = new DateTime('now');
$time_interval=$time_end->diff($time_start);
echo $time_interval->format("%H:%i:%s seconds") . PHP_EOL;
echo $time_interval->format("%H:%I:%S seconds") . PHP_EOL; // <- not documented for DateTime::format()



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-05-24 14:12 UTC] jimgkraai at gmail dot com
--https://secure.php.net/manual/en/datetime.format.php states 
--- "I (capital i)	Whether or not the date is in daylight saving time" which is not minutes with leading zero
--- 'S' is not in the list of format characters

should read

https://secure.php.net/manual/en/function.date.php states 
- "I (capital i)	Whether or not the date is in daylight saving time" which is not minutes with leading zero
- 'S' is not in the list of format characters
 [2017-05-24 14:15 UTC] requinix@php.net
-Status: Open +Status: Not a bug -Package: *General Issues +Package: Date/time related
 [2017-05-24 14:16 UTC] requinix@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

$time_interval is a DateInterval. It has its own format() with its own formatting rules.

http://php.net/manual/en/datetime.diff.php
http://php.net/manual/en/dateinterval.format.php
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 08:01:28 2024 UTC