added years filter for swish to support 1983- notation
[webpac] / filter / swish_years.pm
diff --git a/filter/swish_years.pm b/filter/swish_years.pm
new file mode 100644 (file)
index 0000000..e9eb2d7
--- /dev/null
@@ -0,0 +1,29 @@
+# rewrite interval years into separate values for indexing
+#
+# e.g. 1998- will be indexed as 1998 1999 2000 2001 2002 2003
+#      1993-1995 will be 1993 1994 1995
+
+sub swish_years {
+       my $out = "";
+       foreach (@_) {
+               if (/(\d{4})\s*-\s*(\d{4})/) {
+                       my ($from,$to) = ($1,$2);
+                       for (my $i=$from; $i<=$to; $i++) {
+                               $out .= $i." ";
+                       }
+               } elsif (/(\d{4})-/) {
+                       my $from = $1;
+                       my @t = localtime(time);
+                       my $to = $t[5];
+                       $to += 1900;
+                       for (my $i=$from; $i<=$to; $i++) {
+                               $out .= $i." ";
+                       }
+               } else {
+                       $out .= "$_ ";
+               }
+       }
+       return $out;
+}
+
+1;