Nitrox,
As I mentioned in the CB, 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.

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 localtime() into the bitmap vector.

The following is very basic, but it gives you a fully functional framework. Expand it as you see fit.

#!/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 => 1 +20, 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; }

I hope this helps - L~R


In reply to Re: Representing windows of time in a string by Limbic~Region
in thread Representing windows of time in a string by Nitrox

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.