2001-06-19 02:44:04 +02:00
|
|
|
<?php
|
|
|
|
/**************************************************************************\
|
|
|
|
* phpGroupWare - holidaycalc_US *
|
|
|
|
* http://www.phpgroupware.org *
|
|
|
|
* Based on Yoshihiro Kamimura <your@itheart.com> *
|
|
|
|
* http://www.itheart.com *
|
|
|
|
* -------------------------------------------- *
|
|
|
|
* This program is free software; you can redistribute it and/or modify it *
|
|
|
|
* under the terms of the GNU General Public License as published by the *
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your *
|
|
|
|
* option) any later version. *
|
|
|
|
\**************************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
class holidaycalc {
|
|
|
|
|
|
|
|
function calculate_date($holiday, &$holidays, $year, $datetime, &$i)
|
|
|
|
{
|
2001-12-04 03:38:29 +01:00
|
|
|
// if($holiday['day'] == 0 && $holiday['dow'] != 0 && $holiday['occurence'] != 0)
|
|
|
|
if($holiday['day'] == 0 && $holiday['occurence'] != 0)
|
2001-06-19 02:44:04 +02:00
|
|
|
{
|
|
|
|
if($holiday['occurence'] != 99)
|
|
|
|
{
|
|
|
|
$dow = $datetime->day_of_week($year,$holiday['month'],1);
|
|
|
|
$day = (7 * $holiday['occurence'] - 6 + ($holiday['dow'] - $dow) % 7);
|
|
|
|
$day += ($day < 1 ? 7 : 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-07-09 02:11:09 +02:00
|
|
|
$ld = $datetime->days_in_month($holiday['month'],$year);
|
2001-06-19 02:44:04 +02:00
|
|
|
$dow = $datetime->day_of_week($year,$holiday['month'],$ld);
|
|
|
|
$day = $ld - ($dow - $holiday['dow']) % 7 ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$day = $holiday['day'];
|
|
|
|
if($holiday['observance_rule'] == True)
|
|
|
|
{
|
|
|
|
$dow = $datetime->day_of_week($year,$holiday['month'],$day);
|
|
|
|
// This now calulates Observed holidays and creates a new entry for them.
|
|
|
|
if($dow == 0)
|
|
|
|
{
|
|
|
|
$i++;
|
2001-07-16 13:40:22 +02:00
|
|
|
$holidays[$i]['locale'] = $holiday['locale'];
|
|
|
|
$holidays[$i]['name'] = $holiday['name'].' (Observed)';
|
2001-06-19 02:44:04 +02:00
|
|
|
$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) - $datetime->tz_offset;
|
|
|
|
$holidays[$i]['obervance_rule'] = 0;
|
|
|
|
}
|
|
|
|
elseif($dow == 6)
|
|
|
|
{
|
|
|
|
$i++;
|
2001-07-16 13:40:22 +02:00
|
|
|
$holidays[$i]['locale'] = $holiday['locale'];
|
|
|
|
$holidays[$i]['name'] = $holiday['name'].' (Observed)';
|
2001-06-19 02:44:04 +02:00
|
|
|
$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) - $datetime->tz_offset;
|
|
|
|
$holidays[$i]['obervance_rule'] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$date = mktime(0,0,0,$holiday['month'],$day,$year) - $datetime->tz_offset;
|
|
|
|
|
|
|
|
return $date;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|