alphp / strftime

This provides a cross-platform alternative to strftime() for when it will be removed from PHP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

24-hour format of an hour (0 to 23)

CharleysTante opened this issue · comments

Hey, great work! But I still miss %i for 24-hour format. So you could add this line after line 149:
'%i' => 'G',

According to the documentation %k is the time in 24h format with leading spaces: ' 0' to '23'.
On Windows the actual implementation (7.4.28) returns the time in 24h format without spaces or leading zeros: '0' to '23'.
On RHEL/CentOS the implementation (7.4.28/7.4.14) returns the time in 24h format with leading spaces, as indicated in the documentation.

This implementation of the function fixes the difference in favor of the documented response: with leading spaces.

There is no 24h format without spaces or leading zeros in the documentation.
https://www.php.net/manual/en/function.strftime.php

OK, but I'm just updating an old PHP project that uses %i for 24h. So, I added it just for me then. Thanks!

Strange, %i is not documented.
Could it be an error?
Could you tell the specific version of php under which the project was working?
The main purpose of this implementation is backwards compatibility. If there are any php implementations with undocumented formats they could be added if they don't cause problems with the documented formats.

A mistake? Well, anything is possible. As I said, it's an old project that already ran under PHP 4. Some strings used to format the date contain %i. Anyway, thanks for your feedback.

The topic is very interesting. Being PHP4 and a project of more than 14 years (16 years since PHP5), we can almost talk about archaeology.
I've checked the PHP4 documentation and it doesn't mention %i as a valid format either. Everything indicates that it was a project bug.
https://php-legacy-docs.zend.com/manual/php4/en/function.strftime

%i is not documented and is not supported in strftime in the libc (Linux), I just checked the source code. So if it exists, it's only on Windows, but it is not documented on Microsoft strftime implementation either.

On Windows (PHP 7.4.29) %i is also not supported.
At this point I would update the old project and replace the unsupported format specifier with %k, which is the documented format closest to the desired one.

You're right, let it be. I added %i to this single project and I'm happy to be done with it. Old code is sometimes really strange ;-)