X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;ds=sidebyside;f=events.pm;h=5994ba6571c94174bcae84d89c7d6f69eb5afbe2;hb=HEAD;hp=2820c60b70e187471614190af77be7f8ef996d96;hpb=d8aede5b74879b2369cd12964f0039e89231d934;p=ikiwiki%2Fevents.git
diff --git a/events.pm b/events.pm
index 2820c60..5994ba6 100644
--- a/events.pm
+++ b/events.pm
@@ -217,7 +217,8 @@ sub event_of_page ($%) {
, linktext => $title
, noimageinline => 1
, title => $title );
- add_depends($params{page}, $event, deptype('content'));
+ #add_depends($params{page}, $event, deptype('content'));
+ # NOTE: useless now that deptype('content') is default.
#add_depends($params{page}, $tag, deptype('content'));
# XXX: much too heavy :\ and midnight refresh may fix it anyway.
my $class = qq{$tag};
@@ -370,8 +371,8 @@ sub preprocess_day (@) {
= pagespec_match_list
( $params{page}
, $params{pages}
- , deptype => deptype("presence")
- # NOTE: add presence dependencies to update calendar when pages are added/removed
+ , deptype => deptype("content")
+ # NOTE: add content dependency to update calendar when pages are tagged
);
my $event_html
= event_html
@@ -416,13 +417,15 @@ sub preprocess_month (@) {
= pagespec_match_list
( $params{page}
, $params{pages}
- , deptype => deptype("presence")
- # NOTE: add presence dependencies to update calendar when pages are added/removed
+ , deptype => deptype("content")
+ # NOTE: add presence dependency to update calendar when pages are tagged
);
my %events_by_day = map {($_=>[])} (1 .. $last_day);
foreach my $event (events_of_pages(\@pages, %params)) {
- push @{$events_by_day{$event->{date}->{day}}}, $event;
+ my $day = $event->{date}->{day};
+ push @{$events_by_day{$day}}, $event
+ if defined $day;
}
my $t='
';
@@ -519,22 +522,35 @@ sub preprocess (@) {
: gettext('Agenda');
}
- my %focus_set;
- if (defined $params{day} and $params{day} =~ m/^(\d+)$/) {
- my ($day) = ($1);
- $focus_set{day} = $day;
+ my %focus_set =
+ ( day => $params{focus}->day()
+ , month => $params{focus}->month()
+ , year => $params{focus}->year()
+ );
+ if (defined $params{year} and $params{year} =~ m/^(\d+)$/) {
+ my ($year) = ($1);
+ $focus_set{year} = $year;
}
- if (defined $params{month} and $params{month} =~ m/^(\d+)$/) {
+ if (defined $params{month} and $params{month} =~ m/^(\d+)$/ and ($params{type} eq 'month' or $params{type} eq 'day')) {
my ($month) = ($1);
$focus_set{month} = $month;
}
- if (defined $params{year} and $params{year} =~ m/^(\d+)$/) {
- my ($year) = ($1);
- $focus_set{year} = $year;
+ if (defined $params{day} and $params{day} =~ m/^(\d+)$/ and $params{type} eq 'day') {
+ my ($day) = ($1);
+ $focus_set{day} = $day;
+ }
+ if (not defined $focus_set{day}) {
+ $focus_set{day} = 1;
+ }
+ else {
+ my $month = DateTime->new(year => $focus_set{year}, month => $focus_set{month}, day => 1);
+ my $last_day_of_month = $month->add(months => 1)->subtract(days => 1)->day();
+ $focus_set{day} = $last_day_of_month
+ if $focus_set{day} > $last_day_of_month;
}
$params{focus}->set(%focus_set);
- if (defined $params{day} and $params{day} =~ m/^([+-])(\d+)$/) {
+ if (defined $params{day} and $params{day} =~ m/^([+-])(\d+)$/ and $params{type} eq 'day') {
my ($sign, $days) = ($1, $2);
my $duration = DateTime::Duration->new(days => $days, end_of_month => 'limit');
$params{focus}
@@ -542,7 +558,7 @@ sub preprocess (@) {
? $params{focus}->add_duration($duration)
: $params{focus}->subtract_duration($duration);
}
- if (defined $params{month} and $params{month} =~ m/^([+-])(\d+)$/) {
+ if (defined $params{month} and $params{month} =~ m/^([+-])(\d+)$/ and ($params{type} eq 'month' or $params{type} eq 'day')) {
my ($sign, $months) = ($1, $2);
my $duration = DateTime::Duration->new(months => $months, end_of_month => 'limit');
$params{focus}