diff options
Diffstat (limited to 'lib/VNDB/Func.pm')
-rw-r--r-- | lib/VNDB/Func.pm | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/VNDB/Func.pm b/lib/VNDB/Func.pm new file mode 100644 index 00000000..9e948e0d --- /dev/null +++ b/lib/VNDB/Func.pm @@ -0,0 +1,26 @@ + +package VNDB::Func; + +use strict; +use warnings; +use Exporter 'import'; +use POSIX 'strftime'; +our @EXPORT = qw| shorten date |; + + +# I would've done this as a #define if this was C... +sub shorten { + my($str, $len) = @_; + return length($str) > $len ? substr($str, 0, $len-3).'...' : $str; +} + + +# argument: unix timestamp +# return value: yyyy-mm-dd +# (maybe an idea to use cgit-style ages for recent timestamps) +sub date { + return strftime '%Y-%m-%d', gmtime shift; +} + + +1; |