From:             marcus at corp dot grupos dot com dot br
Operating system: FreeBSD 4.11-STABLE
PHP version:      4.3.10
PHP Bug Type:     Date/time related
Bug description:  strtotime don't work in DST

Description:
------------
If timestamp don't exist, FreeBSD mktime() return -1 is correct. This case
occurs when use strtotime and have Daylight Save Time in timezone.

Example:
If DST save 1 hour and begin on 2004/11/02 00:00, timestamp between 00:00
and 01:00 don't exists.

I fix with this patch, but I find that it is not the best skill.

-- begin patch --
--- ext/standard/parsedate.c.orig       Tue Dec 14 15:55:22 2004
+++ ext/standard/parsedate.c    Mon Feb 14 14:43:08 2005
@@ -2211,9 +2211,9 @@
   date.yyHaveTime = 0;
   date.yyHaveZone = 0;

-  if (yyparse ((void *)&date)
-      || date.yyHaveTime > 1 || date.yyHaveZone > 1
-         || date.yyHaveDate > 1 || date.yyHaveDay > 1)
+  if (yyparse ((void *)&date))
+//      || date.yyHaveTime > 1 || date.yyHaveZone > 1
+//       || date.yyHaveDate > 1 || date.yyHaveDay > 1)
     return -1;

   tm.tm_year = ToYear (date.yyYear) - TM_YEAR_ORIGIN + date.yyRelYear;
@@ -2272,7 +2272,28 @@
        }

       if (Start == (time_t) -1)
-       return Start;
+       {
+               tm = tm0;
+               while((Start = mktime(&tm)) == -1 && tm.tm_year > 68 &&
tm.tm_year < 138)
+               {
+                       if (tm.tm_isdst == 0)
+                       {
+                               tm.tm_isdst = -1;
+                               if (tm.tm_min < 59) {
+                                       tm.tm_min += 1;
+                               } else {
+                                       tm.tm_min = 0;
+                                       if (tm.tm_hour < 23) {
+                                               tm.tm_hour += 1;
+                                       } else {
+                                               tm.tm_hour = 0;
+                                               tm.tm_mday += 1;
+                                       }
+                               }
+                       }
+               }
+               return Start;
+       }
     }

   if (date.yyHaveDay && !date.yyHaveDate)
-- end patch --

Reproduce code:
---------------
<?php
putenv("TZ=America/Sao_Paulo");
echo $i = strtotime("2004-11-01"), "\n";
echo strtotime("+1 day", $i), "\n";
echo $i = strtotime("2005-02-19"), "\n";
echo strtotime("+1 day", $i), "\n";
?>

America/Sao_Paulo DST begin on 2004/11/02 00:00 and terminate on
2005/02/20 00:00

Expected result:
----------------
1099278000
1099364400
1108778400
1108864800

Actual result:
--------------
1099278000
-1
1108778400
1108864800

-- 
Edit bug report at http://bugs.php.net/?id=32086&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=32086&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=32086&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=32086&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=32086&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=32086&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=32086&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=32086&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=32086&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=32086&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=32086&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=32086&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=32086&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=32086&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=32086&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=32086&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=32086&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=32086&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=32086&r=float
No Zend Extensions:          http://bugs.php.net/fix.php?id=32086&r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=32086&r=mysqlcfg

Reply via email to