diff options
author | applehq <theappleman@gmail.com> | 2008-12-17 11:11:19 +0000 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2008-12-17 13:56:04 +0100 |
commit | d310aecaca9aabec942e564dc3a180451b3499bc (patch) | |
tree | a45dbf82effb3fd5791b74e0bdd55d0bc07f4bf3 /lib | |
parent | 432dd0e2de9e4abbd3eb59b36aae8e61341e266f (diff) |
Homepage: Use relative age
Diffstat (limited to 'lib')
-rw-r--r-- | lib/VNDB/Handler/Misc.pm | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/VNDB/Handler/Misc.pm b/lib/VNDB/Handler/Misc.pm index 154312b0..dc6bda71 100644 --- a/lib/VNDB/Handler/Misc.pm +++ b/lib/VNDB/Handler/Misc.pm @@ -45,6 +45,18 @@ YAWF::register( ); +sub age { + my $a = time-$_[0]; + return sprintf '%d %s%s', + $a > 60*60*24*365*2 ? ( $a/60/60/24/365, 'years' ) : + $a > 60*60*24*(365/12)*2 ? ( $a/60/60/24/(365/12), 'months' ) : + $a > 60*60*24*7*2 ? ( $a/60/60/24/7, 'weeks' ) : + $a > 60*60*24*2 ? ( $a/60/60/24, 'days' ) : + $a > 60*60*2 ? ( $a/60/60, 'hours' ) : + $a > 60*2 ? ( $a/60, 'min' ) : + ( $a, 'sec' ), + $_[1]?'':' ago'; +} sub homepage { my $self = shift; @@ -117,7 +129,7 @@ sub homepage { ul; for (@$posts) { li; - txt date($_->{ldate}).' '; + txt age($_->{ldate}).' '; a href => "/t$_->{id}.$_->{count}", title => $_->{title}, shorten $_->{title}, 20; txt ' by '; a href => "/u$_->{luid}", $_->{lusername}; |