From d4be55af095532abcb17cacb07de79520c1c4887 Mon Sep 17 00:00:00 2001 From: Jim Hu Date: Wed, 17 Dec 2008 06:58:52 +0000 Subject: progress on recurrence:until and byday changes --- calendars/Home.ics | 2 ++ functions/init/date_range.php | 2 +- functions/parse/end_vevent.php | 21 ++++++++++++++------- functions/parse/recur_functions.php | 28 ++++++++++++++-------------- month.php | 2 +- 5 files changed, 32 insertions(+), 23 deletions(-) diff --git a/calendars/Home.ics b/calendars/Home.ics index 693f3fd..415089f 100644 --- a/calendars/Home.ics +++ b/calendars/Home.ics @@ -69,6 +69,7 @@ DTSTART;TZID=US/Pacific:20020919T160000 DTEND;TZID=US/Pacific:20020919T180000 RRULE:FREQ=MONTHLY;UNTIL=20021223T075959;INTERVAL=1;BYMONTHDAY=19 END:VEVENT + BEGIN:VEVENT SEQUENCE:7 DTSTAMP:20020918T224617Z @@ -79,6 +80,7 @@ DTSTART;TZID=US/Pacific:20020920T150000 DURATION:PT1H30M RRULE:FREQ=WEEKLY;INTERVAL=2;BYDAY=TU,WE,FR END:VEVENT + BEGIN:VTODO SUMMARY:This is a todo item SEQUENCE:1 diff --git a/functions/init/date_range.php b/functions/init/date_range.php index b957b75..78b0db5 100644 --- a/functions/init/date_range.php +++ b/functions/init/date_range.php @@ -30,7 +30,7 @@ switch ($current_view){ case 'month': case 'week': case 'day': - $mArray_begin = mktime (0,0,0,$start_month,21,($start_year)); + $mArray_begin = mktime (0,0,0,$start_month,1,($start_year)); $mArray_end = mktime (0,0,0,$end_month,31,($end_year)); break; default: diff --git a/functions/parse/end_vevent.php b/functions/parse/end_vevent.php index a247729..47de2d4 100644 --- a/functions/parse/end_vevent.php +++ b/functions/parse/end_vevent.php @@ -212,13 +212,24 @@ $start_date_unixtime = strtotime($start_date); $next_range_unixtime = $start_date_unixtime; #conditions where we can not iterate over the whole range -if($count == 1000000 && $interval == 1) $next_range_unixtime = $mArray_begin; +if($count == 1000000){ + if($interval == 1) { + $next_range_unixtime = $mArray_begin; + }else{ + # can we calculate the right start time? + # pick the right compare function from date_functions.php + # $diff is the number of occurrences between start_date and next_range_time + # $func = $freq_type.'Compare'; + # $diff = $func(date('Ymd',strtotime($getdate)), $start_date); + # $next_range_unixtime = strtotime('+'.$diff*$interval.' '.$freq_type, $start_date_unixtime); echo "
$summary\nnext $freq_type $diff $freq_type".date("Ymd",$start_date_unixtime)."\n";
+	}
+}
 // if the beginning of our range is less than the start of the item, we may as well set it equal to it
 if ($next_range_unixtime < $start_date_unixtime) $next_range_unixtime = $start_date_unixtime;
 
 if(isset($until) && $end_range_unixtime > $until_unixtime) $end_range_unixtime = $until_unixtime;
 if($freq_type == 'year') $end_range_unixtime	+= 366*24*60*60;
-if(!isset($rrule_array['FREQ'])){ 
+if(!isset($rrule_array['FREQ']) && isset($end_date)){ 
 	$end_range_unixtime = strtotime($end_date);
 	$count = 1;
 }
@@ -228,15 +239,11 @@ $wkst3char = two2threeCharDays($wkst);
 /* The while loop below increments $next_range_time by $freq type. For the larger freq types, there is only 
 one $next_range_time per repeat, but the BYXXX rules may write more than one event in that repeat cycle
 $next_date_time handles those instances within a $freq_type */
-#echo "
$summary\n\tstart mArray time:".date("Ymd his",$mArray_begin)."\n\tstart range time:".date("Ymd his",$next_range_unixtime)."\n\tend range time ".date("Ymd his",$end_range_unixtime)."\n";
+#echo "
$summary\n\tstart mArray time:".date("Ymd his",$mArray_begin)."\n\tnext_range_unixtime:".date("Ymd his",$next_range_unixtime)."\n\tend range time ".date("Ymd his",$end_range_unixtime)."\n";
 $recur_data = array();
 while ($next_range_unixtime <= $end_range_unixtime && $count > 0) {
 	$year = date('Y', $next_range_unixtime); 
 	$month = date('m', $next_range_unixtime); 
-	# pick the right compare function from date_functions.php
-	# $diff is the number of occurrences between start_date and next_range_time
-	$func = $freq_type.'Compare';
-	$diff = $func(date('Ymd',$next_range_time), $start_date);
 	$time = mktime(12,0,0,$month,date("d",$start_unixtime),$year);
 	switch ($freq_type){
 		case 'day':
diff --git a/functions/parse/recur_functions.php b/functions/parse/recur_functions.php
index 975d95d..1b6b8c0 100644
--- a/functions/parse/recur_functions.php
+++ b/functions/parse/recur_functions.php
@@ -24,25 +24,28 @@ BYxxx rule parts modify the recurrence in some manner. BYxxx rule
 */
 
 function add_recur($times,$freq=''){
-	global $recur_data, $count, $mArray_begin, $mArray_end, $except_dates;	
+	global $recur_data, $count, $mArray_begin, $mArray_end, $except_dates, $start_date_unixtime,$until_unixtime;	
 	if (!is_array($times)) $times = array($times);
-	$times = array_unique($times);
-	sort($times); 
 	#echo "add_recur";dump_times($times);
 	/*BYMONTH, BYWEEKNO, BYYEARDAY, BYMONTHDAY, BYDAY, BYHOUR,
    BYMINUTE, BYSECOND and BYSETPOS*/
 	$times = restrict_bymonth($times,$freq); 
-
 	$times = restrict_byweekno($times,$freq);
 	$times = restrict_byyearday($times,$freq);
 	$times = restrict_bymonthday($times,$freq);
 	$times = restrict_byday($times,$freq);
 	$times = restrict_bysetpos($times,$freq);#echo "restrict_bysetpos";dump_times($times);
-
+	$times[] = $start_date_unixtime;
+	$times = array_unique($times);
+	sort($times); 
+	$until_date = date("Ymd",$until_unixtime);
 	foreach ($times as $time){ 
 		#echo "time:". date("Ymd",$time);
-		if(isset($time) && !in_array(date("Ymd",$time), $except_dates)) $count--; 
-		if($time >= $mArray_begin && $time <= $mArray_end && $count >= 0) $recur_data[] = $time;
+		$date = date("Ymd",$time);
+		if(isset($time) && !in_array($date, $except_dates) && $time >= $start_date_unixtime && $date <= $until_date){ 
+			$count--; 
+			if($time >= $mArray_begin && $time <= $mArray_end && $count >= 0) $recur_data[] = $time;
+		}
 	}
 	return;
 }
@@ -101,8 +104,9 @@ function expand_bymonthday($times){
 function expand_byday($time){
 	global $freq_type, $byday, $wkst3char, $year, $month, $start_unixtime,$summary;
 	if (empty($byday)) return array($time);
+	$times = array();
 	$the_sunday = dateOfWeek(date("Ymd",$time), $wkst3char);
-#	echo "$freq_type, ".print_r($byday,true)."$wkst3char $the_sunday";
+	#echo "
$summary $freq_type ".print_r($byday,true)."$wkst3char $the_sunday
"; foreach($byday as $key=>$day) { /* set $byday_arr [0] => byday string, e.g. 4TH @@ -114,12 +118,8 @@ function expand_byday($time){ $on_day = two2threeCharDays($byday_arr[3]); switch($freq_type){ case 'week': - #need to find the first day of the appropriate week. - if ($key == 0){ - $next_date_time = strtotime("next $on_day",strtotime($the_sunday)) + (12 * 60 * 60); - }else{ - $next_date_time = strtotime("next $on_day",$next_date_time) + (12 * 60 * 60); - } + #need to find the first day of the appropriate week. + $next_date_time = strtotime("this $on_day",strtotime($the_sunday)) + (12 * 60 * 60); $times[] = $next_date_time; break; case 'month': diff --git a/month.php b/month.php index 9811669..989fe9e 100644 --- a/month.php +++ b/month.php @@ -125,7 +125,7 @@ if ($phpiCal_config->show_search != 'yes') { $page->nosearch($page); } -if ($this_months_events == 'yes') { +if ($phpiCal_config->this_months_events == 'yes') { $page->monthbottom($page); } else { $page->nomonthbottom($page); -- cgit v1.2.3