From: Derick Rethans Date: Sun, 3 Jul 2005 15:01:29 +0000 (+0000) Subject: - Added fallback to system's timezone setting, but marked with an E_STRICT X-Git-Tag: php-5.1.0b3~207 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2e9d063814886f2fd1399678713e54144641d0a6;p=php - Added fallback to system's timezone setting, but marked with an E_STRICT error. - Adjusted tests to use the date_timezone_set() function. --- 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-- 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-- --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-- --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-- --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-- 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--