Is there a CPAN module that can convert a number of seconds to a human-readable English description of the interval?
secToEng( 125 ); # => 2 min 5 sec
secToEng( 129_600 ); # => 1 day 12 h
The format isn't important as long as it's human-readable.
I know that it would be trivial to implement.
It turns out that Time::Duration does exactly this.
$ perl -MTime::Duration -E 'say duration(125)'
2 minutes and 5 seconds
$ perl -MTime::Duration -E 'say duration(129_700)'
1 day and 12 hours
From the synopsis:
Time::Duration - rounded or exact English expression of durations
Example use in a program that ends by noting its runtime:
my $start_time = time(); use Time::Duration; # then things that take all that time, and then ends: print "Runtime ", duration(time() - $start_time), ".\n";
Example use in a program that reports age of a file:
use Time::Duration; my $file = 'that_file'; my $age = $^T - (stat($file))[9]; # 9 = modtime print "$file was modified ", ago($age);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With