package Set::Range;
require Exporter;
use constant DATE_RANGE => 1;
use constant NUM_RANGE => 2;
use constant TIME_RANGE => 3;
use constant EU_DATE_RANGE => 4;
@ISA = qw(Exporter);
@EXPORT = qw(DATE_RANGE EU_DATE_RANGE NUM_RANGE TIME_RANGE);
sub new {
my $self = shift;
my $range = shift;
return bless $range, $self;
}
sub getSet {
my ($self, $var, $type) = @_;
$type = NUM_RANGE unless $type;
if (($type == DATE_RANGE) || ($type == EU_DATE_RANGE)) {
$var = _timify($var, $type);
}
my $state = 0;
foreach $state (keys %$self) {
my ($u, $l) = ($self->{$state}->{upper},
$self->{$state}->{lower});
if (($type == DATE_RANGE) || ($type == EU_DATE_RANGE)) {
$upper= _timify($u, $type);
$lower= _timify($l, $type);
}
my ($uinc, $linc, $result);
if ($self->{$state}->{upper_inclusive}) {
$uinc = '>=';
} else { $uinc = '>' }
if ($self->{$state}->{lower_inclusive}) {
$linc = '>=';
} else { $linc = '>' }
$result =
eval "$state if (($u $uinc $var) && ($var $linc $l))";
return $result if $result;
}
return 0;
}
sub _timify {
my ($u, $type) = @_;
require Date::Calc;
if ($type == EU_DATE_RANGE) {
$u = Date::Calc::Date_to_Days(Date::Calc::Decode_Date_EU($u));
} else {
$u = Date::Calc::Date_to_Days(Date::Calc::Decode_Date_US($u));
}
return $u;
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|