PTools::Time::Elapsed - Create formatted string with elapsed time
This document describes version 0.05, released Dec, 2003.
use PTools::Time::Elapsed; $et = new PTools::Time::Elapsed; $str = $et->convert( $elapsed_seconds ); or $str = $et->convert( $starttime, $endtime ); $str = $et->cvt_secs_print( $elapsed_seconds ); or $str = $et->cvt_secs_print( $starttime, $endtime ); $str = $et->days( $elapsed_seconds ); or $str = $et->days( $starttime, $endtime ); $str = $et->hours( $elapsed_seconds ); or $str = $et->hours( $starttime, $endtime ); $str = $et->granular( $elapsed_seconds ); or $str = $et->granular( $starttime, $endtime ); (@ary) = $et->convertArgs( $elapsed_seconds ); or (@ary) = $et->convertArgs( $starttime, $endtime );
This module is based on the cvt_secs_print() subroutine by Douglas B. Robinson.
A constructor method is provided for convenience. All methods work equally well as class or object methods as shown below.
$et = new PTools::Time::Elapsed;
The convert method returns a human readable time string from a given number of seconds.
$str = $et->convert( $elapsed_seconds ); or $str = $et->convert( $starttime, $endtime );
The convert method can also be invoked using the original subroutine name.
$str = $et->cvt_secs_print( $elapsed_seconds ); or $str = $et->cvt_secs_print( $starttime, $endtime );
Note: All methods work as both object methods (shown above) and as class methods (shown here).
$str = PTools::Time::Elapsed->convert( $elapsed_seconds ); or $str = PTools::Time::Elapsed->convert( $starttime, $endtime );
For all of the above, $str result might equal "1 hour, 51 seconds", for example.
The days method exists to return the result in days with any hours represented as a decimal value.
$str = $et->days( $elapsed_seconds ); or $str = $et->days( $starttime, $endtime );
Where $str result might equal "0.04 days", for example.
The hours method exists to return the result in hours with any minutes represented as a decimal value.
$str = $et->hours( $elapsed_seconds ); or $str = $et->hours( $starttime, $endtime );
Where $str result might equal "1.00 hours", for example.
The granular method exists to provide for a more "granular" result (in terms of the "most significant" element).
$str = $et->granular( $elapsed_seconds ); or $str = $et->granular( $starttime, $endtime );
Where $str result might equal "1.00 hrs", for example.
The convertArgs method provides the raw values for each of the elements.
(@ary) = $et->convertArgs( $elapsed_seconds ); or (@ary) = $et->convertArgs( $starttime, $endtime );
Where @ary params = ($yrs,$days,$hrs,$mins,$secs) and @ary result might equal (0,0,1,0,51) for example.
No classes currently inherit from this class.
Chris Cobb [no dot spam at ccobb dot net]
Copyright (c) 2002-2007 by Chris Cobb. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install PTools, copy and paste the appropriate command in to your terminal.
cpanm
cpanm PTools
CPAN shell
perl -MCPAN -e shell install PTools
For more information on module installation, please visit the detailed CPAN module installation guide.