Bug #9640 Updated: strtotime() cannot properly handle some ISO 8601-compliant strings

From: Date: Sat, 27 Oct 2001 17:46:15 +0000
Subject: Bug #9640 Updated: strtotime() cannot properly handle some ISO 8601-compliant strings
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-69148@lists.php.net to get a copy of this message
ID: 9640 Updated by: derick Reported By: derekm@hackunix.org Old Status: Assigned Status: Closed Bug Type: Date/time related Operating System: Linux 2.4.2 PHP Version: 4.0.4pl1 Old Assigned To: derick Assigned To: New Comment: Fixed in CVS (will be in 4.1.0). Derick Previous Comments: ------------------------------------------------------------------------ [2001-03-08 19:03:36] derekm@hackunix.org Another workaround for PostgreSQL (and the equivalent, if one exists, of this on other databases will work as well): Run your query using the date_part function so that PostgreSQL returns the UNIX timestamp instead of an ISO 8601-style timestamp. The query would look something like this: SELECT date_part('epoch', timestamp) AS timestamp FROM table Then use can just us that those records returned directly with PHP's date, strftime, gmdate, and etc. functions. ------------------------------------------------------------------------ [2001-03-08 17:26:17] derekm@hackunix.org I've recently run into a problem. This problem has been addressed in bug report #9007, but I thought I would try to provide more detailed information. First, I'm pulling ISO 8601-compliant date strings from a PostgreSQL 7.0.3 database. We'll illustrate this bug with a sample date: 1999-06-24 00:01:00-05. Or June 24, 1999, 12:01 AM CDT. $timestamp = "1999-06-24 00:01:00-05"; $timestamp = strtotime($timestamp); print(strftime("%A, %B %d, %Y %H:%M %Z", $timestamp)); Now, that output /should/ read "Thursday, June 24, 1999 00:01 CDT," instead it reads "Wednesday, June 23, 1999 19:06 CDT." Even though PHP knows the timezone of the machine to be CST6CDT, it subtracts 5 hours from the time during conversion, regardless. This is a Bad Thing(tm) because all programs should be ISO 8601-compliant. Currently PHP4 is a lil' broken. This should be fixed in the next release of PHP4, IMHO. The bug probably actually resides in the code in ext/standard/parsedate.c that is borrowed from GNU Bison 1.28. So maybe this bug should be reported to GNU's bug list as well. In any case, here's a fix in the meantime... If using PostgreSQL issue the command "SET DATESTYLE TO Postgres;" in all of your queries that return a timestamp. That will cause the timestamp to be returned in this style: Thu Jun 24 00:01:00 1999 CDT. This style will correctly parse, as we will illustrate with this example: $timestamp = "Thu Jun 24 00:01:00 1999 CDT"; $timestamp = strtotime($timestamp); print(strftime("%A, %B %d, %Y %H:%M %Z", $timestamp)); The output of this example is "Thursday, June 24, 1999 00:01 CDT," which is correct. And that's all. Derek P. Moore derekm@hackunix.org ------------------------------------------------------------------------ [2001-03-08 17:16:14] derekm@hackunix.org I've recently run into a problem. This problem has been addressed in bug report #9007, but I thought I would try to provide more detailed information. First, I'm pulling ISO 8601-compliant date strings from a PostgreSQL 7.0.3. We'll illustrate this bug with a sample date: 1999-06-24 00:01:00-05. Or June 24, 1999, 12:01 AM CDT. $timestamp = "1999-06-24 00:01:00-05"; $timestamp = strtotime($timestamp); print(strftime("%A, %B %d, %Y %H:%M %Z", $timestamp)); Now, that output /should/ read "Thursday, June 24, 1999 00:01 CDT," instead it reads "Wednesday, June 23, 1999 19:06 CDT." Even though PHP knows the timezone of the machine to be CST6CDT, it subtracts 5 hours from the time during conversion, regardless. This is a Bad Thing(tm) because all programs should be ISO 8601-compliant. Currently PHP4 is a lil' broken. This should be fixed in the next release of PHP4, IMHO. The bug probably actually resides in the code in ext/standard/parsedate.c that is borrowed from GNU Bison 1.28. So maybe this bug should be reported to GNU's bug list as well. In any case, here's a fix in the meantime... If using PostgreSQL issue the command "SET DATESTYLE TO Postgres;" in all of your queries that return a timestamp. That will cause the timestamp to be returned in this style: Thu Jun 24 00:01:00 1999 CDT. This style will correctly parse, as we will illustrate with this example: $timestamp = "Thu Jun 24 00:01:00 1999 CDT"; $timestamp = strtotime($timestamp); print(strftime("%A, %B %d, %Y %H:%M %Z", $timestamp)); The output of this example is "Thursday, June 24, 1999 00:01 CDT," which is correct. And that's all. Derek P. Moore derekm@hackunix.org ------------------------------------------------------------------------ Edit this bug report at http://bugs.php.net/?id=9640&edit=1

« previous php.dev (#69148) next »