/[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.2 by dpavlin, Fri Oct 3 15:23:46 2003 UTC revision 1.3 by dpavlin, Fri Oct 3 16:40:00 2003 UTC
# Line 1  Line 1 
1  package Time::Available;  package Time::Available;
2    
3  use 5.008001;  use 5.001;
4  use strict;  use strict;
5  use warnings;  use warnings;
6    
# Line 88  sub new { Line 88  sub new {
88  # this sub (originally from Time::Avail) will return if day is applicable  # this sub (originally from Time::Avail) will return if day is applicable
89  #  #
90    
91  sub _dayOk($$) {  sub _dayOk($) {
92            my $self = shift;
93            my $day = shift || return;
94    
95          my( $dayMask, $day ) = @_;      # get parameters          my $dayMask = $self->{dayMask};
96    
97          my $dayOk = 0;          my $dayOk = 0;
98    
# Line 126  sub uptime { Line 128  sub uptime {
128    
129          my $time = shift || die "need uptime timestamp to calcualte uptime";          my $time = shift || die "need uptime timestamp to calcualte uptime";
130    
131            # calculate offset -- that is number of seconds since midnight
132            my @lt = localtime($time);
133            my $offset = $lt[2];    # hour
134            $offset *= 60;          # convert to minutes
135            $offset += $lt[1];      # minutes
136            $offset *= 60;          # convert to seconds
137            $offset += $lt[0];
138    
139            # check if day falls into dayMask
140            return 0 if (! $self->_dayOk($lt[6]) );
141    
142          my $s=0;          my $s=0;
143    
144          my $start = $self->{start};          my $start = $self->{start};
145          my $end = $self->{end};          my $end = $self->{end};
146    
147          print STDERR "start: $start end: $end time: $time\n" if ($debug);          print STDERR "start: $start end: $end time: $offset\n" if ($debug);
148    
149          if( ( $end > $start ) && ( $time < $end ) ) {          if ( $end > $start ) {
150                  if ($time < $start) {                  if ($offset < $start) {
151                          $s = $end - $start;                          $s = $end - $start;
152                  } else {                  } elsif ($offset < $end) {
153                          $s = $end - $time;                          $s = $end - $offset;
154                  }                  }
155          } elsif( $start > $end ) {      # over midnight          } elsif ( $start > $end ) {     # over midnight
156                  if ( $time < $end ) {                  if ( $offset < $end ) {
157                          if ( $time < $start) {                          if ( $offset < $start) {
158                                  $s = SEC_PER_DAY - $start + $end - $time;                                  $s = SEC_PER_DAY - $start + $end - $offset;
159                          } else {                          } else {
160                                  $s = SEC_PER_DAY - $start + $end;                                  $s = SEC_PER_DAY - $start + $end;
161                          }                          }
162                  } else {                  } else {
163                          if ( $time < $start ) {                          if ( $offset < $start ) {
164                                  $s = SEC_PER_DAY - $start;                                  $s = SEC_PER_DAY - $start;
165                          } else {                          } else {
166                                  $s = SEC_PER_DAY - $time;                                  $s = SEC_PER_DAY - $offset;
167                          }                          }
168                  }                  }
169          }          }
# Line 300  calculating of availability of some inte Line 313  calculating of availability of some inte
313  this module was born.  this module was born.
314    
315  More information about this module might be found on  More information about this module might be found on
316  http://www.rot13.org/~dpavlin/perl.html#cpan  http://www.rot13.org/~dpavlin/projects.html#cpan
317    
318  =head1 AUTHOR  =head1 AUTHOR
319    

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

  ViewVC Help
Powered by ViewVC 1.1.26