[2] | 1 | <?php |
---|
| 2 | /**************************************************************************\ |
---|
| 3 | * eGroupWare - holidaycalc_US * |
---|
| 4 | * http://www.egroupware.org * |
---|
| 5 | * Based on Yoshihiro Kamimura <your@itheart.com> * |
---|
| 6 | * http://www.itheart.com * |
---|
| 7 | * -------------------------------------------- * |
---|
| 8 | * This program is free software; you can redistribute it and/or modify it * |
---|
| 9 | * under the terms of the GNU General Public License as published by the * |
---|
| 10 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
| 11 | * option) any later version. * |
---|
| 12 | \**************************************************************************/ |
---|
| 13 | |
---|
| 14 | |
---|
| 15 | class holidaycalc |
---|
| 16 | { |
---|
| 17 | function calculate_date($holiday, &$holidays, $year, &$i) |
---|
| 18 | { |
---|
| 19 | // if($holiday['day'] == 0 && $holiday['dow'] != 0 && $holiday['occurence'] != 0) |
---|
| 20 | if($holiday['day'] == 0 && $holiday['occurence'] != 0) |
---|
| 21 | { |
---|
| 22 | if($holiday['occurence'] != 99) |
---|
| 23 | { |
---|
| 24 | $dow = $GLOBALS['phpgw']->datetime->day_of_week($year,$holiday['month'],1); |
---|
| 25 | $day = (((7 * $holiday['occurence']) - 6) + ((($holiday['dow'] + 7) - $dow) % 7)); |
---|
| 26 | $day += ($day < 1 ? 7 : 0); |
---|
| 27 | // What is the point of this? |
---|
| 28 | // Add 7 when the holiday falls on a Monday??? |
---|
| 29 | //$day += ($holiday['dow']==1 ? 7 : 0); |
---|
| 30 | |
---|
| 31 | // Sometimes the 5th occurance of a weekday (ie the 5th monday) |
---|
| 32 | // can spill over to the next month. This prevents that. |
---|
| 33 | $ld = $GLOBALS['phpgw']->datetime->days_in_month($holiday['month'],$year); |
---|
| 34 | if ($day > $ld) |
---|
| 35 | { |
---|
| 36 | return; |
---|
| 37 | } |
---|
| 38 | } |
---|
| 39 | else |
---|
| 40 | { |
---|
| 41 | $ld = $GLOBALS['phpgw']->datetime->days_in_month($holiday['month'],$year); |
---|
| 42 | $dow = $GLOBALS['phpgw']->datetime->day_of_week($year,$holiday['month'],$ld); |
---|
| 43 | $day = $ld - (($dow + 7) - $holiday['dow']) % 7 ; |
---|
| 44 | } |
---|
| 45 | } |
---|
| 46 | else |
---|
| 47 | { |
---|
| 48 | $day = $holiday['day']; |
---|
| 49 | if($holiday['observance_rule'] == True) |
---|
| 50 | { |
---|
| 51 | $dow = $GLOBALS['phpgw']->datetime->day_of_week($year,$holiday['month'],$day); |
---|
| 52 | // This now calulates Observed holidays and creates a new entry for them. |
---|
| 53 | if($dow == 0) |
---|
| 54 | { |
---|
| 55 | $i++; |
---|
| 56 | $holidays[$i]['locale'] = $holiday['locale']; |
---|
| 57 | $holidays[$i]['name'] = $holiday['name'].' (Observed)'; |
---|
| 58 | $holidays[$i]['day'] = $holiday['day'] + 1; |
---|
| 59 | $holidays[$i]['month'] = $holiday['month']; |
---|
| 60 | $holidays[$i]['occurence'] = $holiday['occurence']; |
---|
| 61 | $holidays[$i]['dow'] = $holiday['dow']; |
---|
| 62 | $holidays[$i]['date'] = mktime(0,0,0,$holiday['month'],$day+1,$year); |
---|
| 63 | $holidays[$i]['obervance_rule'] = 0; |
---|
| 64 | } |
---|
| 65 | elseif($dow == 6) |
---|
| 66 | { |
---|
| 67 | $i++; |
---|
| 68 | $holidays[$i]['locale'] = $holiday['locale']; |
---|
| 69 | $holidays[$i]['name'] = $holiday['name'].' (Observed)'; |
---|
| 70 | $holidays[$i]['day'] = $holiday['day'] - 1; |
---|
| 71 | $holidays[$i]['month'] = $holiday['month']; |
---|
| 72 | $holidays[$i]['occurence'] = $holiday['occurence']; |
---|
| 73 | $holidays[$i]['dow'] = $holiday['dow']; |
---|
| 74 | $holidays[$i]['date'] = mktime(0,0,0,$holiday['month'],$day-1,$year); |
---|
| 75 | $holidays[$i]['obervance_rule'] = 0; |
---|
| 76 | } |
---|
| 77 | } |
---|
| 78 | } |
---|
| 79 | $date = mktime(0,0,0,$holiday['month'],$day,$year); |
---|
| 80 | |
---|
| 81 | return $date; |
---|
| 82 | } |
---|
| 83 | } |
---|
| 84 | ?> |
---|