/[Time-Available]/Available.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /Available.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by dpavlin, Fri Oct 3 14:19:50 2003 UTC revision 1.2 by dpavlin, Fri Oct 3 15:23:46 2003 UTC
# Line 8  require Exporter; Line 8  require Exporter;
8    
9  our @ISA = qw(Exporter);  our @ISA = qw(Exporter);
10    
 # 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.  
11  our %EXPORT_TAGS = (  our %EXPORT_TAGS = (
12          'days' => [ qw(          'days' => [ qw(
13                  DAY_MONDAY                  DAY_MONDAY
# Line 27  our %EXPORT_TAGS = ( Line 20  our %EXPORT_TAGS = (
20                  DAY_WEEKDAY                  DAY_WEEKDAY
21                  DAY_WEEKEND                  DAY_WEEKEND
22                  DAY_EVERYDAY                  DAY_EVERYDAY
23          ) ]          ) ],
24            'fmt_interval' => [ qw(fmt_interval) ]
25  );  );
26    
27  our @EXPORT_OK = ( @{ $EXPORT_TAGS{'days'} } );  our @EXPORT_OK = (
28            @{ $EXPORT_TAGS{'days'} },
29            @{ $EXPORT_TAGS{'fmt_interval'} }
30            );
31    
32  our @EXPORT = qw(  our @EXPORT;    # don't export anything by default!
           
 );  
33    
34  our $VERSION = '0.01';  our $VERSION = '0.01';
35    
# Line 163  sub uptime { Line 158  sub uptime {
158          return $s;          return $s;
159  }  }
160    
161    #
162    # this auxillary function will pretty-format interval in [days]d hh:mm:ss
163    #
164    
165    sub fmt_interval {
166            my $s = shift || 0;
167            my $out = "";
168    
169            my $d = int($s/(24*60*60));
170            $s = $s % (24*60*60);
171            my $h = int($s/(60*60));
172            $s = $s % (60*60);
173            my $m = int($s/60);
174            $s = $s % 60;
175            
176            $out .= $d."d " if ($d > 0);
177    
178            $out .= sprintf("%02d:%02d:%02d",$h,$m,$s);
179    
180            return $out;
181    }
182    
183  1;  1;
184  __END__  __END__
# Line 191  Time::Available - Perl extension to calc Line 206  Time::Available - Perl extension to calc
206    # calculate availablity in seconds from interval of uptime    # calculate availablity in seconds from interval of uptime
207    print $interval->interval($utime1,$utime2);    print $interval->interval($utime1,$utime2);
208    
209      # pretty print interval data (this will produce output '1d 11:11:11')
210      use Time::Available qw(:fmt_interval);
211      print fmt_interval(126671);
212    
213  =head1 DESCRIPTION  =head1 DESCRIPTION
214    
215  Time::Available is used to calculate availability of some resource if start  Time::Available is used to calculate availability of some resource if start
# Line 242  FIXME Line 261  FIXME
261    
262  =head2 EXPORT  =head2 EXPORT
263    
264  None by default. If you specify B<:days>, Time::Available will export all  None by default.
265    
266    If you specify B<:days>, Time::Available will export all
267  DAY_* constraints to your enviroment (causing possible pollution of name  DAY_* constraints to your enviroment (causing possible pollution of name
268  space). You have been warned.  space). You have been warned.
269    
270    With B<:fmt_interval> it will include function B<fmt_interval> which will
271    pretty-format interval into [days]d hh:mm:ss.
272    
273    
274  =head1 HISTORY  =head1 HISTORY
275    

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.26