IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 36178 for trunk/tools/czarcal


Ignore:
Timestamp:
Oct 2, 2013, 11:06:42 AM (13 years ago)
Author:
bills
Message:

detect and skip holidays

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/czarcal

    r34894 r36178  
    1616my $start_date = shift;
    1717my $num_assignments = shift;
    18 
    1918$num_assignments = 1 unless $num_assignments;
    2019
     20my $num_events = 0;
    2121
    2222# list of all czars
    2323my @staff = qw(
     24bill
     25chris
    2426mark
    2527gene
    26 bill
    2728heather
    28 chris
    2929);
    3030
    31 die "usage: $0 <first czar> <start_date> <num assignments>\n  czar list: @staff\n"
     31my @date_holidays = qw(
     320101
     330326
     340611
     350816
     361225
     37);
     38# MMNW
     39my @weekday_holidays = qw(
     400131
     410231
     420541
     430911
     441121
     451144
     46);
     47
     48
     49
     50die "usage: $0 <first czar> <start_date> [<num assignments>]\n  czar list: @staff\n"
    3251    unless $start_date and $first_czar;
    3352
     
    4867
    4968
    50 
    5169my $year = substr $start_date, 0, 4;
    5270my $month = substr $start_date, 4, 2;
     
    6280for (my $i = 0; $i < $num_assignments; $i++) {
    6381    $tm = localtime($time);
    64     if ($tm->wday != 6 and $tm->wday != 0) {
     82    if ($tm->wday == 6 or $tm->wday == 0) {
     83        # bump counter to account for weekend day
     84        $num_assignments++;
     85    } elsif (is_holiday($tm)) {
     86        # bump counter to account for holiday
     87        $num_assignments++;
     88    } else {
    6589
    6690        assign_czar($this_czar, $tm->year+1900, $tm->mon+1, $tm->mday);
     
    7397            $j = 0;
    7498        }
    75     } else {
    76         # bump counter to account for weekend day
    77         $num_assignments++;
    7899    }
    79100    $time += 86400;
    80101}
    81102
     103print "$end_vcalendar\n";
    82104
    83 print "$end_vcalendar\n";
     105exit 0;
    84106
    85107sub get_czars {
     
    97119}
    98120
    99 my $num_events = 0;
    100121sub assign_czar {
    101122#    print STDERR "assign: @_\n";
     
    132153}
    133154
     155sub is_holiday {
     156    my $tm = shift;
    134157
     158    my $slimdate = sprintf "%02d%02d", $tm->mon + 1, $tm->mday;
     159    foreach my $d (@date_holidays) {
     160        if ($d eq $slimdate) {
     161            print STDERR "$d is a date holiday\n";
     162            return 1;
     163        }
     164    }
     165
     166    my $monthDayOfWeek = sprintf "%02d%d%d", $tm->mon + 1, 1 + ($tm->mday - $tm->wday) / 7, $tm->wday;
     167
     168    foreach my $d (@weekday_holidays) {
     169        if ($d eq $monthDayOfWeek) {
     170            print STDERR "$slimdate is a $d day of week holiday\n";
     171            return 1;
     172        }
     173    }
     174
     175    return 0;
     176}
     177
     178
Note: See TracChangeset for help on using the changeset viewer.