]> granicus.if.org Git - php/commitdiff
- Added fallback to system's timezone setting, but marked with an E_STRICT
authorDerick Rethans <derick@php.net>
Sun, 3 Jul 2005 15:01:29 +0000 (15:01 +0000)
committerDerick Rethans <derick@php.net>
Sun, 3 Jul 2005 15:01:29 +0000 (15:01 +0000)
  error.
- Adjusted tests to use the date_timezone_set() function.

12 files changed:
ext/date/lib/parse_date.c
ext/date/lib/parse_date.re
ext/date/lib/resource/parse_date.re
ext/date/lib/timelib.h
ext/date/php_date.c
ext/date/tests/bug26198.phpt
ext/date/tests/bug28599.phpt
ext/date/tests/bug29585.phpt
ext/date/tests/bug29595.phpt
ext/date/tests/bug33056.phpt
ext/date/tests/bug33452.phpt
ext/date/tests/format-negative-timestamp.phpt

index 816ce9b7802aeb6f966b25b2faf7734aae02126d..68c087515f82415ced5821755a6142b57d063b57 100644 (file)
@@ -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)
index fb7608fdbbaf930052d1a42eb0cc832b943d9212..c66642dbfb12a9b6341d4f1c6d8a1b2ec462eff8 100644 (file)
@@ -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)
index fb7608fdbbaf930052d1a42eb0cc832b943d9212..c66642dbfb12a9b6341d4f1c6d8a1b2ec462eff8 100644 (file)
@@ -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)
index 5bda8b93cf79879a8f45155a8bf0333f7d9a4758..8e9bde2668d6a94698c25b2ebf9790d02270b837 100644 (file)
@@ -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);
index 673cd0417586b9274f4d5d107344c0eb6284d707..bb393bd84bf070ea5ddbd455dd0b85aecc73a8c2 100644 (file)
@@ -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";
 }
index a5a9043c0e9c4ce042d8039d75841c384431eb1f..f42aed967d315d441d907fb4982230e59ab151d0 100644 (file)
@@ -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"));
 ?>
index 79ac9c84b1a8b1568e40e05a496c5d8a8dd9ba21..73da0c102f76c5ca6de2ee38810ef107d37945ca 100644 (file)
@@ -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--
index c86136729a0ab6100bc990190a2e4eabfd15cb42..4443efda8cd097bc12729a804f3013acffc0c15a 100644 (file)
@@ -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
index ae3639439b51b66ecd5976b2677cc41351e123f5..441ef97b7d9cf0c77f5db6830fd1fcdb508e8f43 100644 (file)
@@ -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
index 65a06083acf1667b92b8e826cf5fa6519f1d0dc3..cd5e8c5cafb7fe3a1b79df7b6d0546f27eaacff3 100644 (file)
@@ -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";
index 75287a2f278fb13d540641bd631ed3c4bbbab712..ac1395ea72202584e5077b6312e9f2d31b96294b 100644 (file)
@@ -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";
 ?>
index e85fce10adb9381e2f1f951079e4f23226d8c3a3..1b82e2ccf97803d631e152ee13ff5422065df600 100644 (file)
@@ -2,6 +2,7 @@
 strtotime() - Format: @timestamps
 --FILE--
 <?php
+date_timezone_set("GMT");
 
 $i = 5;
 $max = getrandmax();