--- Available.pm 2003/10/03 14:19:50 1.1 +++ Available.pm 2003/10/03 15:23:46 1.2 @@ -8,13 +8,6 @@ our @ISA = qw(Exporter); -# Items to export into callers namespace by default. Note: do not export -# names by default without a very good reason. Use EXPORT_OK instead. -# Do not simply export all your public functions/methods/constants. - -# This allows declaration use Time::Available ':all'; -# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK -# will save memory. our %EXPORT_TAGS = ( 'days' => [ qw( DAY_MONDAY @@ -27,14 +20,16 @@ DAY_WEEKDAY DAY_WEEKEND DAY_EVERYDAY - ) ] + ) ], + 'fmt_interval' => [ qw(fmt_interval) ] ); -our @EXPORT_OK = ( @{ $EXPORT_TAGS{'days'} } ); +our @EXPORT_OK = ( + @{ $EXPORT_TAGS{'days'} }, + @{ $EXPORT_TAGS{'fmt_interval'} } + ); -our @EXPORT = qw( - -); +our @EXPORT; # don't export anything by default! our $VERSION = '0.01'; @@ -163,7 +158,27 @@ return $s; } +# +# this auxillary function will pretty-format interval in [days]d hh:mm:ss +# + +sub fmt_interval { + my $s = shift || 0; + my $out = ""; + + my $d = int($s/(24*60*60)); + $s = $s % (24*60*60); + my $h = int($s/(60*60)); + $s = $s % (60*60); + my $m = int($s/60); + $s = $s % 60; + + $out .= $d."d " if ($d > 0); + $out .= sprintf("%02d:%02d:%02d",$h,$m,$s); + + return $out; +} 1; __END__ @@ -191,6 +206,10 @@ # calculate availablity in seconds from interval of uptime print $interval->interval($utime1,$utime2); + # pretty print interval data (this will produce output '1d 11:11:11') + use Time::Available qw(:fmt_interval); + print fmt_interval(126671); + =head1 DESCRIPTION Time::Available is used to calculate availability of some resource if start @@ -242,10 +261,15 @@ =head2 EXPORT -None by default. If you specify B<:days>, Time::Available will export all +None by default. + +If you specify B<:days>, Time::Available will export all DAY_* constraints to your enviroment (causing possible pollution of name space). You have been warned. +With B<:fmt_interval> it will include function B which will +pretty-format interval into [days]d hh:mm:ss. + =head1 HISTORY