summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--IkiWiki/Plugin/calendar.pm42
-rw-r--r--debian/changelog2
2 files changed, 35 insertions, 9 deletions
diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm
index fe7ee0361..9cbfd769d 100644
--- a/IkiWiki/Plugin/calendar.pm
+++ b/IkiWiki/Plugin/calendar.pm
@@ -318,24 +318,48 @@ EOF
sub preprocess (@) {
my %params=@_;
+
+ my $thisyear=1900 + $now[5];
+ my $thismonth=1 + $now[4];
+
$params{pages} = "*" unless defined $params{pages};
$params{type} = "month" unless defined $params{type};
- $params{month} = sprintf("%02d", $params{month}) if defined $params{month};
$params{week_start_day} = 0 unless defined $params{week_start_day};
$params{months_per_row} = 3 unless defined $params{months_per_row};
-
- if (! defined $params{year} || ! defined $params{month}) {
- # Record that the calendar next changes at midnight.
+ $params{year} = $thisyear unless defined $params{year};
+ $params{month} = $thismonth unless defined $params{month};
+
+ $params{month} = sprintf("%02d", $params{month});
+
+ if ($params{type} eq 'month' && $params{year} == $thisyear
+ && $params{month} == $thismonth) {
+ # calendar for current month, updates next midnight
$pagestate{$params{destpage}}{calendar}{nextchange}=($time
+ (60 - $now[0]) # seconds
+ (59 - $now[1]) * 60 # minutes
+ (23 - $now[2]) * 60 * 60 # hours
);
-
- $params{year} = 1900 + $now[5] unless defined $params{year};
- $params{month} = 1 + $now[4] unless defined $params{month};
+ }
+ elsif ($params{type} eq 'month' &&
+ (($params{year} == $thisyear && $params{month} > $thismonth) ||
+ $params{year} > $thisyear)) {
+ # calendar for upcoming month, updates 1st of that month
+ $pagestate{$params{destpage}}{calendar}{nextchange}=
+ timelocal(0, 0, 0, 1, $params{month}-1, $params{year});
+ }
+ elsif ($params{type} eq 'year' && $params{year} == $thisyear) {
+ # calendar for current year, updates 1st of next month
+ $pagestate{$params{destpage}}{calendar}{nextchange}=
+ timelocal(0, 0, 0, 1, $thismonth+1-1, $params{year});
+ }
+ elsif ($params{type} eq 'year' && $params{year} > $thisyear) {
+ # calendar for upcoming year, updates 1st of that year
+ $pagestate{$params{destpage}}{calendar}{nextchange}=
+ timelocal(0, 0, 0, 1, 1-1, $params{year});
}
else {
+ # calendar for past month or year, does not need
+ # to update any more
delete $pagestate{$params{destpage}}{calendar};
}
@@ -356,10 +380,10 @@ sub preprocess (@) {
}
my $calendar="";
- if ($params{type} =~ /month/i) {
+ if ($params{type} eq 'month') {
$calendar=format_month(%params);
}
- elsif ($params{type} =~ /year/i) {
+ elsif ($params{type} eq 'year') {
$calendar=format_year(%params);
}
diff --git a/debian/changelog b/debian/changelog
index 0e288dd08..c64758a77 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -28,6 +28,8 @@ ikiwiki (3.2009XXXX) UNRELEASED; urgency=low
* Transitive dependencies are now correctly supported.
* ikiwiki-calendar: New command automates creation of archive pages
using the calendar plugin.
+ * calendar: Fix midnight rebuild trigger of calendars with explicit
+ month/year.
-- Joey Hess <joeyh@debian.org> Fri, 09 Oct 2009 19:53:50 -0400