php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #12934 strftime() doesn't grok negative time_t
Submitted: 2001-08-23 17:36 UTC Modified: 2002-09-21 10:46 UTC
From: rich at horde dot org Assigned:
Status: Closed Package: Date/time related
PHP Version: 4.3.0-dev OS: Linux
Private report: No CVE-ID: None
 [2001-08-23 17:36 UTC] rich at horde dot org
This:

  echo strftime("%Y-%m-%d %H:%M:%S", -200000);

outputs an empty string. However, this:

  $foo = localtime(-200000000); echo $foo[5]+1900;

outputs "1963" in Linux 2.2.15, but outputs an empty string in Win2k. While negative time_t is undefined according to POSIX, time functions should probably work consistently, and strftime() should never output nothing. (That is, since there is no error condition documented for strftime(), this:

  echo strftime("HONK", -200000);

should /always/ output "HONK", even if the %-values end up empty because of the undefined meaning of negative time values.)

So, either strftime with negative time values should work,
or localtime with negative time values should fail (and the rest of the time functions made consistent with either decision). If it's decided that negative time values are to cause the functions to fail, then error conditions should probably be defined or documented for those functions (and maybe even warnings?).

(To be clear, that's not "PHP is nonconforming", but rather "undocumented and nonportable inconsistency amongst *time functions is a particularly icky form of nasal demon".)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-07-03 19:25 UTC] eru@php.net
strftime now returns false for negative values, but that doesn't solve the inconsistency. I'm really undecided if this is a Date/Time-problem or simply a lack of proper documentation.

 [2002-09-21 10:46 UTC] iliaa@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sat May 21 21:05:46 2022 UTC