33 |
|
|
34 |
our @EXPORT; # don't export anything by default! |
our @EXPORT; # don't export anything by default! |
35 |
|
|
36 |
our $VERSION = '0.01'; |
our $VERSION = '0.03'; |
37 |
|
|
38 |
# define some constants used later |
# define some constants used later |
39 |
use constant DAY_MONDAY => 0x01; |
use constant DAY_MONDAY => 0x01; |
61 |
$self->{ARGS} = {@_}; |
$self->{ARGS} = {@_}; |
62 |
$debug = $self->{ARGS}->{DEBUG}; |
$debug = $self->{ARGS}->{DEBUG}; |
63 |
|
|
64 |
croak("need start time") if (! $self->{ARGS}->{start}); |
croak("need start time") if (! defined($self->{ARGS}->{start})); |
65 |
|
|
66 |
# calc start and stop seconds |
# calc start and stop seconds |
67 |
my ($hh,$mm,$ss) = split(/:/,$self->{ARGS}->{start},3); |
my ($hh,$mm,$ss) = split(/:/,$self->{ARGS}->{start},3); |
68 |
print STDERR "new: start time ",$hh||0,":",$mm||0,":",$ss||0,"\n" if ($debug); |
print STDERR "new: start time ",$hh||0,":",$mm||0,":",$ss||0,"\n" if ($debug); |
69 |
croak("need at least hour specified for start time") if (! $hh); |
croak("need at least hour specified for start time") if (! defined($hh)); |
70 |
$mm |= 0; |
$mm |= 0; |
71 |
$ss |= 0; |
$ss |= 0; |
72 |
$self->{start_arr} = [$ss,$mm,$hh]; |
$self->{start_arr} = [$ss,$mm,$hh]; |
77 |
$start *= 60; |
$start *= 60; |
78 |
$start += $ss; |
$start += $ss; |
79 |
|
|
80 |
croak("need end time") if (! $self->{ARGS}->{end}); |
croak("need end time") if (! defined($self->{ARGS}->{end})); |
81 |
|
|
82 |
($hh,$mm,$ss) = split(/:/,$self->{ARGS}->{end},3); |
($hh,$mm,$ss) = split(/:/,$self->{ARGS}->{end},3); |
83 |
print STDERR "new: end time ",$hh||0,":",$mm||0,":",$ss||0,"\n" if ($debug); |
print STDERR "new: end time ",$hh||0,":",$mm||0,":",$ss||0,"\n" if ($debug); |
84 |
croak("need at least hour specified for end time") if (! $hh); |
croak("need at least hour specified for end time") if (! defined($hh)); |
85 |
$mm |= 0; |
$mm |= 0; |
86 |
$ss |= 0; |
$ss |= 0; |
87 |
$self->{end_arr} = [$ss,$mm,$hh]; |
$self->{end_arr} = [$ss,$mm,$hh]; |
92 |
$end *= 60; |
$end *= 60; |
93 |
$end += $ss; |
$end += $ss; |
94 |
|
|
95 |
croak("need dayMask specified") if (! $self->{ARGS}->{dayMask}); |
croak("need dayMask specified") if (! defined($self->{ARGS}->{dayMask})); |
96 |
|
|
97 |
$self->{dayMask} = $self->{ARGS}->{dayMask}; |
$self->{dayMask} = $self->{ARGS}->{dayMask}; |
98 |
|
|
111 |
|
|
112 |
sub _dayOk($) { |
sub _dayOk($) { |
113 |
my $self = shift; |
my $self = shift; |
114 |
my $day = shift || return; |
my $day = shift || 0; |
115 |
|
|
116 |
my $dayMask = $self->{dayMask}; |
my $dayMask = $self->{dayMask}; |
117 |
|
|
378 |
my $interval = new( start=>'07:00', stop=>'17:00', |
my $interval = new( start=>'07:00', stop=>'17:00', |
379 |
dayMask=> DAY_WEEKDAY ); |
dayMask=> DAY_WEEKDAY ); |
380 |
|
|
381 |
# calculate current availability in seconds |
# calculate current uptime availability from now in seconds |
382 |
print $interval->uptime(localtime); |
print $interval->uptime(localtime); |
383 |
|
|
384 |
|
# calculate maximum downtime in seconds from current moment |
385 |
|
print $interval->downtime(localtime); |
386 |
|
|
387 |
# calculate availablity in seconds from interval of uptime |
# calculate availablity in seconds from interval of uptime |
388 |
print $interval->interval($utime1,$utime2); |
print $interval->interval($utime1,$utime2); |
389 |
|
|
394 |
=head1 DESCRIPTION |
=head1 DESCRIPTION |
395 |
|
|
396 |
Time::Available is used to calculate availability of some resource if start |
Time::Available is used to calculate availability of some resource if start |
397 |
end end time of availability is available. That availability is calculated |
and end time of availability is supplied. Availability is calculated |
398 |
relative to some interval which is defined when new instance of module is |
relative to some interval which is defined when new instance of module is |
399 |
created. |
created. |
400 |
|
|
401 |
Start and end dates must be specified in 24-hour format. You can specify |
Start and end dates must be specified in 24-hour format. You can specify |
402 |
just hour, hour:minute or hour:minute:seconds format. |
just hour, hour:minute or hour:minute:seconds format. Start and end time is |
403 |
|
specified in your B<local time zone>. Timestamp, are specified in unix |
404 |
|
utime, and module will take care of recalculating (using C<localtime> and |
405 |
|
C<timelocal> when needed). There is one small canvat here: module is assuing |
406 |
|
that time you are specifing is in same time zone in which your module is |
407 |
|
running (that is from local system). |
408 |
|
|
409 |
The B<dayMask> parameter is constructed by OR'ing together one or more of |
The B<dayMask> parameter is constructed by OR'ing together one or more of |
410 |
the following dayMask constants: |
the following dayMask constants: |
443 |
|
|
444 |
=back |
=back |
445 |
|
|
446 |
FIXME |
They should be self-explainatory. |
447 |
|
|
448 |
=head2 EXPORT |
=head2 EXPORT |
449 |
|
|
478 |
|
|
479 |
=head1 SEE ALSO |
=head1 SEE ALSO |
480 |
|
|
481 |
Time::Avail is CPAN module that started it all. However, it lacked |
L<Time::Avail> is CPAN module that started it all. However, it lacked |
482 |
calculating of availability of some interval and precision in seconds, so |
calculating of availability of some interval and precision in seconds, so |
483 |
this module was born. |
this module was born. It also had some bugs in dayMask which where reported |
484 |
|
to author, but his e-mail address bounced. |
485 |
|
|
486 |
More information about this module might be found on |
More information about this module might be found on |
487 |
http://www.rot13.org/~dpavlin/projects.html#cpan |
http://www.rot13.org/~dpavlin/projects.html#cpan |