derick Sun Jul 3 11:01:30 2005 EDT
Modified files:
/php-src/ext/date php_date.c
/php-src/ext/date/lib parse_date.c timelib.h
/php-src/ext/date/lib/resource parse_date.re
/php-src/ext/date/tests bug26198.phpt bug28599.phpt bug29585.phpt
bug29595.phpt bug33056.phpt bug33452.phpt
format-negative-timestamp.phpt
Log:
- Added fallback to system's timezone setting, but marked with an E_STRICT
error.
- Adjusted tests to use the date_timezone_set() function.
http://cvs.php.net/diff.php/php-src/ext/date/php_date.c?r1=1.22&r2=1.23&ty=u
Index: php-src/ext/date/php_date.c
diff -u php-src/ext/date/php_date.c:1.22 php-src/ext/date/php_date.c:1.23
--- php-src/ext/date/php_date.c:1.22 Sun Jul 3 10:36:59 2005
+++ php-src/ext/date/php_date.c Sun Jul 3 11:01:29 2005
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_date.c,v 1.22 2005/07/03 14:36:59 derick Exp $ */
+/* $Id: php_date.c,v 1.23 2005/07/03 15:01:29 derick Exp $ */
#include "php.h"
#include "php_streams.h"
@@ -130,6 +130,24 @@
if (DATEG(default_timezone) && (strlen(DATEG(default_timezone)) > 0)) {
return DATEG(default_timezone);
}
+#if HAVE_TM_ZONE
+ /* Try to guess timezone from system information */
+ {
+ struct tm *ta, tmbuf;
+ time_t the_time;
+ char *tzid;
+
+ the_time = time(NULL);
+ ta = php_localtime_r(&the_time, &tmbuf);
+ tzid = timelib_timezone_id_from_abbr(ta->tm_zone);
+ if (! tzid) {
+ tzid = "UTC";
+ }
+
+ php_error_docref(NULL TSRMLS_CC, E_STRICT, "It is not safe to
rely on the systems timezone settings, please use the date.timezone setting,
the TZ environment variable or the date_timezone_set() function. We now use
'%s' for '%s'", tzid, ta->tm_zone);
+ return tzid;
+ }
+#endif
/* Fallback to UTC */
return "UTC";
}
http://cvs.php.net/diff.php/php-src/ext/date/lib/parse_date.c?r1=1.19&r2=1.20&ty=u
Index: php-src/ext/date/lib/parse_date.c
diff -u php-src/ext/date/lib/parse_date.c:1.19
php-src/ext/date/lib/parse_date.c:1.20
--- php-src/ext/date/lib/parse_date.c:1.19 Fri Jul 1 03:18:42 2005
+++ php-src/ext/date/lib/parse_date.c Sun Jul 3 11:01:29 2005
@@ -1,4 +1,4 @@
-/* Generated by re2c 0.9.8.dev on Fri Jul 1 09:16:07 2005 */
+/* Generated by re2c 0.9.8.dev on Sun Jul 3 16:51:26 2005 */
#line 1 "parse_date.re"
/*
+----------------------------------------------------------------------+
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: parse_date.c,v 1.19 2005/07/01 07:18:42 derick Exp $ */
+/* $Id: parse_date.c,v 1.20 2005/07/03 15:01:29 derick Exp $ */
#include "timelib.h"
@@ -655,7 +655,7 @@
}
}
-static timelib_tz_lookup_table* zone_search(char *word, int left, int right)
+static timelib_tz_lookup_table* zone_search(const char *word, int left, int
right)
{
int mid, cmp;
@@ -13323,6 +13323,13 @@
*/
}
+char *timelib_timezone_id_from_abbr(const char *abbr)
+{
+ timelib_tz_lookup_table *tp;
+
+ tp = zone_search(abbr, 0, sizeof(timelib_timezone_lookup) /
sizeof(*timelib_timezone_lookup) - 1);
+ return (tp->full_tz_name);
+}
#ifdef DEBUG_PARSER_STUB
int main(void)
http://cvs.php.net/diff.php/php-src/ext/date/lib/timelib.h?r1=1.6&r2=1.7&ty=u
Index: php-src/ext/date/lib/timelib.h
diff -u php-src/ext/date/lib/timelib.h:1.6 php-src/ext/date/lib/timelib.h:1.7
--- php-src/ext/date/lib/timelib.h:1.6 Thu Jun 30 19:03:36 2005
+++ php-src/ext/date/lib/timelib.h Sun Jul 3 11:01:29 2005
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: timelib.h,v 1.6 2005/06/30 23:03:36 fmk Exp $ */
+/* $Id: timelib.h,v 1.7 2005/07/03 15:01:29 derick Exp $ */
#ifndef __TIMELIB_H__
#define __TIMELIB_H__
@@ -48,6 +48,7 @@
/* From parse_date.re */
timelib_time *timelib_strtotime(char *s);
void timelib_fill_holes(timelib_time *parsed, timelib_time *now, int options);
+char *timelib_timezone_id_from_abbr(const char *abbr);
/* From tm2unixtime.c */
void timelib_update_ts(timelib_time* time, timelib_tzinfo* tzi);
http://cvs.php.net/diff.php/php-src/ext/date/lib/resource/parse_date.re?r1=1.17&r2=1.18&ty=u
Index: php-src/ext/date/lib/resource/parse_date.re
diff -u php-src/ext/date/lib/resource/parse_date.re:1.17
php-src/ext/date/lib/resource/parse_date.re:1.18
--- php-src/ext/date/lib/resource/parse_date.re:1.17 Fri Jul 1 03:18:43 2005
+++ php-src/ext/date/lib/resource/parse_date.re Sun Jul 3 11:01:29 2005
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: parse_date.re,v 1.17 2005/07/01 07:18:43 derick Exp $ */
+/* $Id: parse_date.re,v 1.18 2005/07/03 15:01:29 derick Exp $ */
#include "timelib.h"
@@ -653,7 +653,7 @@
}
}
-static timelib_tz_lookup_table* zone_search(char *word, int left, int right)
+static timelib_tz_lookup_table* zone_search(const char *word, int left, int
right)
{
int mid, cmp;
@@ -1443,6 +1443,13 @@
*/
}
+char *timelib_timezone_id_from_abbr(const char *abbr)
+{
+ timelib_tz_lookup_table *tp;
+
+ tp = zone_search(abbr, 0, sizeof(timelib_timezone_lookup) /
sizeof(*timelib_timezone_lookup) - 1);
+ return (tp->full_tz_name);
+}
#ifdef DEBUG_PARSER_STUB
int main(void)
http://cvs.php.net/diff.php/php-src/ext/date/tests/bug26198.phpt?r1=1.3&r2=1.4&ty=u
Index: php-src/ext/date/tests/bug26198.phpt
diff -u php-src/ext/date/tests/bug26198.phpt:1.3
php-src/ext/date/tests/bug26198.phpt:1.4
--- php-src/ext/date/tests/bug26198.phpt:1.3 Sat Jul 2 17:19:25 2005
+++ php-src/ext/date/tests/bug26198.phpt Sun Jul 3 11:01:29 2005
@@ -2,7 +2,7 @@
Bug #26198 (strtotime handling of "M Y" and "Y M" format)
--FILE--
<?php
- putenv("TZ=");
+ date_timezone_set("GMT");
echo gmdate("F Y (Y-m-d H:i:s T)\n", strtotime("Oct 2001"));
echo gmdate("M Y (Y-m-d H:i:s T)\n", strtotime("2001 Oct"));
?>
http://cvs.php.net/diff.php/php-src/ext/date/tests/bug28599.phpt?r1=1.1&r2=1.2&ty=u
Index: php-src/ext/date/tests/bug28599.phpt
diff -u php-src/ext/date/tests/bug28599.phpt:1.1
php-src/ext/date/tests/bug28599.phpt:1.2
--- php-src/ext/date/tests/bug28599.phpt:1.1 Thu Jun 16 13:35:08 2005
+++ php-src/ext/date/tests/bug28599.phpt Sun Jul 3 11:01:29 2005
@@ -2,6 +2,7 @@
Bug #28599 (strtotime fails with zero base time)
--FILE--
<?php
+date_timezone_set("Europe/Amsterdam");
print gmdate("d-m-Y H:i:s", strtotime("+30 minutes", 1100535573));
?>
--EXPECT--
http://cvs.php.net/diff.php/php-src/ext/date/tests/bug29585.phpt?r1=1.2&r2=1.3&ty=u
Index: php-src/ext/date/tests/bug29585.phpt
diff -u php-src/ext/date/tests/bug29585.phpt:1.2
php-src/ext/date/tests/bug29585.phpt:1.3
--- php-src/ext/date/tests/bug29585.phpt:1.2 Sat Jul 2 17:19:25 2005
+++ php-src/ext/date/tests/bug29585.phpt Sun Jul 3 11:01:29 2005
@@ -2,9 +2,8 @@
Bug #29585 (Support week numbers in strtotime())
--FILE--
<?php
-putenv('TZ=');
+date_timezone_set("GMT");
echo gmdate("Y-m-d H:i:s", strtotime("2004W30"));
-
?>
--EXPECT--
2004-07-19 00:00:00
http://cvs.php.net/diff.php/php-src/ext/date/tests/bug29595.phpt?r1=1.1&r2=1.2&ty=u
Index: php-src/ext/date/tests/bug29595.phpt
diff -u php-src/ext/date/tests/bug29595.phpt:1.1
php-src/ext/date/tests/bug29595.phpt:1.2
--- php-src/ext/date/tests/bug29595.phpt:1.1 Mon Jun 20 04:47:56 2005
+++ php-src/ext/date/tests/bug29595.phpt Sun Jul 3 11:01:29 2005
@@ -2,11 +2,10 @@
Bug #29595 (Roman number format for months)
--FILE--
<?php
-
+date_timezone_set("GMT");
$from_postgres = '2004-08-09 14:48:27.304809+10';
echo strtotime($from_postgres);
-
?>
--EXPECT--
1092026907
http://cvs.php.net/diff.php/php-src/ext/date/tests/bug33056.phpt?r1=1.1&r2=1.2&ty=u
Index: php-src/ext/date/tests/bug33056.phpt
diff -u php-src/ext/date/tests/bug33056.phpt:1.1
php-src/ext/date/tests/bug33056.phpt:1.2
--- php-src/ext/date/tests/bug33056.phpt:1.1 Wed Jun 15 19:24:28 2005
+++ php-src/ext/date/tests/bug33056.phpt Sun Jul 3 11:01:29 2005
@@ -2,6 +2,7 @@
Bug #33056 (strtotime() does not parse 20050518t090000Z)
--FILE--
<?php
+date_timezone_set("GMT");
echo strtotime('20050518t090000Z')."\n";
echo strtotime('20050518t091234Z')."\n";
echo strtotime('20050518t191234Z')."\n";
http://cvs.php.net/diff.php/php-src/ext/date/tests/bug33452.phpt?r1=1.1&r2=1.2&ty=u
Index: php-src/ext/date/tests/bug33452.phpt
diff -u php-src/ext/date/tests/bug33452.phpt:1.1
php-src/ext/date/tests/bug33452.phpt:1.2
--- php-src/ext/date/tests/bug33452.phpt:1.1 Thu Jun 30 17:38:06 2005
+++ php-src/ext/date/tests/bug33452.phpt Sun Jul 3 11:01:29 2005
@@ -2,6 +2,7 @@
Bug #33452 (Support for year accompanying ISO week nr)
--FILE--
<?php
+date_timezone_set("GMT");
echo date('Y-W', strtotime('2005-1-1')), "\n";
echo date('o-W', strtotime('2005-1-1')), "\n";
?>
http://cvs.php.net/diff.php/php-src/ext/date/tests/format-negative-timestamp.phpt?r1=1.1&r2=1.2&ty=u
Index: php-src/ext/date/tests/format-negative-timestamp.phpt
diff -u php-src/ext/date/tests/format-negative-timestamp.phpt:1.1
php-src/ext/date/tests/format-negative-timestamp.phpt:1.2
--- php-src/ext/date/tests/format-negative-timestamp.phpt:1.1 Wed Jun 29
15:07:06 2005
+++ php-src/ext/date/tests/format-negative-timestamp.phpt Sun Jul 3
11:01:29 2005
@@ -2,6 +2,7 @@
strtotime() - Format: @timestamps
--FILE--
<?php
+date_timezone_set("GMT");
$i = 5;
$max = getrandmax();
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php