PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Date and Time » Date » Bug #2652

format() should have hour output without leading zero

Details

Request #2652format() should have hour output without leading zero
Submitted2004-10-30 01:34 UTC
Frommcp at orange-mag dot com
Assignedpajoye
StatusClosed
PackageDate
PHP VersionIrrelevant
OSNA
Roadmaps(Not assigned)

Comments

[2004-10-30 01:34 UTC] mcp at orange-mag dot com

Description:
------------
I have started to convert all of my date and time output
and input to the Pear Date class. Because I use the
format function for all output I noticed there is no way
to display the hour without the leading zero.

This is supported by the date() function in PHP.

I would rather not have to use getHour() along with the
other "get" type functions to output the hour without
the leading zero.

Maybe use "%h" for this?

For example:
5:55:55 could be output by $date->format("%h:%M:%S");

I am using version 1.4.3 of the Date library, but the
documentation I am referencing is 1.4.2 (since 1.4.3
gives a 404).

Thanks.

mcp

Reproduce code:
---------------
NA

Expected result:
----------------
NA

Actual result:
--------------
NA

[2005-03-14 22:16 UTC] nick at silverorange dot com

Here's a patch that adds two new options:
%h hour as single digit decimal number (0 to 23)
%i hour as single digit decimal number on 12-hour clock (1 to 12)

http://www.worksintheory.org/files/pear/Date-time-format.diff

[2005-09-11 18:28 UTC] drewish at php dot net

The diff at: http://www.worksintheory.org/files/pear/Date-time-format.diff
seems to have disappeared...

[2005-09-28 02:25 UTC] rob at wildlime dot com

here's a patch that works as Nick describes:

351a341,343
> case "h":
> $output .= sprintf("%d", $this->hour);
> break;
355a348,351
> case "i":
> $hour = ($this->hour + 1) > 12 ? $this->hour - 12 : $this->hour;
> $output .= sprintf("%d", $hour==0 ? 12 : $hour);
> break;