-
- $params{pmonth}=$pmonth;
- $params{nmonth}=$nmonth;
- $params{pyear} =$pyear;
- $params{nyear} =$nyear;
-
- my $calendar="\n";
- my $pagespec=$params{pages};
- my $page =$params{page};
-
- if (! defined $cache{$pagespec}) {
- foreach my $p (keys %pagesources) {
- next unless pagespec_match($p, $pagespec);
- my $mtime = $IkiWiki::pagectime{$p};
- my $src = $pagesources{$p};
- my @date = localtime($mtime);
- my $mday = $date[3];
- my $month = $date[4] + 1;
- my $year = $date[5] + 1900;
- my $mtag = sprintf("%02d", $month);
-
- # Only one posting per day is being linked to.
- $linkcache{"$year/$mtag/$mday"} = "$src";
- $cache{$pagespec}{"$year"}++;
- $cache{$pagespec}{"$year/$mtag"}++;
- $cache{$pagespec}{"$year/$mtag/$mday"}++;
+
+ $params{month} = sprintf("%02d", $params{month});
+
+ if ($params{type} eq 'month' && $params{year} == $thisyear
+ && $params{month} == $thismonth) {
+ # calendar for current month, updates next midnight
+ setnextchange($params{destpage}, ($time
+ + (60 - $now[0]) # seconds
+ + (59 - $now[1]) * 60 # minutes
+ + (23 - $now[2]) * 60 * 60 # hours
+ ));
+ }
+ elsif ($params{type} eq 'month' &&
+ (($params{year} == $thisyear && $params{month} > $thismonth) ||
+ $params{year} > $thisyear)) {
+ # calendar for upcoming month, updates 1st of that month
+ setnextchange($params{destpage},
+ timelocal(0, 0, 0, 1, $params{month}-1, $params{year}));
+ }
+ elsif (($params{type} eq 'year' && $params{year} == $thisyear) ||
+ $relativemonth) {
+ # Calendar for current year updates 1st of next month.
+ # Any calendar relative to the current month also updates
+ # then.
+ if ($thismonth < 12) {
+ setnextchange($params{destpage},
+ timelocal(0, 0, 0, 1, $thismonth+1-1, $params{year}));
+ }
+ else {
+ setnextchange($params{destpage},
+ timelocal(0, 0, 0, 1, 1-1, $params{year}+1));