--- lib/TWiki/Plugins/CalendarPlugin.pm 12 Mar 2005 19:10:27 -0000 1.5 +++ lib/TWiki/Plugins/CalendarPlugin.pm 13 Apr 2005 14:30:40 -0000 @@ -26,7 +26,8 @@ # ========================= use vars qw( $web $topic $user $installWeb $VERSION $libsLoaded $libsError $defaultsInitialized %defaults ); -$VERSION = '1.016'; #dab# Added support for anniversary events; changed "our" to "my" in module to support perl versions prior to 5.6.0 +$VERSION = '1.017'; #dro# Added start and end date support for periodic repeaters; Added lang patch by JensKloecker; Changed "my" to "local" so exceptions working again; Removed fetchxmap debug message +#$VERSION = '1.016'; #dab# Added support for anniversary events; changed "our" to "my" in module to support perl versions prior to 5.6.0 #$VERSION = '1.015'; #pf# Added back support for preview showing unsaved events; Two loop fixes from DanielRohde #$VERSION = '1.014'; #nk# Added support for start and end dates in weekly repeaters #$VERSION = '1.013'; #mrjc# Added support for multiple sources in topic= @@ -106,6 +107,7 @@ weekstartsonmonday => '0', # other options not belonging to HTML::CalendarMonthSimple daynames => undef, # order is: Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday + lang => 'en', topic => $topic, web => $web, format => "" @@ -230,7 +232,6 @@ } } } - &TWiki::Func::writeDebug($ret{06}); return @ret; } @@ -270,7 +271,10 @@ # read and set the desired language my $lang = scalar &TWiki::Func::extractNameValuePair( $attributes, "lang" ); - Date::Calc::Language(Date::Calc::Decode_Language($lang)) if $lang; + $lang = $lang ? $lang : $defaults{lang}; + #Date::Calc::Language(Date::Calc::Decode_Language($lang)) if $lang; + Date::Calc::Language(Date::Calc::Decode_Language($lang)); + # get GMT offset my ($currentYear, $currentMonth, $currentDay, $currentHour, $currentMinute, $currentSecond) = Today_and_Now(1); @@ -293,12 +297,13 @@ my $cal = new HTML::CalendarMonthSimple(month => $m, year => $y, today_year => $currentYear, today_month => $currentMonth, today_date => $currentDay); # set the day names in the desired language - if ($lang) { +# if ($lang) { $cal->saturday(Date::Calc::Day_of_Week_to_Text(6)); $cal->sunday(Date::Calc::Day_of_Week_to_Text(7)); $cal->weekdays(map { Date::Calc::Day_of_Week_to_Text $_ } (1..5)); - } +# } + my $p = ""; while (($k,$v) = each %options) { $p = "HTML::CalendarMonthSimple::$k"; @@ -335,20 +340,20 @@ my @days = (); my ($descr, $d, $dd, $mm, $yy, $text) = ('', '', '', '', '', '' ); - my %months = ( Jan=>1, Feb=>2, Mar=>3, Apr=>4, May=>5, Jun=>6, + local %months = ( Jan=>1, Feb=>2, Mar=>3, Apr=>4, May=>5, Jun=>6, Jul=>7, Aug=>8, Sep=>9, Oct=>10, Nov=>11, Dec=>12); - my %wdays = ( Sun=>7, Mon=>1, Tue=>2, Wed=>3, Thu=>4, Fri=>5, Sat=>6); - my $days_rx = '[0-9]?[0-9]'; - my $months_rx = join ('|', keys %months); - my $wdays_rx = join ('|', keys %wdays); - my $years_rx = '[12][0-9][0-9][0-9]'; - my $date_rx = "($days_rx)\\s+($months_rx)"; - my $monthly_rx = "([1-6])\\s+($wdays_rx)"; - my $full_date_rx = "$date_rx\\s+($years_rx)"; - my $anniversary_date_rx = "A\\s+$date_rx\\s+($years_rx)"; - my $weekly_rx = "E\\s+($wdays_rx)"; - my $periodic_rx = "E([0-9]+)\\s+$full_date_rx"; - my $numdaymon_rx = "([0-9L])\\s+($wdays_rx)\\s+($months_rx)"; + local %wdays = ( Sun=>7, Mon=>1, Tue=>2, Wed=>3, Thu=>4, Fri=>5, Sat=>6); + local $days_rx = '[0-9]?[0-9]'; + local $months_rx = join ('|', keys %months); + local $wdays_rx = join ('|', keys %wdays); + local $years_rx = '[12][0-9][0-9][0-9]'; + local $date_rx = "($days_rx)\\s+($months_rx)"; + local $monthly_rx = "([1-6])\\s+($wdays_rx)"; + local $full_date_rx = "$date_rx\\s+($years_rx)"; + local $anniversary_date_rx = "A\\s+$date_rx\\s+($years_rx)"; + local $weekly_rx = "E\\s+($wdays_rx)"; + local $periodic_rx = "E([0-9]+)\\s+$full_date_rx"; + local $numdaymon_rx = "([0-9L])\\s+($wdays_rx)\\s+($months_rx)"; $text = getTopicText($theTopic, $theWeb, $refText, %options); # recursively expand includes @@ -542,8 +547,31 @@ } } } + + # collect periodic repeaters with start and end dates + @days = fetchDays( "$periodic_rx\\s+-\\s+$full_date_rx", \@bullets ); + foreach $d (@days) { + my ($p, $dd1, $mm1, $yy1, $dd2, $mm2, $yy2, $xs, $xcstr, $descr) = split( /\|/, $d); + if (length($xcstr) > 9) { + @xmap = &fetchxmap($xcstr, $y, $m); + } else { + @xmap = &emptyxmap($y, $m); + } + $mm1= $months{$mm1}; + while ( $yy1 < $y || ( $yy1==$y && $mm1 < $m )) { + ($yy1, $mm1, $dd1) = Add_Delta_Days($yy1, $mm1, $dd1, $p); + } + my $ldate = Date_to_Days ($yy2, $months{$mm2}, $dd2); + while ( ($yy1 == $y) && ($mm1 == $m) ) { + my $date = Date_to_Days($yy1, $mm1, $dd1); + if ($xmap[$dd1] && ($date <=$ldate)) { + &highlightDay( $cal, $dd1, $descr, %options ); + } + ($yy1, $mm1, $dd1) = Add_Delta_Days($yy1, $mm1, $dd1, $p); + } + } - # collect periodic repeaters + # collect periodic repeaters with start dates @days = fetchDays( "$periodic_rx", \@bullets ); foreach $d (@days) { ($p, $dd, $mm, $yy, $xs, $xcstr, $descr) = split( /\|/, $d);