diff options
-rw-r--r-- | lib/VNDB/Func.pm | 17 | ||||
-rw-r--r-- | lib/VNDB/Handler/Misc.pm | 12 |
2 files changed, 16 insertions, 13 deletions
diff --git a/lib/VNDB/Func.pm b/lib/VNDB/Func.pm index 37bec8be..9abacad0 100644 --- a/lib/VNDB/Func.pm +++ b/lib/VNDB/Func.pm @@ -6,7 +6,7 @@ use warnings; use YAWF ':html'; use Exporter 'import'; use POSIX 'strftime'; -our @EXPORT = qw| shorten date datestr monthstr userstr bb2html gtintype liststat clearfloat cssicon |; +our @EXPORT = qw| shorten age date datestr monthstr userstr bb2html gtintype liststat clearfloat cssicon |; # I would've done this as a #define if this was C... @@ -16,6 +16,21 @@ sub shorten { } +# Argument: unix timestamp +# Returns: age +sub age { + my $a = time-$_[0]; + return sprintf '%d %s ago', + $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' ); +} + + # argument: unix timestamp and optional format (compact/full) # return value: yyyy-mm-dd # (maybe an idea to use cgit-style ages for recent timestamps) diff --git a/lib/VNDB/Handler/Misc.pm b/lib/VNDB/Handler/Misc.pm index dc6bda71..7f7fee45 100644 --- a/lib/VNDB/Handler/Misc.pm +++ b/lib/VNDB/Handler/Misc.pm @@ -45,18 +45,6 @@ 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; |