diff --git a/calendar/inc/class.calendar_holiday.inc.php b/calendar/inc/class.calendar_holiday.inc.php
index 40796a446a..20e5a55061 100755
--- a/calendar/inc/class.calendar_holiday.inc.php
+++ b/calendar/inc/class.calendar_holiday.inc.php
@@ -149,65 +149,6 @@ class calendar_holiday
}
}
- function calculate_date($holiday,&$i)
- {
- global $phpgw;
-
- if($holiday['day'] == 0 && $holiday['dow'] != 0 && $holiday['occurence'] != 0)
- {
- if($holiday['occurence'] != 99)
- {
- $dow = $this->datetime->day_of_week($this->year,$holiday['month'],1);
- $day = (7 * $holiday['occurence'] - 6 + ($holiday['dow'] - $dow) % 7);
- $day += ($day < 1 ? 7 : 0);
- }
- else
- {
- $ld = $this->datetime->days_in_month($holiday['month'],$this->year);
- $dow = $this->datetime->day_of_week($this->year,$holiday['month'],$ld);
- $day = $ld - ($dow - $holiday['dow']) % 7 ;
- }
- }
- else
- {
- $day = $holiday['day'];
- if($holiday['observance_rule'] == True)
- {
- $dow = $this->datetime->day_of_week($this->year,$holiday['month'],$day);
- // This now calulates Observed holidays and creates a new entry for them.
- if($dow == 0)
- {
- $i++;
- $this->holidays[$i]['locale'] = $holiday['locale'].' (Observed)';
- $this->holidays[$i]['name'] = $holiday['name'];
- $this->holidays[$i]['day'] = $holiday['day'] + 1;
- $this->holidays[$i]['month'] = $holiday['month'];
- $this->holidays[$i]['occurence'] = $holiday['occurence'];
- $this->holidays[$i]['dow'] = $holiday['dow'];
- $this->holidays[$i]['date'] = mktime(0,0,0,$holiday['month'],$day+1,$this->year) - $this->datetime->tz_offset;
- $this->holidays[$i]['obervance_rule'] = 0;
-// echo 'Calculating for year('.$this->year.') month('.$this->holidays[$i]['month'].') dow('.$this->holidays[$i]['dow'].') occurence('.$this->holidays[$i]['occurence'].') datetime('.$this->holidays[$i]['date'].') DATE('.date('Y.m.d H:i:s',$this->holidays[$i]['date']).')
'."\n";
- }
- elseif($dow == 6)
- {
- $i++;
- $this->holidays[$i]['locale'] = $holiday['locale'].' (Observed)';
- $this->holidays[$i]['name'] = $holiday['name'];
- $this->holidays[$i]['day'] = $holiday['day'] - 1;
- $this->holidays[$i]['month'] = $holiday['month'];
- $this->holidays[$i]['occurence'] = $holiday['occurence'];
- $this->holidays[$i]['dow'] = $holiday['dow'];
- $this->holidays[$i]['date'] = mktime(0,0,0,$holiday['month'],$day-1,$this->year) - $this->datetime->tz_offset;
- $this->holidays[$i]['obervance_rule'] = 0;
-// echo 'Calculating for year('.$this->year.') month('.$this->holidays[$i]['month'].') dow('.$this->holidays[$i]['dow'].') occurence('.$this->holidays[$i]['occurence'].') datetime('.$this->holidays[$i]['date'].') DATE('.date('Y.m.d H:i:s',$this->holidays[$i]['date']).')
'."\n";
- }
- }
- }
- $datetime = mktime(0,0,0,$holiday['month'],$day,$this->year) - $this->datetime->tz_offset;
-// echo 'Calculating for year('.$this->year.') month('.$holiday['month'].') dow('.$holiday['dow'].') occurence('.$holiday['occurence'].') datetime('.$datetime.') DATE('.date('Y.m.d H:i:s',$datetime).')
'."\n";
- return $datetime;
- }
-
function read_holiday()
{
global $phpgw;
@@ -222,6 +163,7 @@ class calendar_holiday
$this->db->query($sql,__LINE__,__FILE__);
$i = 0;
+ $holidaycalc = CreateObject('calendar.holidaycalc');
while($this->db->next_record())
{
$this->index[$this->db->f('hol_id')] = $i;
@@ -248,7 +190,7 @@ class calendar_holiday
$this->holidays[$i]['owner'] = 'user';
}
$c = $i;
- $this->holidays[$i]['date'] = $this->calculate_date($this->holidays[$i],$c);
+ $this->holidays[$i]['date'] = $holidaycalc->calculate_date($this->holidays[$i], $this->holidays, $this->year, $this->datetime, $c);
if($c != $i)
{
$i = $c;
diff --git a/calendar/inc/class.holidaycalc.inc.php b/calendar/inc/class.holidaycalc.inc.php
new file mode 100755
index 0000000000..1aea1e6ec1
--- /dev/null
+++ b/calendar/inc/class.holidaycalc.inc.php
@@ -0,0 +1,26 @@
+ *
+ * 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$ */
+
+ if (empty($phpgw_info['user']['preferences']['calendar']['locale']))
+ {
+ $rule = 'EN';
+ }
+ else
+ {
+ $rule = $phpgw_info['user']['preferences']['calendar']['locale'];
+ }
+
+ include(PHPGW_INCLUDE_ROOT.'/calendar/inc/class.holidaycalc_'.$rule.'.inc.php');
+?>
diff --git a/calendar/inc/class.holidaycalc_JP.inc.php b/calendar/inc/class.holidaycalc_JP.inc.php
new file mode 100755
index 0000000000..ce2671ae5f
--- /dev/null
+++ b/calendar/inc/class.holidaycalc_JP.inc.php
@@ -0,0 +1,105 @@
+ *
+ * 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)
+ {
+
+ if($holiday['day'] == 0 && $holiday['dow'] != 0 && $holiday['occurence'] != 0)
+ {
+ // for Coming of Age Day and Health and Sports Day
+ // Happy monday law.
+ if ($year >= 2000)
+ {
+ $dow = $datetime->day_of_week($year, $holiday['month'], 1);
+ $dayshift = (($holiday['dow'] + 7) - $dow) % 7;
+ $day = ($holiday['occurence'] - 1) * 7 + $dayshift + 1;
+ }
+ else
+ {
+ // non Happy monday law.
+ if ($holiday['month'] == 1)
+ {
+ $day = 15;
+ }
+ elseif ($holiday['month'] == 10)
+ {
+ $day = 10;
+ }
+ }
+ }
+ elseif ($holiday['day'] == 0 && $holiday['dow'] == 0 && $holiday['occurence'] == 0)
+ {
+ // For the next generation.
+ // over 2151, please set $factor...
+ if ($holiday['month'] == 3)
+ {
+ // for Vernal Equinox
+ if ($year >= 1980 && $year <= 2099)
+ {
+ $factor = 20.8431;
+ }
+ elseif ($year >= 2100 && $year <= 2150)
+ {
+ $factor = 21.851;
+ }
+ }
+ elseif ($holiday['month'] == 9)
+ {
+ // for Autumnal Equinox
+ if ($year >= 1980 && $year <= 2099)
+ {
+ $factor = 23.2488;
+ }
+ elseif ($year >= 2100 && $year <= 2150)
+ {
+ $factor = 24.2488;
+ }
+ }
+
+ $day = (int)($factor + 0.242194 * ($year - 1980)
+ - (int)(($year - 1980) / 4));
+ }
+ else
+ {
+ // normal holiday
+ $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++;
+ $holidays[$i]['locale'] = $holiday['locale'].' (Observed)';
+ $holidays[$i]['name'] = lang('overlap holiday');
+ $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;
+ }
+}
+?>
diff --git a/calendar/inc/class.holidaycalc_US.inc.php b/calendar/inc/class.holidaycalc_US.inc.php
new file mode 100755
index 0000000000..60125e25a2
--- /dev/null
+++ b/calendar/inc/class.holidaycalc_US.inc.php
@@ -0,0 +1,73 @@
+ *
+ * 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)
+ {
+ if($holiday['day'] == 0 && $holiday['dow'] != 0 && $holiday['occurence'] != 0)
+ {
+ 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
+ {
+ $ld = $datetime->days_in_month($holiday['month'],$this->year);
+ $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++;
+ $holidays[$i]['locale'] = $holiday['locale'].' (Observed)';
+ $holidays[$i]['name'] = $holiday['name'];
+ $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++;
+ $holidays[$i]['locale'] = $holiday['locale'].' (Observed)';
+ $holidays[$i]['name'] = $holiday['name'];
+ $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;
+ }
+}
+?>