aboutsummaryrefslogtreecommitdiffstats
path: root/functions
diff options
context:
space:
mode:
authorJim Hu <jimhu@users.sourceforge.net>2008-12-17 06:58:52 +0000
committerJim Hu <jimhu@users.sourceforge.net>2008-12-17 06:58:52 +0000
commitd4be55af095532abcb17cacb07de79520c1c4887 (patch)
tree41c55adaf3e101568820fa25b8a33e7216468bfb /functions
parentfd14e5ce0beec32d38078064a865161433f33a06 (diff)
downloadphpicalendar-d4be55af095532abcb17cacb07de79520c1c4887.tar.gz
phpicalendar-d4be55af095532abcb17cacb07de79520c1c4887.tar.bz2
phpicalendar-d4be55af095532abcb17cacb07de79520c1c4887.zip
progress on recurrence:until and byday changes
Diffstat (limited to 'functions')
-rw-r--r--functions/init/date_range.php2
-rw-r--r--functions/parse/end_vevent.php21
-rw-r--r--functions/parse/recur_functions.php28
3 files changed, 29 insertions, 22 deletions
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 "<pre>$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 "<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\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 "<pre>$summary $freq_type ".print_r($byday,true)."$wkst3char $the_sunday</pre>";
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':

© 2014-2024 Faster IT GmbH | imprint | privacy policy