summaryrefslogtreecommitdiff
path: root/lib/VNDB
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2008-11-12 15:02:42 +0100
committerYorhel <git@yorhel.nl>2008-11-12 15:02:42 +0100
commit8209ca6017e5ccff8cc0597eab03dc6ffc2ed599 (patch)
tree1e36b00b5ad6eea977f0765e4638f9e3d8028d53 /lib/VNDB
parent727714378e8eb8a8c1ebd8a4b7d69df0148a1e4e (diff)
Added datestr() and fixed the release date display on producer pages
Diffstat (limited to 'lib/VNDB')
-rw-r--r--lib/VNDB/Func.pm25
-rw-r--r--lib/VNDB/Handler/Producers.pm5
2 files changed, 27 insertions, 3 deletions
diff --git a/lib/VNDB/Func.pm b/lib/VNDB/Func.pm
index 9e948e0d..0bfd58de 100644
--- a/lib/VNDB/Func.pm
+++ b/lib/VNDB/Func.pm
@@ -5,7 +5,7 @@ use strict;
use warnings;
use Exporter 'import';
use POSIX 'strftime';
-our @EXPORT = qw| shorten date |;
+our @EXPORT = qw| shorten date datestr |;
# I would've done this as a #define if this was C...
@@ -23,4 +23,25 @@ sub date {
}
-1;
+# argument: database release date format (yyyymmdd)
+# y = 0000 -> unkown
+# y = 9999 -> TBA
+# m = 99 -> month+day unkown
+# d = 99 -> day unknown
+# return value: (unknown|TBA|yyyy|yyyy-mm|yyyy-mm-dd)
+# if date > now: <b class="future">str</b>
+sub datestr {
+ my $date = sprintf '%08d', shift||0;
+ my $future = $date > strftime '%Y%m%d', gmtime;
+ my($y, $m, $d) = ($1, $2, $3) if $date =~ /^([0-9]{4})([0-9]{2})([0-9]{2})$/;
+
+ my $str = $y == 0 ? 'unknown' : $y == 9999 ? 'TBA' :
+ $m == 99 ? sprintf('%04d', $y) :
+ $d == 99 ? sprintf('%04d-%02d', $y, $m) :
+ sprintf('%04d-%02d-%02d', $y, $m, $d);
+
+ return $str if !$future;
+ return qq|<b class="future">$str</b>|;
+}
+
+
diff --git a/lib/VNDB/Handler/Producers.pm b/lib/VNDB/Handler/Producers.pm
index 2583ad13..d2bfa6db 100644
--- a/lib/VNDB/Handler/Producers.pm
+++ b/lib/VNDB/Handler/Producers.pm
@@ -4,6 +4,7 @@ package VNDB::Handler::Producers;
use strict;
use warnings;
use YAWF ':html';
+use VNDB::Func;
YAWF::register(
@@ -42,7 +43,9 @@ sub page {
ul;
for (@{$p->{vn}}) {
li;
- txt "$_->{date} ";
+ i;
+ lit datestr $_->{date};
+ end;
a href => "/v$_->{id}", title => $_->{original}, $_->{title};
end;
}