[ Index ] |
|
Code source de eGroupWare 1.2.106-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 /* $Id: class.holidaycalc_US.inc.php 20295 2006-02-15 12:31:25Z $ */ 15 16 /** 17 * Calculations for calendar US and other holidays 18 * 19 * @package calendar 20 * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License 21 */ 22 class holidaycalc 23 { 24 function add($holiday,&$holidays,$year,$day_offset=0) 25 { 26 if ($day_offset) 27 { 28 $holiday['name'] .= ' (Observed)'; 29 } 30 $holiday['date'] = mktime(0,0,0,$holiday['month'],$holiday['day']+$day_offset,$year); 31 foreach(array('day'=>'d','month'=>'m','occurence'=>'Y') as $key => $frmt) 32 { 33 $holiday[$key] = date($frmt,$holiday['date']); 34 } 35 $holiday['obervance_rule'] = 0; 36 37 $holidays[]= $holiday; 38 39 //echo "<p>holidaycalc::add(,,$year,,$day_offset)=".print_r($holiday,True)."</p>"; 40 } 41 42 function calculate_date($holiday, &$holidays, $year) 43 { 44 //echo "<p>holidaycalc::calculate_date(".print_r($holiday,True).",,$year,)</p>"; 45 46 if($holiday['day'] == 0 && $holiday['occurence'] != 0) 47 { 48 if($holiday['occurence'] != 99) 49 { 50 $dow = $GLOBALS['egw']->datetime->day_of_week($year,$holiday['month'],1); 51 $day = (((7 * $holiday['occurence']) - 6) + ((($holiday['dow'] + 7) - $dow) % 7)); 52 $day += ($day < 1 ? 7 : 0); 53 54 // Sometimes the 5th occurance of a weekday (ie the 5th monday) 55 // can spill over to the next month. This prevents that. 56 $ld = $GLOBALS['egw']->datetime->days_in_month($holiday['month'],$year); 57 if ($day > $ld) 58 { 59 return; 60 } 61 } 62 else 63 { 64 $ld = $GLOBALS['egw']->datetime->days_in_month($holiday['month'],$year); 65 $dow = $GLOBALS['egw']->datetime->day_of_week($year,$holiday['month'],$ld); 66 $day = $ld - (($dow + 7) - $holiday['dow']) % 7 ; 67 } 68 } 69 else 70 { 71 $day = $holiday['day']; 72 if($holiday['observance_rule'] == True) 73 { 74 $dow = $GLOBALS['egw']->datetime->day_of_week($year,$holiday['month'],$day); 75 // This now calulates Observed holidays and creates a new entry for them. 76 77 // 0 = sundays are observed on monday (+1), 6 = saturdays are observed on fridays (-1) 78 if($dow == 0 || $dow == 6) 79 { 80 $this->add($holiday,$holidays,$year,$dow == 0 ? 1 : -1); 81 } 82 if ($holiday['month'] == 1 && $day == 1) 83 { 84 $dow = $GLOBALS['egw']->datetime->day_of_week($year+1,$holiday['month'],$day); 85 // checking if next year's newyear might be observed in this year 86 if ($dow == 6) 87 { 88 $this->add($holiday,$holidays,$year+1,-1); 89 } 90 // add the next years newyear, to show it in a week- or month-view 91 $this->add($holiday,$holidays,$year+1); 92 } 93 // checking if last year's new year's eve might be observed in this year 94 if ($holiday['month'] == 12 && $day == 31) 95 { 96 $dow = $GLOBALS['egw']->datetime->day_of_week($year-1,$holiday['month'],$day); 97 if ($dow == 0) 98 { 99 $this->add($holiday,$holidays,$year-1,1); 100 } 101 // add the last years new year's eve, to show it in a week- or month-view 102 $this->add($holiday,$holidays,$year-1); 103 } 104 } 105 } 106 $date = mktime(0,0,0,$holiday['month'],$day,$year); 107 108 return $date; 109 } 110 } 111 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |