treebird/perl/string_helpers.pm
nekobit d46209f0ee Relative time perl, emojis and attachment funcs
FossilOrigin-Name: 7a290aefc9a21f9789cb097ff99c1423fbf67a399f916ab2232e6eab7e83b460
2022-07-30 03:51:30 +00:00

19 lines
547 B
Perl

package string_helpers;
use strict;
use warnings;
use Exporter 'import';
our @EXPORT = qw( &reltime_to_str );
sub reltime_to_str
{
my $since = time() - $_[0];
return $since . 's' if $since < 60;
return int($since / 60) . 'm' if $since < 60 * 60;
return int($since / (60 * 60)) . 'h' if $since < 60 * 60 * 24;
return int($since / (60 * 60 * 24)) . 'd' if $since < 60 * 60 * 24 * 31;
return int($since / (60 * 60 * 24 * 31)) . 'mon' if $since < 60 * 60 * 24 * 365;
return int($since / (60 * 60 * 24 * 365)) . 'yr';
}