summaryrefslogtreecommitdiff
path: root/ext/date
diff options
context:
space:
mode:
authorDerick Rethans <derick@php.net>2005-07-03 15:01:29 +0000
committerDerick Rethans <derick@php.net>2005-07-03 15:01:29 +0000
commit2e9d063814886f2fd1399678713e54144641d0a6 (patch)
tree7cca4f039b12dbe277cde8ec97219123f4be72f0 /ext/date
parentd3c83378ebf7f7d605a891df0fbcfd7d6564b76c (diff)
downloadphp-git-2e9d063814886f2fd1399678713e54144641d0a6.tar.gz
- Added fallback to system's timezone setting, but marked with an E_STRICT
error. - Adjusted tests to use the date_timezone_set() function.
Diffstat (limited to 'ext/date')
-rw-r--r--ext/date/lib/parse_date.c11
-rw-r--r--ext/date/lib/parse_date.re9
-rw-r--r--ext/date/lib/resource/parse_date.re9
-rw-r--r--ext/date/lib/timelib.h1
-rw-r--r--ext/date/php_date.c18
-rw-r--r--ext/date/tests/bug26198.phpt2
-rw-r--r--ext/date/tests/bug28599.phpt1
-rw-r--r--ext/date/tests/bug29585.phpt3
-rw-r--r--ext/date/tests/bug29595.phpt3
-rw-r--r--ext/date/tests/bug33056.phpt1
-rw-r--r--ext/date/tests/bug33452.phpt1
-rw-r--r--ext/date/tests/format-negative-timestamp.phpt1
12 files changed, 51 insertions, 9 deletions
diff --git a/ext/date/lib/parse_date.c b/ext/date/lib/parse_date.c
index 816ce9b780..68c087515f 100644
--- a/ext/date/lib/parse_date.c
+++ b/ext/date/lib/parse_date.c
@@ -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"
/*
+----------------------------------------------------------------------+
@@ -655,7 +655,7 @@ static void timelib_set_relative(char **ptr, timelib_sll amount, Scanner *s)
}
}
-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 @@ void timelib_fill_holes(timelib_time *parsed, timelib_time *now, int options)
*/
}
+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)
diff --git a/ext/date/lib/parse_date.re b/ext/date/lib/parse_date.re
index fb7608fdbb..c66642dbfb 100644
--- a/ext/date/lib/parse_date.re
+++ b/ext/date/lib/parse_date.re
@@ -653,7 +653,7 @@ static void timelib_set_relative(char **ptr, timelib_sll amount, Scanner *s)
}
}
-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 @@ void timelib_fill_holes(timelib_time *parsed, timelib_time *now, int options)
*/
}
+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)
diff --git a/ext/date/lib/resource/parse_date.re b/ext/date/lib/resource/parse_date.re
index fb7608fdbb..c66642dbfb 100644
--- a/ext/date/lib/resource/parse_date.re
+++ b/ext/date/lib/resource/parse_date.re
@@ -653,7 +653,7 @@ static void timelib_set_relative(char **ptr, timelib_sll amount, Scanner *s)
}
}
-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 @@ void timelib_fill_holes(timelib_time *parsed, timelib_time *now, int options)
*/
}
+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)
diff --git a/ext/date/lib/timelib.h b/ext/date/lib/timelib.h
index 5bda8b93cf..8e9bde2668 100644
--- a/ext/date/lib/timelib.h
+++ b/ext/date/lib/timelib.h
@@ -48,6 +48,7 @@ void timelib_isoweek_from_date(timelib_sll y, timelib_sll m, timelib_sll d, time
/* 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);
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
index 673cd04175..bb393bd84b 100644
--- a/ext/date/php_date.c
+++ b/ext/date/php_date.c
@@ -130,6 +130,24 @@ static char* guess_timezone(TSRMLS_D)
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";
}
diff --git a/ext/date/tests/bug26198.phpt b/ext/date/tests/bug26198.phpt
index a5a9043c0e..f42aed967d 100644
--- a/ext/date/tests/bug26198.phpt
+++ b/ext/date/tests/bug26198.phpt
@@ -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"));
?>
diff --git a/ext/date/tests/bug28599.phpt b/ext/date/tests/bug28599.phpt
index 79ac9c84b1..73da0c102f 100644
--- a/ext/date/tests/bug28599.phpt
+++ b/ext/date/tests/bug28599.phpt
@@ -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--
diff --git a/ext/date/tests/bug29585.phpt b/ext/date/tests/bug29585.phpt
index c86136729a..4443efda8c 100644
--- a/ext/date/tests/bug29585.phpt
+++ b/ext/date/tests/bug29585.phpt
@@ -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
diff --git a/ext/date/tests/bug29595.phpt b/ext/date/tests/bug29595.phpt
index ae3639439b..441ef97b7d 100644
--- a/ext/date/tests/bug29595.phpt
+++ b/ext/date/tests/bug29595.phpt
@@ -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
diff --git a/ext/date/tests/bug33056.phpt b/ext/date/tests/bug33056.phpt
index 65a06083ac..cd5e8c5caf 100644
--- a/ext/date/tests/bug33056.phpt
+++ b/ext/date/tests/bug33056.phpt
@@ -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";
diff --git a/ext/date/tests/bug33452.phpt b/ext/date/tests/bug33452.phpt
index 75287a2f27..ac1395ea72 100644
--- a/ext/date/tests/bug33452.phpt
+++ b/ext/date/tests/bug33452.phpt
@@ -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";
?>
diff --git a/ext/date/tests/format-negative-timestamp.phpt b/ext/date/tests/format-negative-timestamp.phpt
index e85fce10ad..1b82e2ccf9 100644
--- a/ext/date/tests/format-negative-timestamp.phpt
+++ b/ext/date/tests/format-negative-timestamp.phpt
@@ -2,6 +2,7 @@
strtotime() - Format: @timestamps
--FILE--
<?php
+date_timezone_set("GMT");
$i = 5;
$max = getrandmax();