note
Limbic~Region
[Nitrox],
<br>
As I mentioned in the CB, [http://www.amazon.com/exec/obidos/tg/detail/-/1565922204/002-9911316-4380833?v=glance|The Panther] has a section on using bitmap vectors to determine scheduling conflicts. It is just a matter of logically AND-ing the two bitmaps.
<p>
Each hour in the week would be one bit. You would be storing a 21 byte bitmap vector. If the bit is set, then there is a problem if the event happens at this hour. The task then is to design a way to parse your range and <b>localtime()</b> into the bitmap vector.
<p>
The following is very basic, but it gives you a fully functional framework. Expand it as you see fit.
<readmore>
<CODE>
#!/usr/bin/perl -w
use strict;
my $interval = "Mon 3-4, Mon 8-12, Wed 4-7, Thu 11-18";
my $alert = interval_parse( $interval );
my $alarm = get_current();
print "Page someone\n" if Critical($alert, $alarm);
sub interval_parse {
my $interval = shift;
my $bitmap = "";
my %day_offset = (
sun => 0, mon => 24, tue => 48, wed => 72, thu => 96, fri => 120, sat => 144
);
for my $range (split /,/ , $interval) {
my ($day, $from, $to) = ($range =~ /([A-Za-z]+)\s+(\d+)-(\d+)/);
my $offset = $day_offset{lc $day};
$from += $offset;
$to += $offset;
vec( $bitmap, $_, 1 ) = 1 for $from .. $to;
}
return $bitmap;
}
sub get_current {
my ($hour, $day) = (localtime())[2,6];
my $bitmap = "";
my $now = $day * 24 + $hour;
vec ( $bitmap, $now, 1 ) = 1;
return $bitmap;
}
sub Critical {
my ($alert, $alarm) = @_;
my ($combined) = $alert & $alarm;
my $offset = length ($combined) * 8;
while (--$offset >= 0) {
return 1 if vec($combined, $offset, 1);
}
return 0;
}
</CODE>
</readmore>
<p>
I hope this helps - [Limbic~Region|L~R]
303290
303290