my $counter = 0;
my %user_ranges = ();
my $julian_day = 0;
for my $date ($beginning_date..$ending_date) { # run through the main range and create smaller ranges
my ($year, $month, $day) = ((substr $date, 0, 4),(substr $date, 4, 2),(substr $date, 6, 2));
next if !check_date ($year, $month, $day); # next iteration if date is not valid
print "passed as a vaild day: $year$month$day
";
# next iteration if the weekday range is selected and the date is not on a weekday
next if (((Day_of_Week ($year, $month, $day)) > 5) && ($session_vars{'date_type'} == 2));
print "passed as a weekday: $year$month$day
" if ($session_vars{'date_type'} == 2);
# next iteration if the weekend range is selected and the date is not on a weekend
next if (((Day_of_Week ($year, $month, $day)) < 6) && ($session_vars{'date_type'} == 3));
print "passed as a weekend: $year$month$day
" if ($session_vars{'date_type'} == 3);
if (($julian_day + 1) == (Day_of_Year ($year, $month, $day))) {
#one day later
$user_ranges{$counter}->[1] = $date;
print "assigned $date as end date to range # $counter
";
$julian_day++;
print "same range: julian day-$julian_day -- counter-$counter -- date: $date
";
}
else {
# this is where the problem lies, notice '$counter >= 1' used to read !$counter
if ((!$user_ranges{$counter}->[1]) && ($counter >= 1)) { # if range is one day long
print "\n\ncounter: $counter -- user ranges 0: $user_ranges{$counter}->[0] -- user ranges 1: $user_ranges{$counter}->[1]
";
$user_ranges{$counter}->[1] = $user_ranges{$counter}->[0];
}
#range switch
$counter++;
$user_ranges{$counter}->[0] = $date;
print "assigned $date as beginning date to range # $counter
";
$julian_day = Day_of_Year ($year, $month, $day);
print "new range: julian day-$julian_day -- counter-$counter -- date: $date
";
}
}