derick          Sat May  3 10:04:37 2008 UTC

  Modified files:              (Branch: PHP_5_3)
    /php-src    NEWS 
    /php-src/ext/date/lib       tm2unixtime.c 
  Log:
  - MFH: Fixed weekdays adding/subtracting algorithm.
  
  
http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.965.2.168&r2=1.2027.2.547.2.965.2.169&diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2027.2.547.2.965.2.168 
php-src/NEWS:1.2027.2.547.2.965.2.169
--- php-src/NEWS:1.2027.2.547.2.965.2.168       Fri May  2 21:33:05 2008
+++ php-src/NEWS        Sat May  3 10:04:36 2008
@@ -50,6 +50,8 @@
   . support for date/time strings returned by MS SQL.
   . support for serialization and unserialization of DateTime objects.
   . support for diffing date/times through date_diff() / DateTime::diff().
+  . support for adding/subtracting weekdays with strtotime() and
+    DateTime::modify().
   . added DateInterval class to represent the difference between two 
date/times.
   . support for parsing ISO intervals for use with DateInterval.
   . date_add() / DateTime::add(), date_sub() / DateTime::sub() for applying an
http://cvs.php.net/viewvc.cgi/php-src/ext/date/lib/tm2unixtime.c?r1=1.13.2.3.2.2.2.7&r2=1.13.2.3.2.2.2.8&diff_format=u
Index: php-src/ext/date/lib/tm2unixtime.c
diff -u php-src/ext/date/lib/tm2unixtime.c:1.13.2.3.2.2.2.7 
php-src/ext/date/lib/tm2unixtime.c:1.13.2.3.2.2.2.8
--- php-src/ext/date/lib/tm2unixtime.c:1.13.2.3.2.2.2.7 Fri May  2 12:49:16 2008
+++ php-src/ext/date/lib/tm2unixtime.c  Sat May  3 10:04:37 2008
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: tm2unixtime.c,v 1.13.2.3.2.2.2.7 2008/05/02 12:49:16 derick Exp $ */
+/* $Id: tm2unixtime.c,v 1.13.2.3.2.2.2.8 2008/05/03 10:04:37 derick Exp $ */
 
 #include "timelib.h"
 
@@ -197,35 +197,55 @@
 
 static void do_adjust_special_weekday(timelib_time* time)
 {
-       timelib_sll current_dow, this_weekday = 0, count;
+       timelib_sll current_dow, count;
 
-       current_dow = timelib_day_of_week(time->y, time->m, time->d);
        count = time->relative.special.amount;
+
+       current_dow = timelib_day_of_week(time->y, time->m, time->d);
        if (count == 0) {
+               // skip over saturday and sunday
                if (current_dow == 6) {
-                       this_weekday = 2;
+                       time->d += 2;
                }
+               // skip over sunday
                if (current_dow == 0) {
-                       this_weekday = 1;
+                       time->d += 1;
                }
-               time->d += this_weekday;
-               return;
        } else if (count > 0) {
+               // skip over saturday and sunday
                if (current_dow == 5) {
-                       this_weekday = 2;
+                       time->d += 2;
                }
+               // skip over sunday
                if (current_dow == 6) {
-                       this_weekday = 1;
+                       time->d += 1;
                }
-       } else if (count < 0) {
-               if (current_dow == 0) {
-                       this_weekday = -1;
+               // add increments of 5 weekdays as a week
+               time->d += (count / 5) * 7;
+               // if current DOW plus the remainder > 5, add two days
+               current_dow = timelib_day_of_week(time->y, time->m, time->d);
+               time->d += (count % 5);
+               if ((count % 5) + current_dow > 5) {
+                       time->d += 2;
                }
+       } else if (count < 0) {
+               // skip over sunday and saturday
                if (current_dow == 1) {
-                       this_weekday = -2;
+                       time->d -= 2;
+               }
+               // skip over satruday
+               if (current_dow == 0 ) {
+                       time->d -= 1;
+               }
+               // subtract increments of 5 weekdays as a week
+               time->d += (count / 5) * 7;
+               // if current DOW minus the remainder < 0, subtract two days
+               current_dow = timelib_day_of_week(time->y, time->m, time->d);
+               time->d += (count % 5);
+               if ((count % 5) + current_dow < 1) {
+                       time->d -= 2;
                }
        }
-       time->d += this_weekday + ((count / 5) * 7) + (count % 5);
 }
 
 static void do_adjust_special(timelib_time* time)



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to