aboutsummaryrefslogtreecommitdiffstats
path: root/functions/ical_parser.php
diff options
context:
space:
mode:
authorJim Hu <jimhu@users.sourceforge.net>2006-04-09 00:32:48 +0000
committerJim Hu <jimhu@users.sourceforge.net>2006-04-09 00:32:48 +0000
commit0cc687c3b06462fde5b972db12259a15105fab0f (patch)
treef7f4420ae3fd680720f5618b8b5658c746921532 /functions/ical_parser.php
parent68326f92f68840d9bd0937ee72078a8883d3bef3 (diff)
downloadphpicalendar-0cc687c3b06462fde5b972db12259a15105fab0f.tar.gz
phpicalendar-0cc687c3b06462fde5b972db12259a15105fab0f.tar.bz2
phpicalendar-0cc687c3b06462fde5b972db12259a15105fab0f.zip
recur bug fix...add bysetpos support
Diffstat (limited to 'functions/ical_parser.php')
-rw-r--r--functions/ical_parser.php62
1 files changed, 59 insertions, 3 deletions
diff --git a/functions/ical_parser.php b/functions/ical_parser.php
index fe8ca33..855f782 100644
--- a/functions/ical_parser.php
+++ b/functions/ical_parser.php
@@ -459,8 +459,10 @@ foreach ($cal_filelist as $cal_key=>$filename) {
$master_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = localizeDate($dateFormat_week,$until);
break;
case 'INTERVAL':
+ if ($val > 0){
$number = $val;
$master_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = $number;
+ }
break;
case 'BYSECOND':
$bysecond = $val;
@@ -564,7 +566,7 @@ foreach ($cal_filelist as $cal_key=>$filename) {
case 'WEEKLY':
// Populate $byday with the default day if it's not set.
if (!isset($byday)) {
- $byday[] = strtoupper(substr($daysofweekshort_lang[date('w', $start_date_time)], 0, 2));
+ $byday[] = strtoupper(substr(date('D', $start_date_time), 0, 2));
}
if (is_array($byday)) {
foreach($byday as $day) {
@@ -591,7 +593,35 @@ foreach ($cal_filelist as $cal_key=>$filename) {
if (empty($bymonth)) $bymonth = array(1,2,3,4,5,6,7,8,9,10,11,12);
$next_range_time = strtotime(date('Y-m-01', $next_range_time));
$next_date_time = $next_date_time;
- if ((isset($bymonthday)) && (!isset($byday))) {
+ if (isset($bysetpos)){
+ /* bysetpos code from dustinbutler
+ start on day 1 or last day.
+ if day matches any BYDAY the count is incremented.
+ SETPOS = 4, need 4th match
+ SETPOS = -1, need 1st match
+ */
+ $year = date('Y', $next_range_time);
+ $month = date('m', $next_range_time);
+ if ($bysetpos > 0) {
+ $next_day = '+1 day';
+ $day = 1;
+ } else {
+ $next_day = '-1 day';
+ $day = $totalDays[$month];
+ }
+ $day = mktime(0, 0, 0, $month, $day, $year);
+ $countMatch = 0;
+ while ($countMatch != abs($bysetpos)) {
+ /* Does this day match a BYDAY value? */
+ $thisDay = $day;
+ $textDay = strtoupper(substr(date('D', $thisDay), 0, 2));
+ if (in_array($textDay, $byday)) {
+ $countMatch++;
+ }
+ $day = strtotime($next_day, $thisDay);
+ }
+ $recur_data[] = $thisDay;
+ }elseif ((isset($bymonthday)) && (!isset($byday))) {
foreach($bymonthday as $day) {
if ($day < 0) $day = ((date('t', $next_range_time)) + ($day)) + 1;
$year = date('Y', $next_range_time);
@@ -661,7 +691,33 @@ foreach ($cal_filelist as $cal_key=>$filename) {
} else {
$year = date('Y', $next_range_time);
}
-
+ if (isset($bysetpos)){
+ /* bysetpos code from dustinbutler
+ start on day 1 or last day.
+ if day matches any BYDAY the count is incremented.
+ SETPOS = 4, need 4th match
+ SETPOS = -1, need 1st match
+ */
+ if ($bysetpos > 0) {
+ $next_day = '+1 day';
+ $day = 1;
+ } else {
+ $next_day = '-1 day';
+ $day = date("t",$month);
+ }
+ $day = mktime(12, 0, 0, $month, $day, $year);
+ $countMatch = 0;
+ while ($countMatch != abs($bysetpos)) {
+ /* Does this day match a BYDAY value? */
+ $thisDay = $day;
+ $textDay = strtoupper(substr(date('D', $thisDay), 0, 2));
+ if (in_array($textDay, $byday)) {
+ $countMatch++;
+ }
+ $day = strtotime($next_day, $thisDay);
+ }
+ $recur_data[] = $thisDay;
+ }
if ((isset($byday)) && (is_array($byday))) {
$checkdate_time = mktime(0,0,0,$month,1,$year);
foreach($byday as $day) {

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