From c11f05eba87d73124d3afa2dfa607d0ca0857bd4 Mon Sep 17 00:00:00 2001 From: Jim Hu Date: Wed, 17 Dec 2008 09:58:30 +0000 Subject: progress on recurrence handle some negative values in byxxx rules --- functions/parse/end_vevent.php | 4 ++-- functions/parse/recur_functions.php | 44 +++++++++++++++++++++++++++---------- includes/event.php | 2 ++ 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/functions/parse/end_vevent.php b/functions/parse/end_vevent.php index 47de2d4..eb78ee3 100644 --- a/functions/parse/end_vevent.php +++ b/functions/parse/end_vevent.php @@ -277,8 +277,8 @@ sort($recur_data); /* ============================ Use $recur_data array to write the master array ============================*/ // This used to use 5 different blocks to write the array... can it be reduced further? -$recur_data_hour = @substr($start_unixtime,0,2); -$recur_data_minute = @substr($start_unixtime,2,2); +$recur_data_hour = @substr($start_time,0,2); +$recur_data_minute = @substr($start_time,2,2); foreach($recur_data as $recur_data_unixtime) { $recur_data_year = date('Y', $recur_data_unixtime); $recur_data_month = date('m', $recur_data_unixtime); diff --git a/functions/parse/recur_functions.php b/functions/parse/recur_functions.php index 8a694be..e805e42 100644 --- a/functions/parse/recur_functions.php +++ b/functions/parse/recur_functions.php @@ -1,4 +1,4 @@ - $mArray_begin) $times[] = $start_date_unixtime; $times = array_unique($times); sort($times); $until_date = date("Ymd",$end_range_unixtime); +#dump_times($times); +#dump_times($recur_data); foreach ($times as $time){ - #echo "time:". date("Ymd",$time); + #echo "time:". date("Ymd",$time)."\n"; $date = date("Ymd",$time); - if(isset($time) && !in_array($date, $except_dates) && $time >= $start_date_unixtime && $date <= $until_date){ - $count--; + $time = strtotime("$date 12:00:00"); + if(isset($time) && !in_array($time, $recur_data) && !in_array($date, $except_dates) && $time >= $start_date_unixtime && $date <= $until_date){ + $count--; #echo "."; if($time >= $mArray_begin && $time <= $mArray_end && $count >= 0) $recur_data[] = $time; } } @@ -94,6 +98,7 @@ function expand_bymonthday($times){ foreach($times as $time){ $month = date('m',$time); foreach($bymonthday as $monthday){ + if($monthday < 0) $monthday = date("t",$time) + $monthday +1; $new_times[] = mktime(12,0,0,$month,$monthday,$year); #echo "monthday:$monthday\n"; } @@ -127,9 +132,11 @@ function expand_byday($time){ $week_arr = array(1,2,3,4,5); if(isset($byday_arr[2]) && $byday_arr[2] !='') $week_arr = array($byday_arr[2]); $month_start = strtotime(date("Ym00",$time)); + $month_end = strtotime(date("Ymt",$time))+ (36 * 60 * 60); foreach($week_arr as $week){ - #echo "
$summary".$byday_arr[1].$week.$on_day,date("Ymd",$month_start)."\n";
-					$next_date_time = strtotime($byday_arr[1].$week.$on_day,$month_start);
+				#	echo "
$summary".$byday_arr[1].$week.$on_day,date("Ymd",$month_start)."\n";
+					if($byday_arr[1] == '-') $next_date_time = strtotime($byday_arr[1].$week.$on_day,$month_end);
+					else $next_date_time = strtotime($byday_arr[1].$week.$on_day,$month_start);
 					# check that we're still in the same month
 					if (date("m",$next_date_time) == date("m",$time) ) $times[] = $next_date_time; 
 				}
@@ -165,7 +172,16 @@ function restrict_byyearday($times,$freq=''){
 	global $byyearday;
 	if(empty($byyearday)) return $times;
 	$new_times=array();
-	foreach ($times as $time) if(in_array(date("z", $time), $byyearday)) $new_times[] = $time;
+	foreach ($times as $time){
+		foreach ($byyearday as $yearday){
+			if($yearday < 0){
+				$yearday = 365 + $yearday +1;
+				if(date("L",$time)) $yearday += 1;
+			}	
+			$yearday_arr[] = $yearday;
+		}	
+		if(in_array(date("z", $time), $yearday_arr)) $new_times[] = $time;
+	}	
 	return $new_times;
 }
 
@@ -173,7 +189,13 @@ function restrict_bymonthday($times,$freq=''){
 	global $bymonthday;
 	if(empty($bymonthday)) return $times;
 	$new_times=array();
-	foreach ($times as $time) if(in_array(date("j", $time), $bymonthday)) $new_times[] = $time;
+	foreach ($times as $time){
+		foreach ($bymonthday as $monthday){
+			if($monthday < 0) $monthday = date("t",$time) + $monthday +1;
+			$monthday_arr[] = $monthday;
+		}	
+		if(in_array(date("j", $time), $monthday_arr)) $new_times[] = $time;
+	}	
 	return $new_times;
 }
 function restrict_byday($times,$freq=''){
diff --git a/includes/event.php b/includes/event.php
index 4a42f0c..c8c5865 100644
--- a/includes/event.php
+++ b/includes/event.php
@@ -75,6 +75,8 @@ switch ($event['status']){
 	case 'TENTATIVE':
 		$event['status'] =	$lang['l_status_tentative'] ; 
 		break;
+	default:	
+		$event['status'] =	'' ; 
 }
 
 $page = new Page(BASE.'templates/'.$template.'/event.tpl');
-- 
cgit v1.2.3