--- Available.pm 2003/10/03 15:23:46 1.2 +++ Available.pm 2003/10/03 16:40:00 1.3 @@ -1,6 +1,6 @@ package Time::Available; -use 5.008001; +use 5.001; use strict; use warnings; @@ -88,9 +88,11 @@ # this sub (originally from Time::Avail) will return if day is applicable # -sub _dayOk($$) { +sub _dayOk($) { + my $self = shift; + my $day = shift || return; - my( $dayMask, $day ) = @_; # get parameters + my $dayMask = $self->{dayMask}; my $dayOk = 0; @@ -126,31 +128,42 @@ my $time = shift || die "need uptime timestamp to calcualte uptime"; + # calculate offset -- that is number of seconds since midnight + my @lt = localtime($time); + my $offset = $lt[2]; # hour + $offset *= 60; # convert to minutes + $offset += $lt[1]; # minutes + $offset *= 60; # convert to seconds + $offset += $lt[0]; + + # check if day falls into dayMask + return 0 if (! $self->_dayOk($lt[6]) ); + my $s=0; my $start = $self->{start}; my $end = $self->{end}; - print STDERR "start: $start end: $end time: $time\n" if ($debug); + print STDERR "start: $start end: $end time: $offset\n" if ($debug); - if( ( $end > $start ) && ( $time < $end ) ) { - if ($time < $start) { + if ( $end > $start ) { + if ($offset < $start) { $s = $end - $start; - } else { - $s = $end - $time; + } elsif ($offset < $end) { + $s = $end - $offset; } - } elsif( $start > $end ) { # over midnight - if ( $time < $end ) { - if ( $time < $start) { - $s = SEC_PER_DAY - $start + $end - $time; + } elsif ( $start > $end ) { # over midnight + if ( $offset < $end ) { + if ( $offset < $start) { + $s = SEC_PER_DAY - $start + $end - $offset; } else { $s = SEC_PER_DAY - $start + $end; } } else { - if ( $time < $start ) { + if ( $offset < $start ) { $s = SEC_PER_DAY - $start; } else { - $s = SEC_PER_DAY - $time; + $s = SEC_PER_DAY - $offset; } } } @@ -300,7 +313,7 @@ this module was born. More information about this module might be found on -http://www.rot13.org/~dpavlin/perl.html#cpan +http://www.rot13.org/~dpavlin/projects.html#cpan =head1 AUTHOR