diff options
| author | fisharebest <fisharebest@gmail.com> | 2013-06-23 17:58:17 +0000 |
|---|---|---|
| committer | fisharebest <fisharebest@gmail.com> | 2013-06-23 17:58:17 +0000 |
| commit | a30e3d5b12f5c5aa1d1e55ba0aa7f4db74e68498 (patch) | |
| tree | bbfc3b88ea30709304a1f13e5e1fe170e25f76b6 /library | |
| parent | 287e5d28b8a5a876a1fecd0a04eff6d448fc0fd0 (diff) | |
| download | webtrees-a30e3d5b12f5c5aa1d1e55ba0aa7f4db74e68498.tar.gz webtrees-a30e3d5b12f5c5aa1d1e55ba0aa7f4db74e68498.tar.bz2 webtrees-a30e3d5b12f5c5aa1d1e55ba0aa7f4db74e68498.zip | |
Use PHP5.3 language features in date classes - gives performance gain of several percent
Diffstat (limited to 'library')
| -rw-r--r-- | library/WT/Date/Calendar.php | 167 | ||||
| -rw-r--r-- | library/WT/Date/French.php | 49 | ||||
| -rw-r--r-- | library/WT/Date/Gregorian.php | 10 | ||||
| -rw-r--r-- | library/WT/Date/Hijri.php | 37 | ||||
| -rw-r--r-- | library/WT/Date/Jalali.php | 43 | ||||
| -rw-r--r-- | library/WT/Date/Jewish.php | 41 | ||||
| -rw-r--r-- | library/WT/Date/Julian.php | 8 | ||||
| -rw-r--r-- | library/WT/Date/Roman.php | 4 |
8 files changed, 104 insertions, 255 deletions
diff --git a/library/WT/Date/Calendar.php b/library/WT/Date/Calendar.php index 1f47deecc4..6b59fce5e7 100644 --- a/library/WT/Date/Calendar.php +++ b/library/WT/Date/Calendar.php @@ -36,10 +36,19 @@ if (!defined('WT_WEBTREES')) { } class WT_Date_Calendar { + const CALENDAR_ESCAPE = '@#DUNKNOWN@'; + const NUM_MONTHS = 12; + const CAL_START_JD = 0; // @#DJULIAN@ 01 JAN 4713B.C. + const CAL_END_JD = 99999999; + const NUM_DAYS_OF_WEEK = 7; + static $MONTH_ABBREV = array( + ''=>0, 'JAN'=>1, 'FEB'=>2, 'MAR'=>3, 'APR'=>4, 'MAY'=>5, 'JUN'=>6, 'JUL'=>7, 'AUG'=>8, 'SEP'=>9, 'OCT'=>10, 'NOV'=>11, 'DEC'=>12 + ); + var $y, $m, $d; // Numeric year/month/day var $minJD, $maxJD; // Julian Day numbers - function __construct($date) { + public function __construct($date) { // Construct from an integer (a julian day number) if (is_numeric($date)) { $this->minJD=$date; @@ -48,14 +57,14 @@ class WT_Date_Calendar { return; } - // Construct from an array (of three gedcom-style strings: "1900", "feb", "4") + // Construct from an array (of three gedcom-style strings: "1900", "FEB", "4") if (is_array($date)) { - $this->d=(int)$date[2]; - if (!is_null($this->MONTH_TO_NUM($date[1]))) { - $this->m=$this->MONTH_TO_NUM($date[1]); + $this->d = (int)$date[2]; + if (array_key_exists($date[1], static::$MONTH_ABBREV)) { + $this->m = static::$MONTH_ABBREV[$date[1]]; } else { - $this->m=0; - $this->d=0; + $this->m = 0; + $this->d = 0; } $this->y=$this->ExtractYear($date[0]); $this->SetJDfromYMD(); @@ -64,7 +73,6 @@ class WT_Date_Calendar { // Construct from an equivalent xxxxDate object if (get_class($this)==get_class($date)) { - // NOTE - can't copy whole object - need to be able to copy Hebrew to Jewish, etc. $this->y=$date->y; $this->m=$date->m; $this->d=$date->d; @@ -90,8 +98,8 @@ class WT_Date_Calendar { $this->SetJDfromYMD(); } - // Set the object's JD from a potentially incomplete YMD - function SetJDfromYMD() { + // Set the object’s JD from a potentially incomplete YMD + public function SetJDfromYMD() { if ($this->y==0) { $this->minJD=0; $this->maxJD=0; @@ -111,22 +119,6 @@ class WT_Date_Calendar { } } - // Calendars are defined in terms of the following static functions. - // They should redefine them as necessary. - static function CALENDAR_ESCAPE() { - return '@#DUNKNOWN@'; - } - static function NUM_MONTHS() { - return 12; - } - static function MONTH_TO_NUM($m) { - static $months=array(''=>0, 'JAN'=>1, 'FEB'=>2, 'MAR'=>3, 'APR'=>4, 'MAY'=>5, 'JUN'=>6, 'JUL'=>7, 'AUG'=>8, 'SEP'=>9, 'OCT'=>10, 'NOV'=>11, 'DEC'=>12); - if (isset($months[$m])) { - return $months[$m]; - } else { - return null; - } - } // We put these in the base class, to save duplicating it in the Julian and Gregorian calendars static function NUM_TO_MONTH_NOMINATIVE($n, $leap_year) { switch ($n) { @@ -213,32 +205,6 @@ class WT_Date_Calendar { default: return ''; } } - static function NUM_TO_GEDCOM_MONTH($n, $leap_year) { - switch ($n) { - case 1: return 'JAN'; - case 2: return 'FEB'; - case 3: return 'MAR'; - case 4: return 'APR'; - case 5: return 'MAY'; - case 6: return 'JUN'; - case 7: return 'JUL'; - case 8: return 'AUG'; - case 9: return 'SEP'; - case 10: return 'OCT'; - case 11: return 'NOV'; - case 12: return 'DEC'; - default: return ''; - } - } - static function CAL_START_JD() { - return 0; // @#DJULIAN@ 01 JAN 4713B.C. - } - static function CAL_END_JD() { - return 99999999; - } - static function NUM_DAYS_OF_WEEK() { - return 7; - } static function LONG_DAYS_OF_WEEK($n) { switch ($n) { case 0: return WT_I18N::translate('Monday'); @@ -271,12 +237,12 @@ class WT_Date_Calendar { static function NextYear($y) { return $y+1; } - // Calendars that use suffixes, etc. (e.g. 'B.C.') or OS/NS notation should redefine this. - function ExtractYear($year) { + // Calendars that use suffixes, etc. (e.g. “B.C.”) or OS/NS notation should redefine this. + public function ExtractYear($year) { return (int)$year; } // Leap years may have extra days, extra months, etc. - function IsLeapYear() { + public function IsLeapYear() { return false; } @@ -295,7 +261,7 @@ class WT_Date_Calendar { // bool $full: true=gedcom style, false=just years // int $jd: date for calculation // TODO: WT_Date_Jewish needs to redefine this to cope with leap months - function GetAge($full, $jd, $warn_on_negative=true) { + public function GetAge($full, $jd, $warn_on_negative=true) { if ($this->y==0 || $jd==0) { return $full?'':'0'; } @@ -317,7 +283,7 @@ class WT_Date_Calendar { $dm--; } if ($dm<0) { - $dm+=$this->NUM_MONTHS(); + $dm+=static::NUM_MONTHS; $dy--; } // Not a full age? Then just the years @@ -326,7 +292,7 @@ class WT_Date_Calendar { // Age in years? if ($dy>1) return $dy.'y'; - $dm+=$dy*$this->NUM_MONTHS(); + $dm+=$dy*static::NUM_MONTHS; // Age in months? if ($dm>1) return $dm.'m'; @@ -335,7 +301,7 @@ class WT_Date_Calendar { } // Convert a date from one calendar to another. - function convert_to_cal($calendar) { + public function convert_to_cal($calendar) { switch ($calendar) { case 'gregorian': return new WT_Date_Gregorian($this); @@ -355,25 +321,30 @@ class WT_Date_Calendar { } // Is this date within the valid range of the calendar - function InValidRange() { - return $this->minJD>=$this->CAL_START_JD() && $this->maxJD<=$this->CAL_END_JD(); + public function InValidRange() { + return $this->minJD >= static::CAL_START_JD && $this->maxJD <= static::CAL_END_JD; + } + + // How many months in a year + public function MonthsInYear() { + return static::MONTHS_IN_YEAR; } // How many days in the current month - function DaysInMonth() { + public function DaysInMonth() { list($ny,$nm)=$this->NextMonth(); return $this->YMDtoJD($ny, $nm, 1) - $this->YMDtoJD($this->y, $this->m, 1); } // How many days in the current week - function DaysInWeek() { - return $this->NUM_DAYS_OF_WEEK(); + public function DaysInWeek() { + return static::NUM_DAYS_OF_WEEK; } // Format a date // $format - format string: the codes are specified in http://php.net/date - function Format($format, $qualifier='') { - // Don't show exact details for inexact dates + public function Format($format, $qualifier='') { + // Don’t show exact details for inexact dates if (!$this->d) { // The comma is for US "M D, Y" dates $format=preg_replace('/%[djlDNSwz][,]?/', '', $format); @@ -384,7 +355,7 @@ class WT_Date_Calendar { if (!$this->y) { $format=str_replace(array('%t', '%L', '%G', '%y', '%Y'), '', $format); } - // If we've trimmed the format, also trim the punctuation + // If we’ve trimmed the format, also trim the punctuation if (!$this->d || !$this->m || !$this->y) { $format=trim($format, ',. ;/-'); } @@ -427,7 +398,7 @@ class WT_Date_Calendar { case '%Y': $format=str_replace($match, $this->FormatLongYear(), $format); break; case '%y': $format=str_replace($match, $this->FormatShortYear(), $format); break; // These 4 extensions are useful for re-formatting gedcom dates. - case '%@': $format=str_replace($match, $this->CALENDAR_ESCAPE(), $format); break; + case '%@': $format=str_replace($match, static::CALENDAR_ESCAPE, $format); break; case '%A': $format=str_replace($match, $this->FormatGedcomDay(), $format); break; case '%O': $format=str_replace($match, $this->FormatGedcomMonth(), $format); break; case '%E': $format=str_replace($match, $this->FormatGedcomYear(), $format); break; @@ -438,7 +409,7 @@ class WT_Date_Calendar { // Functions to extract bits of the date in various formats. Individual calendars // will want to redefine some of these. - function FormatDayZeros() { + private function FormatDayZeros() { if ($this->d>9) { return WT_I18N::digits($this->d); } else { @@ -446,23 +417,23 @@ class WT_Date_Calendar { } } - function FormatDay() { + private function FormatDay() { return WT_I18N::digits($this->d); } - function FormatLongWeekday() { - return $this->LONG_DAYS_OF_WEEK($this->minJD % $this->NUM_DAYS_OF_WEEK()); + private function FormatLongWeekday() { + return $this->LONG_DAYS_OF_WEEK($this->minJD % static::NUM_DAYS_OF_WEEK); } - function FormatShortWeekday() { - return $this->SHORT_DAYS_OF_WEEK($this->minJD % $this->NUM_DAYS_OF_WEEK()); + private function FormatShortWeekday() { + return $this->SHORT_DAYS_OF_WEEK($this->minJD % static::NUM_DAYS_OF_WEEK); } - function FormatISOWeekday() { + private function FormatISOWeekday() { return WT_I18N::digits($this->minJD % 7 + 1); } - function FormatOrdinalSuffix() { + private function FormatOrdinalSuffix() { $func="ordinal_suffix_".WT_LOCALE; if (function_exists($func)) return $func($this->d); @@ -470,19 +441,19 @@ class WT_Date_Calendar { return ''; } - function FormatNumericWeekday() { - return WT_I18N::digits(($this->minJD + 1) % $this->NUM_DAYS_OF_WEEK()); + private function FormatNumericWeekday() { + return WT_I18N::digits(($this->minJD + 1) % static::NUM_DAYS_OF_WEEK); } - function FormatDayOfYear() { + private function FormatDayOfYear() { return WT_I18N::digits($this->minJD - $this->YMDtoJD($this->y, 1, 1)); } - function FormatMonth() { + private function FormatMonth() { return WT_I18N::digits($this->m); } - function FormatMonthZeros() { + private function FormatMonthZeros() { if ($this->m>9) { return WT_I18N::digits($this->m); } else { @@ -490,7 +461,7 @@ class WT_Date_Calendar { } } - function FormatLongMonth($case='NOMINATIVE') { + private function FormatLongMonth($case='NOMINATIVE') { switch ($case) { case 'GENITIVE': return $this->NUM_TO_MONTH_GENITIVE ($this->m, $this->IsLeapYear()); case 'NOMINATIVE': return $this->NUM_TO_MONTH_NOMINATIVE ($this->m, $this->IsLeapYear()); @@ -499,17 +470,17 @@ class WT_Date_Calendar { } } - function FormatShortMonth() { + private function FormatShortMonth() { return $this->NUM_TO_SHORT_MONTH($this->m, $this->IsLeapYear()); } // NOTE Short year is NOT a 2-digit year. It is for calendars such as hebrew // which have a 3-digit form of 4-digit years. - function FormatShortYear() { + private function FormatShortYear() { return WT_I18N::digits($this->y); } - function FormatGedcomDay() { + private function FormatGedcomDay() { if ($this->d==0) { return ''; } else { @@ -517,11 +488,11 @@ class WT_Date_Calendar { } } - function FormatGedcomMonth() { - return $this->NUM_TO_GEDCOM_MONTH($this->m, $this->IsLeapYear()); + private function FormatGedcomMonth() { + return array_search($this->m, static::$MONTH_ABBREV); } - function FormatGedcomYear() { + private function FormatGedcomYear() { if ($this->y==0) { return ''; } else { @@ -529,15 +500,15 @@ class WT_Date_Calendar { } } - function FormatLongYear() { + private function FormatLongYear() { return WT_I18N::digits($this->y); } // Calendars with leap-months should redefine this. - function NextMonth() { + private function NextMonth() { return array( - $this->m==$this->NUM_MONTHS() ? $this->NextYear($this->y) : $this->y, - ($this->m%$this->NUM_MONTHS())+1 + $this->m==static::NUM_MONTHS ? $this->NextYear($this->y) : $this->y, + ($this->m % static::NUM_MONTHS)+1 ); } @@ -555,7 +526,7 @@ class WT_Date_Calendar { } // Convert a roman numeral to decimal - static function RomanToNum($roman) { + private static function RomanToNum($roman) { static $lookup=array(1000=>'M', '900'=>'CM', '500'=>'D', 400=>'CD', 100=>'C', 90=>'XC', 50=>'L', 40=>'XL', 10=>'X', 9=>'IX', 5=>'V', 4=>'IV', 1=>'I'); $num=0; foreach ($lookup as $key=>$value) @@ -566,11 +537,11 @@ class WT_Date_Calendar { return $num; } - // Get today's date in the current calendar - function TodayYMD() { + // Get today’s date in the current calendar + public function TodayYMD() { return $this->JDtoYMD(WT_Date_Gregorian::YMDtoJD(date('Y'), date('n'), date('j'))); } - function Today() { + public function Today() { $tmp=clone $this; $ymd=$tmp->TodayYMD(); $tmp->y=$ymd[0]; @@ -581,12 +552,12 @@ class WT_Date_Calendar { } // Create a URL that links this date to the WT calendar - function CalendarURL($date_fmt="") { + public function CalendarURL($date_fmt="") { global $DATE_FORMAT; if (empty($date_fmt)) { $date_fmt=$DATE_FORMAT; } - $URL='calendar.php?cal='.rawurlencode($this->CALENDAR_ESCAPE()); + $URL='calendar.php?cal='.rawurlencode(static::CALENDAR_ESCAPE); $action="year"; if (strpos($date_fmt, "Y")!==false || strpos($date_fmt, "y")!==false) { diff --git a/library/WT/Date/French.php b/library/WT/Date/French.php index c4cf3125ad..1dc7e003b7 100644 --- a/library/WT/Date/French.php +++ b/library/WT/Date/French.php @@ -32,22 +32,19 @@ if (!defined('WT_WEBTREES')) { } class WT_Date_French extends WT_Date_Calendar { - static function CALENDAR_ESCAPE() { - return '@#DFRENCH R@'; - } + const CALENDAR_ESCAPE = '@#DFRENCH R@'; + const NUM_MONTHS = 13; + const CAL_START_JD = 2375840; // 22 SEP 1792 = 01 VEND 0001 + const CAL_END_JD = 2380687; // 31 DEC 1805 = 10 NIVO 0014 + const NUM_DAYS_OF_WEEK = 10; // A metric week of 10 unimaginatively named days. + static $MONTH_ABBREV = array( + ''=>0, 'VEND'=>1, 'BRUM'=>2, 'FRIM'=>3, 'NIVO'=>4, 'PLUV'=>5, 'VENT'=>6, 'GERM'=>7, 'FLOR'=>8, 'PRAI'=>9, 'MESS'=>10, 'THER'=>11, 'FRUC'=>12, 'COMP'=>13 + ); static function calendarName() { return /* I18N: The French calendar */ WT_I18N::translate('French'); } - static function MONTH_TO_NUM($m) { - static $months=array(''=>0, 'VEND'=>1, 'BRUM'=>2, 'FRIM'=>3, 'NIVO'=>4, 'PLUV'=>5, 'VENT'=>6, 'GERM'=>7, 'FLOR'=>8, 'PRAI'=>9, 'MESS'=>10, 'THER'=>11, 'FRUC'=>12, 'COMP'=>13); - if (isset($months[$m])) { - return $months[$m]; - } else { - return null; - } - } static function NUM_TO_MONTH_NOMINATIVE($n, $leap_year) { switch ($n) { case 1: return WT_I18N::translate_c('NOMINATIVE', 'Vendémiaire'); @@ -120,26 +117,7 @@ class WT_Date_French extends WT_Date_Calendar { // TODO: Do these have short names? return self::NUM_TO_MONTH_NOMINATIVE($n, $leap_year); } - static function NUM_TO_GEDCOM_MONTH($n, $leap_year) { - switch ($n) { - case 1: return 'VEND'; - case 2: return 'BRUM'; - case 3: return 'FRIM'; - case 4: return 'NIVO'; - case 5: return 'PLUV'; - case 6: return 'VENT'; - case 7: return 'GERM'; - case 8: return 'FLOR'; - case 9: return 'PRAI'; - case 10: return 'MESS'; - case 11: return 'THER'; - case 12: return 'FRUC'; - case 13: return 'COMP'; - } - } - static function NUM_MONTHS() { - return 13; - } + static function LONG_DAYS_OF_WEEK($n) { switch ($n) { case 0: return WT_I18N::translate('Primidi'); @@ -158,15 +136,6 @@ class WT_Date_French extends WT_Date_Calendar { // TODO: Do these have short names? return self::LONG_DAYS_OF_WEEK($n); } - static function NUM_DAYS_OF_WEEK() { - return 10; // A "metric" week of 10 unimaginatively named days. - } - static function CAL_START_JD() { - return 2375840; // 22 SEP 1792 = 01 VEND 0001 - } - static function CAL_END_JD() { - return 2380687; // 31 DEC 1805 = 10 NIVO 0014 - } // Leap years were based on astronomical observations. Only years 3, 7 and 11 // were ever observed. Moves to a gregorian-like (fixed) system were proposed diff --git a/library/WT/Date/Gregorian.php b/library/WT/Date/Gregorian.php index 2eeeb0bf8e..1fbc4a239f 100644 --- a/library/WT/Date/Gregorian.php +++ b/library/WT/Date/Gregorian.php @@ -8,7 +8,7 @@ // midday. // // webtrees: Web based Family History software -// Copyright (C) 2012 webtrees development team. +// Copyright (C) 2013 webtrees development team. // // 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 @@ -32,12 +32,8 @@ if (!defined('WT_WEBTREES')) { } class WT_Date_Gregorian extends WT_Date_Calendar { - static function CALENDAR_ESCAPE() { - return '@#DGREGORIAN@'; - } - static function CAL_START_JD() { - return 2299161; // 15 OCT 1582 - } + const CALENDAR_ESCAPE = '@#DGREGORIAN@'; + const CAL_START_JD = 2299161; // 15 OCT 1582 static function calendarName() { return /* I18N: The gregorian calendar */ WT_I18N::translate('Gregorian'); diff --git a/library/WT/Date/Hijri.php b/library/WT/Date/Hijri.php index 2bd168119d..704d35b838 100644 --- a/library/WT/Date/Hijri.php +++ b/library/WT/Date/Hijri.php @@ -33,22 +33,16 @@ if (!defined('WT_WEBTREES')) { } class WT_Date_Hijri extends WT_Date_Calendar { - static function CALENDAR_ESCAPE() { - return '@#DHIJRI@'; - } + const CALENDAR_ESCAPE = '@#DHIJRI@'; + const CAL_START_JD = 1948440; // @#DHIJRI@ 1 MUHAR 0001 = @#JULIAN@ 16 JUL 0622 + static $MONTH_ABBREV = array( + ''=>0, 'MUHAR'=>1, 'SAFAR'=>2, 'RABIA'=>3, 'RABIT'=>4, 'JUMAA'=>5, 'JUMAT'=>6, 'RAJAB'=>7, 'SHAAB'=>8, 'RAMAD'=>9, 'SHAWW'=>10, 'DHUAQ'=>11, 'DHUAH'=>12 + ); static function calendarName() { return /* I18N: The Arabic/Hijri calendar */ WT_I18N::translate('Hijri'); } - static function MONTH_TO_NUM($m) { - static $months=array(''=>0, 'MUHAR'=>1, 'SAFAR'=>2, 'RABIA'=>3, 'RABIT'=>4, 'JUMAA'=>5, 'JUMAT'=>6, 'RAJAB'=>7, 'SHAAB'=>8, 'RAMAD'=>9, 'SHAWW'=>10, 'DHUAQ'=>11, 'DHUAH'=>12); - if (isset($months[$m])) { - return $months[$m]; - } else { - return null; - } - } static function NUM_TO_MONTH_NOMINATIVE($n, $leap_year) { switch ($n) { case 1: return /* I18N: http://en.wikipedia.org/wiki/Muharram */ WT_I18N::translate_c('NOMINATIVE', 'Muharram' ); @@ -117,30 +111,11 @@ class WT_Date_Hijri extends WT_Date_Calendar { default: return ''; } } + static function NUM_TO_SHORT_MONTH($n, $leap_year) { // TODO: Do these have short names? return self::NUM_TO_MONTH_NOMINATIVE($n, $leap_year); } - static function NUM_TO_GEDCOM_MONTH($n, $leap_year) { - switch ($n) { - case 1: return 'MUHAR'; - case 2: return 'SAFAR'; - case 3: return 'RABIA'; - case 4: return 'RABIT'; - case 5: return 'JUMAA'; - case 6: return 'JUMAT'; - case 7: return 'RAJAB'; - case 8: return 'SHAAB'; - case 9: return 'RAMAD'; - case 10: return 'SHAWW'; - case 11: return 'DHUAQ'; - case 12: return 'DHUAH'; - default: return ''; - } - } - static function CAL_START_JD() { - return 1948440; // @#DHIJRI@ 1 MUHAR 0001 = @#JULIAN@ 16 JUL 0622 - } function IsLeapYear() { return ((11*$this->y+14)%30)<11; diff --git a/library/WT/Date/Jalali.php b/library/WT/Date/Jalali.php index 4f08be7ecd..6302c3158f 100644 --- a/library/WT/Date/Jalali.php +++ b/library/WT/Date/Jalali.php @@ -8,7 +8,7 @@ // midday. // // webtrees: Web based Family History software -// Copyright (C) 2012 webtrees development team. +// Copyright (C) 2013 webtrees development team. // // 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 @@ -32,23 +32,16 @@ if (!defined('WT_WEBTREES')) { } class WT_Date_Jalali extends WT_Date_Calendar { - static function CALENDAR_ESCAPE() { - return '@#DJALALI@'; - } + const CALENDAR_ESCAPE = '@#DJALALI@'; + const CAL_START_JD = 1948321; + static $MONTH_ABBREV = array( + ''=>0, 'FARVA'=>1, 'ORDIB'=>2, 'KHORD'=>3, 'TIR'=>4, 'MORDA'=>5, 'SHAHR'=>6, 'MEHR'=>7, 'ABAN'=>8, 'AZAR'=>9, 'DEY'=>10, 'BAHMA'=>11, 'ESFAN'=>12 + ); static function calendarName() { return /* I18N: The Persian/Jalali calendar */ WT_I18N::translate('Jalali'); } - static function MONTH_TO_NUM($m) { - static $months=array(''=>0, 'FARVA'=>1, 'ORDIB'=>2, 'KHORD'=>3, 'TIR'=>4, 'MORDA'=>5, 'SHAHR'=>6, 'MEHR'=>7, 'ABAN'=>8, 'AZAR'=>9, 'DEY'=>10, 'BAHMA'=>11, 'ESFAN'=>12); - if (isset($months[$m])) { - return $months[$m]; - } else { - return null; - } - } - static function NUM_TO_MONTH_NOMINATIVE($n, $leap_year) { switch ($n) { case 1: return /* I18N: 1st month in the Persian/Jalali calendar */ WT_I18N::translate_c('NOMINATIVE', 'Farvardin' ); @@ -139,28 +132,6 @@ class WT_Date_Jalali extends WT_Date_Calendar { } } - static function NUM_TO_GEDCOM_MONTH($n, $leap_year) { - switch ($n) { - case 1: return 'FARVA'; - case 2: return 'ORDIB'; - case 3: return 'KHORD'; - case 4: return 'TIR'; - case 5: return 'MORDA'; - case 6: return 'SHAHR'; - case 7: return 'MEHR'; - case 8: return 'ABAN'; - case 9: return 'AZAR'; - case 10: return 'DEY'; - case 11: return 'BAHMA'; - case 12: return 'ESFAN'; - default: return ''; - } - } - - static function CAL_START_JD() { - return 1948321; - } - function IsLeapYear() { return (((((($this->y - (($this->y > 0) ? 474 : 473)) % 2820) + 474) + 38) * 682) % 2816) < 682; } @@ -177,7 +148,7 @@ class WT_Date_Jalali extends WT_Date_Calendar { (int)((($epyear * 682) - 110) / 2816) + ($epyear - 1) * 365 + (int)($epbase / 2820) * 1029983 + - (self::CAL_START_JD() - 1); + (self::CAL_START_JD - 1); } static function JDtoYMD($jd) { diff --git a/library/WT/Date/Jewish.php b/library/WT/Date/Jewish.php index bc2b2fe804..f3c1a46da4 100644 --- a/library/WT/Date/Jewish.php +++ b/library/WT/Date/Jewish.php @@ -32,9 +32,12 @@ if (!defined('WT_WEBTREES')) { } class WT_Date_Jewish extends WT_Date_Calendar { - static function CALENDAR_ESCAPE() { - return '@#DHEBREW@'; - } + const CALENDAR_ESCAPE = '@#DHEBREW@'; + const NUM_MONTHS = 13; + const CAL_START_JD = 347998; // 01 TSH 0001 = @#JULIAN@ 7 OCT 3761B.C. + static $MONTH_ABBREV = array( + ''=>0, 'TSH'=>1, 'CSH'=>2, 'KSL'=>3, 'TVT'=>4, 'SHV'=>5, 'ADR'=>6, 'ADS'=>7, 'NSN'=>8, 'IYR'=>9, 'SVN'=>10, 'TMZ'=>11, 'AAV'=>12, 'ELL'=>13 + ); static function calendarName() { return /* I18N: The Hebrew/Jewish calendar */ WT_I18N::translate('Jewish'); @@ -76,14 +79,6 @@ class WT_Date_Jewish extends WT_Date_Calendar { } } - static function MONTH_TO_NUM($m) { - static $months=array(''=>0, 'TSH'=>1, 'CSH'=>2, 'KSL'=>3, 'TVT'=>4, 'SHV'=>5, 'ADR'=>6, 'ADS'=>7, 'NSN'=>8, 'IYR'=>9, 'SVN'=>10, 'TMZ'=>11, 'AAV'=>12, 'ELL'=>13); - if (isset($months[$m])) { - return $months[$m]; - } else { - return null; - } - } static function NUM_TO_MONTH_NOMINATIVE($n, $leap_year) { switch ($n) { case 1: return WT_I18N::translate_c('NOMINATIVE', 'Tishrei'); @@ -160,30 +155,6 @@ class WT_Date_Jewish extends WT_Date_Calendar { // TODO: Do these have short names? return self::NUM_TO_MONTH_NOMINATIVE($n, $leap_year); } - static function NUM_TO_GEDCOM_MONTH($n, $leap_year) { - switch ($n) { - case 1: return 'TSH'; - case 2: return 'CSH'; - case 3: return 'KSL'; - case 4: return 'TVT'; - case 5: return 'SHV'; - case 6: return 'ADR'; - case 7: return 'ADS'; - case 8: return 'NSN'; - case 9: return 'IYR'; - case 10: return 'SVN'; - case 11: return 'TMZ'; - case 12: return 'AAV'; - case 13: return 'ELL'; - default: return ''; - } - } - static function NUM_MONTHS() { - return 13; - } - static function CAL_START_JD() { - return 347998; // 01 TSH 0001 = @#JULIAN@ 7 OCT 3761B.C. - } function NextMonth() { if ($this->m==6 && !$this->IsLeapYear()) diff --git a/library/WT/Date/Julian.php b/library/WT/Date/Julian.php index 78b13100ce..d73ef47f35 100644 --- a/library/WT/Date/Julian.php +++ b/library/WT/Date/Julian.php @@ -9,7 +9,7 @@ // midday. // // webtrees: Web based Family History software -// Copyright (C) 2012 webtrees development team. +// Copyright (C) 2013 webtrees development team. // // 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 @@ -33,11 +33,9 @@ if (!defined('WT_WEBTREES')) { } class WT_Date_Julian extends WT_Date_Calendar { - var $new_old_style=false; + const CALENDAR_ESCAPE = '@#DJULIAN@'; - static function CALENDAR_ESCAPE() { - return '@#DJULIAN@'; - } + var $new_old_style=false; static function calendarName() { return /* I18N: The julian calendar */ WT_I18N::translate('Julian'); diff --git a/library/WT/Date/Roman.php b/library/WT/Date/Roman.php index 2f220ab9d4..586bd92afb 100644 --- a/library/WT/Date/Roman.php +++ b/library/WT/Date/Roman.php @@ -35,9 +35,7 @@ if (!defined('WT_WEBTREES')) { } class WT_Date_Roman extends WT_Date_Calendar { - static function CALENDAR_ESCAPE() { - return '@#DROMAN@'; - } + const CALENDAR_ESCAPE = '@#DROMAN@'; function FormatGedcomYear() { return sprintf('%04dAUC',$this->y); |
