+sub previousmonth($$$) {
+ my $year = shift;
+ my $month = shift;
+ my $archivebase = shift;
+
+ if (not exists $wikistate{calendar}{minyear}) {
+ $wikistate{calendar}{minyear} = $year;
+ }
+
+ my $pmonth = $month;
+ my $pyear = $year;
+ while ((not exists $pagesources{"$archivebase/$pyear/" . sprintf("%02d", $pmonth)}) or ($pmonth == $month and $pyear == $year)) {
+ $pmonth -= 1;
+ if ($pmonth == 0) {
+ $pyear -= 1;
+ $pmonth = 12;
+ return ($pyear, $pmonth, 0) unless $pyear >= $wikistate{calendar}{minyear};
+ }
+ }
+ return ($pyear, $pmonth, 1);
+}
+
+sub nextmonth($$$) {
+ my $year = shift;
+ my $month = shift;
+ my $archivebase = shift;
+
+ if (not exists $wikistate{calendar}{maxyear}) {
+ $wikistate{calendar}{maxyear} = $year;
+ }
+
+ my $nmonth = $month;
+ my $nyear = $year;
+ while ((not exists $pagesources{"$archivebase/$nyear/" . sprintf("%02d", $nmonth)}) or ($nmonth == $month and $nyear == $year)) {
+ $nmonth += 1;
+ if ($nmonth == 13) {
+ $nyear += 1;
+ $nmonth = 1;
+ return ($nyear, $nmonth, 0) unless $nyear <= $wikistate{calendar}{maxyear};
+ }
+ }
+ return ($nyear, $nmonth, 1);
+}
+
+sub previousyear($$) {
+ my $year = shift;
+ my $archivebase = shift;
+
+ my $pyear = $year - 1;
+ while (not exists $pagesources{"$archivebase/$pyear"}) {
+ $pyear -= 1;
+ return ($pyear, 0) unless ($pyear >= $wikistate{calendar}{minyear});
+ }
+ return ($pyear, 1);
+}
+
+sub nextyear($$) {
+ my $year = shift;
+ my $archivebase = shift;
+
+ my $nyear = $year + 1;
+ while (not exists $pagesources{"$archivebase/$nyear"}) {
+ $nyear += 1;
+ return ($nyear, 0) unless ($nyear <= $wikistate{calendar}{maxyear});
+ }
+ return ($nyear, 1);
+}
+