diff --git a/calendar/egroupware.org/holidays.US.csv b/calendar/egroupware.org/holidays.US.csv index bfb36f476f..c324dd6b26 100644 --- a/calendar/egroupware.org/holidays.US.csv +++ b/calendar/egroupware.org/holidays.US.csv @@ -1,5 +1,5 @@ US Martin Luther King's Birthday 0 1 3 1 0 -US New Year's Day 1 1 0 0 0 +US New Year's Day 1 1 0 0 1 US Inauguration Day 20 1 0 0 0 US Presidents Day 0 2 3 1 0 US Armed Forces Day 0 5 3 6 0 diff --git a/calendar/inc/class.holidaycalc_US.inc.php b/calendar/inc/class.holidaycalc_US.inc.php index 450e320cd0..315adc5233 100755 --- a/calendar/inc/class.holidaycalc_US.inc.php +++ b/calendar/inc/class.holidaycalc_US.inc.php @@ -15,9 +15,28 @@ class holidaycalc { + function add($holiday,&$holidays,$year,&$i,$day_offset=0) + { + $i++; + $holidays[$i]= $holiday; + if ($day_offset) + { + $holidays[$i]['name'] .= ' (Observed)'; + } + $holidays[$i]['date'] = mktime(0,0,0,$holiday['month'],$holiday['day']+$day_offset,$year); + foreach(array('day'=>'d','month'=>'m','occurence'=>'Y') as $key => $frmt) + { + $holidays[$i][$key] = date($frmt,$holidays[$i]['date']); + } + $holidays[$i]['obervance_rule'] = 0; + + //echo "

holidaycalc::add(".print_r($holiday,True).",,$year,,$day_offset)=".print_r($holidays[$i],True)."

"; + } + function calculate_date($holiday, &$holidays, $year, &$i) { - // if($holiday['day'] == 0 && $holiday['dow'] != 0 && $holiday['occurence'] != 0) + //echo "

holidaycalc::calculate_date(".print_r($holiday,True).",,$year,)

"; + if($holiday['day'] == 0 && $holiday['occurence'] != 0) { if($holiday['occurence'] != 99) @@ -25,9 +44,6 @@ $dow = $GLOBALS['phpgw']->datetime->day_of_week($year,$holiday['month'],1); $day = (((7 * $holiday['occurence']) - 6) + ((($holiday['dow'] + 7) - $dow) % 7)); $day += ($day < 1 ? 7 : 0); - // What is the point of this? - // Add 7 when the holiday falls on a Monday??? - //$day += ($holiday['dow']==1 ? 7 : 0); // Sometimes the 5th occurance of a weekday (ie the 5th monday) // can spill over to the next month. This prevents that. @@ -51,29 +67,33 @@ { $dow = $GLOBALS['phpgw']->datetime->day_of_week($year,$holiday['month'],$day); // This now calulates Observed holidays and creates a new entry for them. - if($dow == 0) + + // 0 = sundays are observed on monday (+1), 6 = saturdays are observed on fridays (-1) + if($dow == 0 || $dow == 6) { - $i++; - $holidays[$i]['locale'] = $holiday['locale']; - $holidays[$i]['name'] = $holiday['name'].' (Observed)'; - $holidays[$i]['day'] = $holiday['day'] + 1; - $holidays[$i]['month'] = $holiday['month']; - $holidays[$i]['occurence'] = $holiday['occurence']; - $holidays[$i]['dow'] = $holiday['dow']; - $holidays[$i]['date'] = mktime(0,0,0,$holiday['month'],$day+1,$year); - $holidays[$i]['obervance_rule'] = 0; + $this->add($holiday,&$holidays,$year,$i,$dow == 0 ? 1 : -1); } - elseif($dow == 6) + if ($holiday['month'] == 1 && $day == 1) { - $i++; - $holidays[$i]['locale'] = $holiday['locale']; - $holidays[$i]['name'] = $holiday['name'].' (Observed)'; - $holidays[$i]['day'] = $holiday['day'] - 1; - $holidays[$i]['month'] = $holiday['month']; - $holidays[$i]['occurence'] = $holiday['occurence']; - $holidays[$i]['dow'] = $holiday['dow']; - $holidays[$i]['date'] = mktime(0,0,0,$holiday['month'],$day-1,$year); - $holidays[$i]['obervance_rule'] = 0; + $dow = $GLOBALS['phpgw']->datetime->day_of_week($year+1,$holiday['month'],$day); + // checking if next year's newyear might be observed in this year + if ($dow == 6) + { + $this->add($holiday,&$holidays,$year+1,$i,-1); + } + // add the next years newyear, to show it in a week- or month-view + $this->add($holiday,&$holidays,$year+1,$i); + } + // checking if last year's new year's eve might be observed in this year + if ($holiday['month'] == 12 && $day == 31) + { + $dow = $GLOBALS['phpgw']->datetime->day_of_week($year-1,$holiday['month'],$day); + if ($dow == 0) + { + $this->add($holiday,&$holidays,$year-1,$i,1); + } + // add the last years new year's eve, to show it in a week- or month-view + $this->add($holiday,&$holidays,$year-1,$i); } } } diff --git a/calendar/inc/class.soholiday.inc.php b/calendar/inc/class.soholiday.inc.php index b87a93d8fa..3d3a3264a9 100755 --- a/calendar/inc/class.soholiday.inc.php +++ b/calendar/inc/class.soholiday.inc.php @@ -28,6 +28,10 @@ /* Begin Holiday functions */ function save_holiday($holiday) { + // observance_rule is either "True" or unset ! + $holiday['observance_rule'] = @$holiday['observance_rule'] ? 1 : 0; + $holiday['locale'] = strtoupper($holiday['locale']); + if(@$holiday['hol_id']) { if($this->debug) @@ -43,9 +47,9 @@ echo "Inserting LOCALE='".$holiday['locale']."' NAME='".$holiday['name']."' extra=(".$holiday['mday'].'/'.$holiday['month_num'].'/'.$holiday['occurence'].'/'.$holiday['dow'].'/'.$holiday['observance_rule'].")
\n"; } unset($holiday['hol_id']); // in case its 0 - $holiday['locale'] = strtoupper($holiday['locale']); $sql = "INSERT INTO $this->table ".$this->db->column_data_implode(',',$holiday,'VALUES',True); } + //echo "

soholiday::save_holiday(".print_r($holiday,True).") sql='$sql'

\n"; $this->db->query($sql,__LINE__,__FILE__); }