diff options
author | Jim Hu <jimhu@users.sourceforge.net> | 2008-12-16 19:48:23 +0000 |
---|---|---|
committer | Jim Hu <jimhu@users.sourceforge.net> | 2008-12-16 19:48:23 +0000 |
commit | fd14e5ce0beec32d38078064a865161433f33a06 (patch) | |
tree | 1e21f4a4f62f348e55a146634bb01370c21dff71 /functions | |
parent | ac501f092835e07d6d4683f29824f9b54e7ee162 (diff) | |
download | phpicalendar-fd14e5ce0beec32d38078064a865161433f33a06.tar.gz phpicalendar-fd14e5ce0beec32d38078064a865161433f33a06.tar.bz2 phpicalendar-fd14e5ce0beec32d38078064a865161433f33a06.zip |
progress on recurrence
Diffstat (limited to 'functions')
-rw-r--r-- | functions/parse/end_vevent.php | 14 | ||||
-rw-r--r-- | functions/parse/recur_functions.php | 38 |
2 files changed, 31 insertions, 21 deletions
diff --git a/functions/parse/end_vevent.php b/functions/parse/end_vevent.php index 54c0c9a..a247729 100644 --- a/functions/parse/end_vevent.php +++ b/functions/parse/end_vevent.php @@ -228,7 +228,7 @@ $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 "<pre>$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 "<pre>$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"; $recur_data = array(); while ($next_range_unixtime <= $end_range_unixtime && $count > 0) { $year = date('Y', $next_range_unixtime); @@ -237,6 +237,7 @@ while ($next_range_unixtime <= $end_range_unixtime && $count > 0) { # $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': add_recur($next_range_unixtime); @@ -245,17 +246,16 @@ while ($next_range_unixtime <= $end_range_unixtime && $count > 0) { add_recur(expand_byday($next_range_unixtime)); break; case 'month': - $time = mktime(12,0,0,$month,date("d",$start_unixtime),$year); $times = expand_bymonthday(array($time)); foreach($times as $time){ add_recur(expand_byday($time)); } break; case 'year': - $times = expand_bymonth($next_range_unixtime); - $times = expand_byweekno($times); - $times = expand_byyearday($times); - $times = expand_bymonthday($times); + $times = expand_bymonth($time); #echo "exp bymonth";dump_times($times); + $times = expand_byweekno($times); #echo "exp bymonth";dump_times($times); + $times = expand_byyearday($times); #echo "exp bymonth";dump_times($times); + $times = expand_bymonthday($times); #echo "exp bymonthday";dump_times($times); foreach($times as $time){ add_recur(expand_byday($time)); } @@ -264,7 +264,7 @@ while ($next_range_unixtime <= $end_range_unixtime && $count > 0) { add_recur($start_unixtime); break 2; } - $next_range_unixtime = strtotime('+'.$interval.' '.$freq_type, $next_range_unixtime); echo "\nnext $interval $freq_type".date("Ymd",$next_range_unixtime)."\n"; + $next_range_unixtime = strtotime('+'.$interval.' '.$freq_type, $next_range_unixtime); #echo "\nnext $interval $freq_type".date("Ymd",$next_range_unixtime)."\n"; } #end while loop sort($recur_data); diff --git a/functions/parse/recur_functions.php b/functions/parse/recur_functions.php index 6b970b6..975d95d 100644 --- a/functions/parse/recur_functions.php +++ b/functions/parse/recur_functions.php @@ -28,17 +28,19 @@ function add_recur($times,$freq=''){ 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_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); + $times = restrict_bysetpos($times,$freq);#echo "restrict_bysetpos";dump_times($times); foreach ($times as $time){ - echo "time:". date("Ymd",$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; } @@ -84,14 +86,20 @@ function expand_byyearday($times){ } function expand_bymonthday($times){ - global $bymonthday, $year, $month; + global $bymonthday, $year; if (empty($bymonthday)) return $times; - foreach($times as $time) foreach($bymonthday as $monthday) $new_times[] = mktime(12,0,0,$month,$monthday,$year); + foreach($times as $time){ + $month = date('m',$time); + foreach($bymonthday as $monthday){ + $new_times[] = mktime(12,0,0,$month,$monthday,$year); + #echo "monthday:$monthday\n"; + } + } return $new_times; } function expand_byday($time){ - global $freq_type, $byday, $wkst3char, $year, $month, $start_unixtime; + global $freq_type, $byday, $wkst3char, $year, $month, $start_unixtime,$summary; if (empty($byday)) return array($time); $the_sunday = dateOfWeek(date("Ymd",$time), $wkst3char); # echo "$freq_type, ".print_r($byday,true)."$wkst3char $the_sunday"; @@ -117,12 +125,13 @@ function expand_byday($time){ case 'month': case 'year': $week_arr = array(1,2,3,4,5); - if(isset($byday_arr[2])) $week_arr = array($byday_arr[2]); - $month_start = strtotime(date("Ym01",$time)); + if(isset($byday_arr[2]) && $byday_arr[2] !='') $week_arr = array($byday_arr[2]); + $month_start = strtotime(date("Ym00",$time)); foreach($week_arr as $week){ + #echo "<pre>$summary".$byday_arr[1].$week.$on_day,date("Ymd",$month_start)."\n"; $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",$month_start) ) $times[] = $next_date_time; + if (date("m",$next_date_time) == date("m",$time) ) $times[] = $next_date_time; } break; default: @@ -130,7 +139,7 @@ function expand_byday($time){ $next_date_time = strtotime($byday_arr[1].$byday_arr[2].$on_day, $month_start); } } - dump_times($times); + #echo "exp byday";dump_times($times); return $times; } @@ -196,10 +205,11 @@ function restrict_bysetpos($times,$freq=''){ return $new_times; } -function dump_times($recur_data){ +# for diagnostics +function dump_times($times){ global $summary; - echo "<pre>$summary recur_data:"; - var_dump($recur_data); - foreach($recur_data as $time) echo "\n".date("Ymd his",$time); + echo "<pre>$summary times:"; + var_dump($times); + foreach($times as $time) echo "\ndate:".date("Ymd his",$time); echo "</pre>"; } |