diff options
| author | fisharebest <fisharebest@gmail.com> | 2011-01-01 15:04:58 +0000 |
|---|---|---|
| committer | fisharebest <fisharebest@gmail.com> | 2011-01-01 15:04:58 +0000 |
| commit | 65844fe0d595f49a85f3a13ee14ebe0adfd6d0fe (patch) | |
| tree | 918ec27c29f5a3858f67d738d843ad540095b737 | |
| parent | 3f00e12930f917fcd52629041b942db9bec5f701 (diff) | |
| download | webtrees-65844fe0d595f49a85f3a13ee14ebe0adfd6d0fe.tar.gz webtrees-65844fe0d595f49a85f3a13ee14ebe0adfd6d0fe.tar.bz2 webtrees-65844fe0d595f49a85f3a13ee14ebe0adfd6d0fe.zip | |
Refactoring class names and use autoloading.
62 files changed, 2423 insertions, 2287 deletions
diff --git a/autocomplete.php b/autocomplete.php index 293612305a..ce5975b244 100644 --- a/autocomplete.php +++ b/autocomplete.php @@ -128,7 +128,7 @@ function autocomplete_INDI($FILTER, $OPTION) { if ($OPTION) { list($pid, $event_date) = explode("|", $OPTION."|"); $record=WT_GedcomRecord::getInstance($pid); // INDI or FAM - $tmp=new GedcomDate($event_date); + $tmp=new WT_Date($event_date); $event_jd=$tmp->JD(); // INDI $indi_birth_jd = 0; diff --git a/calendar.php b/calendar.php index 42097c5570..b2d6aa09e3 100644 --- a/calendar.php +++ b/calendar.php @@ -54,25 +54,25 @@ if (empty($filterev)) $filterev='bdm'; if (empty($filterof)) $filterof='all'; if (empty($filtersx)) $filtersx=''; -// Create a CalendarDate from the parameters +// Create a WT_Date_Calendar from the parameters // advance-year "year range" if (preg_match('/^(\d+)-(\d+)$/', $year, $match)) { if (strlen($match[1]) > strlen($match[2])) $match[2]=substr($match[1], 0, strlen($match[1])-strlen($match[2])).$match[2]; - $ged_date=new GedcomDate("FROM {$cal} {$match[1]} TO {$cal} {$match[2]}"); + $ged_date=new WT_Date("FROM {$cal} {$match[1]} TO {$cal} {$match[2]}"); $action='year'; } else // advanced-year "decade/century wildcard" if (preg_match('/^(\d+)(\?+)$/', $year, $match)) { $y1=$match[1].str_replace('?', '0', $match[2]); $y2=$match[1].str_replace('?', '9', $match[2]); - $ged_date=new GedcomDate("FROM {$cal} {$y1} TO {$cal} {$y2}"); + $ged_date=new WT_Date("FROM {$cal} {$y1} TO {$cal} {$y2}"); $action='year'; } else { if ($year<0) $year=(-$year)."B.C."; // need BC to parse date - $ged_date=new GedcomDate("{$cal} {$day} {$month} {$year}"); + $ged_date=new WT_Date("{$cal} {$day} {$month} {$year}"); $year=$ged_date->date1->y; // need negative year for year entry field. } $cal_date=&$ged_date->date1; @@ -138,14 +138,14 @@ echo '<tr><td class="descriptionbox vmiddle">'; echo i18n::translate('Day'), help_link('annivers_date_select'), '</td><td colspan="7" class="optionbox">'; for ($d=1; $d<=$days_in_month; $d++) { // Format the day number using the calendar - $tmp=new GedcomDate($cal_date->Format("%@ {$d} %O %E")); $d_fmt=$tmp->date1->Format('%j'); + $tmp=new WT_Date($cal_date->Format("%@ {$d} %O %E")); $d_fmt=$tmp->date1->Format('%j'); if ($d==$cal_date->d) echo "<span class=\"error\">{$d_fmt}</span>"; else echo "<a href=\"calendar.php?cal={$cal}&day={$d}&month={$cal_month}&year={$cal_date->y}&filterev={$filterev}&filterof={$filterof}&filtersx={$filtersx}&action={$action}"."\">{$d_fmt}</a>"; echo ' | '; } -$tmp=new GedcomDate($today->Format('%@ %A %O %E')); // Need a GedcomDate object to get localisation +$tmp=new WT_Date($today->Format('%@ %A %O %E')); // Need a WT_Date object to get localisation echo "<a href=\"calendar.php?cal={$cal}&day={$today->d}&month={$today_month}&year={$today->y}&filterev={$filterev}&filterof={$filterof}&filtersx={$filtersx}&action={$action}\"><b>".$tmp->Display(true, NULL, array()).'</b></a>'; // Month selector echo '<tr><td class="descriptionbox vmiddle">'; @@ -483,7 +483,7 @@ case 'calendar': echo ' '; else { // Format the day number using the calendar - $tmp=new GedcomDate($cal_date->Format("%@ {$d} %O %E")); $d_fmt=$tmp->date1->Format('%j'); + $tmp=new WT_Date($cal_date->Format("%@ {$d} %O %E")); $d_fmt=$tmp->date1->Format('%j'); if ($d==$today->d && $cal_date->m==$today->m) echo "<span class=\"cal_day current_day\">{$d_fmt}</span>"; else diff --git a/edit_interface.php b/edit_interface.php index 889b8ca87b..046598ab36 100644 --- a/edit_interface.php +++ b/edit_interface.php @@ -1433,7 +1433,7 @@ case 'addchildaction': $gedrec = $family->getGedcomRecord(); $done = false; foreach ($family->getChildren() as $key=>$child) { - if (GedcomDate::Compare($newchild->getEstimatedBirthDate(), $child->getEstimatedBirthDate())<0) { + if (WT_Date::Compare($newchild->getEstimatedBirthDate(), $child->getEstimatedBirthDate())<0) { // new child is older : insert before $gedrec = str_replace("1 CHIL @".$child->getXref()."@", "1 CHIL @$xref@\n1 CHIL @".$child->getXref()."@", diff --git a/help_text.php b/help_text.php index 5333781849..0b766fa80d 100644 --- a/help_text.php +++ b/help_text.php @@ -274,77 +274,77 @@ case 'DATE': $title=translate_fact('DATE'); $CALENDAR_FORMAT=null; // Don't perform conversions here - it will confuse the examples! $dates=array( - '1900' =>new GedcomDate('1900'), - 'JAN 1900' =>new GedcomDate('JAN 1900'), - 'FEB 1900' =>new GedcomDate('FEB 1900'), - 'MAR 1900' =>new GedcomDate('MAR 1900'), - 'APR 1900' =>new GedcomDate('APR 1900'), - 'MAY 1900' =>new GedcomDate('MAY 1900'), - 'JUN 1900' =>new GedcomDate('JUN 1900'), - 'JUL 1900' =>new GedcomDate('JUL 1900'), - 'AUG 1900' =>new GedcomDate('AUG 1900'), - 'SEP 1900' =>new GedcomDate('SEP 1900'), - 'OCT 1900' =>new GedcomDate('OCT 1900'), - 'NOV 1900' =>new GedcomDate('NOV 1900'), - 'DEC 1900' =>new GedcomDate('DEC 1900'), - '11 DEC 1913' =>new GedcomDate('11 DEC 1913'), - '01 FEB 2003' =>new GedcomDate('01 FEB 2003'), - 'ABT 1900' =>new GedcomDate('ABT 1900'), - 'EST 1900' =>new GedcomDate('EST 1900'), - 'CAL 1900' =>new GedcomDate('CAL 1900'), - 'INT 1900 (...)' =>new GedcomDate('INT 1900 (...)'), - '@#DJULIAN@ 44 B.C.' =>new GedcomDate('@#DJULIAN@ 44 B.C.'), - '@#DJULIAN@ 14 JAN 1700' =>new GedcomDate('@#DJULIAN@ 14 JAN 1700'), - 'BET @#DJULIAN@ 01 SEP 1752 AND @#DGREGORIAN@ 30 SEP 1752' =>new GedcomDate('BET @#DJULIAN@ 01 SEP 1752 AND @#DGREGORIAN@ 30 SEP 1752'), - '@#DJULIAN@ 20 FEB 1742/43'=>new GedcomDate('@#DJULIAN@ 20 FEB 1742/43'), - 'FROM 1900 TO 1910' =>new GedcomDate('FROM 1900 TO 1910'), - 'FROM 1900' =>new GedcomDate('FROM 1900'), - 'TO 1910' =>new GedcomDate('TO 1910'), - 'BET 1900 AND 1910' =>new GedcomDate('BET 1900 AND 1910'), - 'BET JAN 1900 AND MAR 1900'=>new GedcomDate('BET JAN 1900 AND MAR 1900'), - 'BET APR 1900 AND JUN 1900'=>new GedcomDate('BET APR 1900 AND JUN 1900'), - 'BET JUL 1900 AND SEP 1900'=>new GedcomDate('BET JUL 1900 AND SEP 1900'), - 'BET OCT 1900 AND DEC 1900'=>new GedcomDate('BET OCT 1900 AND DEC 1900'), - 'AFT 1900' =>new GedcomDate('AFT 1900'), - 'BEF 1910' =>new GedcomDate('BEF 1910'), + '1900' =>new WT_Date('1900'), + 'JAN 1900' =>new WT_Date('JAN 1900'), + 'FEB 1900' =>new WT_Date('FEB 1900'), + 'MAR 1900' =>new WT_Date('MAR 1900'), + 'APR 1900' =>new WT_Date('APR 1900'), + 'MAY 1900' =>new WT_Date('MAY 1900'), + 'JUN 1900' =>new WT_Date('JUN 1900'), + 'JUL 1900' =>new WT_Date('JUL 1900'), + 'AUG 1900' =>new WT_Date('AUG 1900'), + 'SEP 1900' =>new WT_Date('SEP 1900'), + 'OCT 1900' =>new WT_Date('OCT 1900'), + 'NOV 1900' =>new WT_Date('NOV 1900'), + 'DEC 1900' =>new WT_Date('DEC 1900'), + '11 DEC 1913' =>new WT_Date('11 DEC 1913'), + '01 FEB 2003' =>new WT_Date('01 FEB 2003'), + 'ABT 1900' =>new WT_Date('ABT 1900'), + 'EST 1900' =>new WT_Date('EST 1900'), + 'CAL 1900' =>new WT_Date('CAL 1900'), + 'INT 1900 (...)' =>new WT_Date('INT 1900 (...)'), + '@#DJULIAN@ 44 B.C.' =>new WT_Date('@#DJULIAN@ 44 B.C.'), + '@#DJULIAN@ 14 JAN 1700' =>new WT_Date('@#DJULIAN@ 14 JAN 1700'), + 'BET @#DJULIAN@ 01 SEP 1752 AND @#DGREGORIAN@ 30 SEP 1752' =>new WT_Date('BET @#DJULIAN@ 01 SEP 1752 AND @#DGREGORIAN@ 30 SEP 1752'), + '@#DJULIAN@ 20 FEB 1742/43'=>new WT_Date('@#DJULIAN@ 20 FEB 1742/43'), + 'FROM 1900 TO 1910' =>new WT_Date('FROM 1900 TO 1910'), + 'FROM 1900' =>new WT_Date('FROM 1900'), + 'TO 1910' =>new WT_Date('TO 1910'), + 'BET 1900 AND 1910' =>new WT_Date('BET 1900 AND 1910'), + 'BET JAN 1900 AND MAR 1900'=>new WT_Date('BET JAN 1900 AND MAR 1900'), + 'BET APR 1900 AND JUN 1900'=>new WT_Date('BET APR 1900 AND JUN 1900'), + 'BET JUL 1900 AND SEP 1900'=>new WT_Date('BET JUL 1900 AND SEP 1900'), + 'BET OCT 1900 AND DEC 1900'=>new WT_Date('BET OCT 1900 AND DEC 1900'), + 'AFT 1900' =>new WT_Date('AFT 1900'), + 'BEF 1910' =>new WT_Date('BEF 1910'), // Hijri dates - '@#DHIJRI@ 1497' =>new GedcomDate('@#DHIJRI@ 1497'), - '@#DHIJRI@ MUHAR 1497' =>new GedcomDate('@#DHIJRI@ MUHAR 1497'), - 'ABT @#DHIJRI@ SAFAR 1497' =>new GedcomDate('ABT @#DHIJRI@ SAFAR 1497'), - 'BET @#DHIJRI@ RABIA 1497 AND @#DHIJRI@ RABIT 1497'=>new GedcomDate('BET @#DHIJRI@ RABIA 1497 AND @#DHIJRI@ RABIT 1497'), - 'FROM @#DHIJRI@ JUMAA 1497 TO @#DHIJRI@ JUMAT 1497'=>new GedcomDate('FROM @#DHIJRI@ JUMAA 1497 TO @#DHIJRI@ JUMAT 1497'), - 'AFT @#DHIJRI@ RAJAB 1497' =>new GedcomDate('AFT @#DHIJRI@ RAJAB 1497'), - 'BEF @#DHIJRI@ SHAAB 1497' =>new GedcomDate('BEF @#DHIJRI@ SHAAB 1497'), - 'ABT @#DHIJRI@ RAMAD 1497' =>new GedcomDate('ABT @#DHIJRI@ RAMAD 1497'), - 'FROM @#DHIJRI@ SHAWW 1497'=>new GedcomDate('FROM @#DHIJRI@ SHAWW 1497'), - 'TO @#DHIJRI@ DHUAQ 1497' =>new GedcomDate('TO @#DHIJRI@ DHUAQ 1497'), - '@#DHIJRI@ 03 DHUAH 1497' =>new GedcomDate('@#DHIJRI@ 03 DHUAH 1497'), + '@#DHIJRI@ 1497' =>new WT_Date('@#DHIJRI@ 1497'), + '@#DHIJRI@ MUHAR 1497' =>new WT_Date('@#DHIJRI@ MUHAR 1497'), + 'ABT @#DHIJRI@ SAFAR 1497' =>new WT_Date('ABT @#DHIJRI@ SAFAR 1497'), + 'BET @#DHIJRI@ RABIA 1497 AND @#DHIJRI@ RABIT 1497'=>new WT_Date('BET @#DHIJRI@ RABIA 1497 AND @#DHIJRI@ RABIT 1497'), + 'FROM @#DHIJRI@ JUMAA 1497 TO @#DHIJRI@ JUMAT 1497'=>new WT_Date('FROM @#DHIJRI@ JUMAA 1497 TO @#DHIJRI@ JUMAT 1497'), + 'AFT @#DHIJRI@ RAJAB 1497' =>new WT_Date('AFT @#DHIJRI@ RAJAB 1497'), + 'BEF @#DHIJRI@ SHAAB 1497' =>new WT_Date('BEF @#DHIJRI@ SHAAB 1497'), + 'ABT @#DHIJRI@ RAMAD 1497' =>new WT_Date('ABT @#DHIJRI@ RAMAD 1497'), + 'FROM @#DHIJRI@ SHAWW 1497'=>new WT_Date('FROM @#DHIJRI@ SHAWW 1497'), + 'TO @#DHIJRI@ DHUAQ 1497' =>new WT_Date('TO @#DHIJRI@ DHUAQ 1497'), + '@#DHIJRI@ 03 DHUAH 1497' =>new WT_Date('@#DHIJRI@ 03 DHUAH 1497'), // French dates - '@#DFRENCH R@ 12' =>new GedcomDate('@#DFRENCH R@ 12'), - '@#DFRENCH R@ VEND 12' =>new GedcomDate('@#DFRENCH R@ VEND 12'), - 'ABT @#DFRENCH R@ BRUM 12' =>new GedcomDate('ABT @#DFRENCH R@ BRUM 12'), - 'BET @#DFRENCH R@ FRIM 12 AND @#DFRENCH R@ NIVO 12'=>new GedcomDate('BET @#DFRENCH R@ FRIM 12 AND @#DFRENCH R@ NIVO 12'), - 'FROM @#DFRENCH R@ PLUV 12 TO @#DFRENCH R@ VENT 12'=>new GedcomDate('FROM @#DFRENCH R@ PLUV 12 TO @#DFRENCH R@ VENT 12'), - 'AFT @#DFRENCH R@ GERM 12' =>new GedcomDate('AFT @#DFRENCH R@ GERM 12'), - 'BEF @#DFRENCH R@ FLOR 12' =>new GedcomDate('BEF @#DFRENCH R@ FLOR 12'), - 'ABT @#DFRENCH R@ PRAI 12' =>new GedcomDate('ABT @#DFRENCH R@ PRAI 12'), - 'FROM @#DFRENCH R@ MESS 12'=>new GedcomDate('FROM @#DFRENCH R@ MESS 12'), - 'TO @#DFRENCH R@ THER 12' =>new GedcomDate('TO @#DFRENCH R@ THER 12'), - 'EST @#DFRENCH R@ FRUC 12' =>new GedcomDate('EST @#DFRENCH R@ FRUC 12'), - '@#DFRENCH R@ 03 COMP 12' =>new GedcomDate('@#DFRENCH R@ 03 COMP 12'), + '@#DFRENCH R@ 12' =>new WT_Date('@#DFRENCH R@ 12'), + '@#DFRENCH R@ VEND 12' =>new WT_Date('@#DFRENCH R@ VEND 12'), + 'ABT @#DFRENCH R@ BRUM 12' =>new WT_Date('ABT @#DFRENCH R@ BRUM 12'), + 'BET @#DFRENCH R@ FRIM 12 AND @#DFRENCH R@ NIVO 12'=>new WT_Date('BET @#DFRENCH R@ FRIM 12 AND @#DFRENCH R@ NIVO 12'), + 'FROM @#DFRENCH R@ PLUV 12 TO @#DFRENCH R@ VENT 12'=>new WT_Date('FROM @#DFRENCH R@ PLUV 12 TO @#DFRENCH R@ VENT 12'), + 'AFT @#DFRENCH R@ GERM 12' =>new WT_Date('AFT @#DFRENCH R@ GERM 12'), + 'BEF @#DFRENCH R@ FLOR 12' =>new WT_Date('BEF @#DFRENCH R@ FLOR 12'), + 'ABT @#DFRENCH R@ PRAI 12' =>new WT_Date('ABT @#DFRENCH R@ PRAI 12'), + 'FROM @#DFRENCH R@ MESS 12'=>new WT_Date('FROM @#DFRENCH R@ MESS 12'), + 'TO @#DFRENCH R@ THER 12' =>new WT_Date('TO @#DFRENCH R@ THER 12'), + 'EST @#DFRENCH R@ FRUC 12' =>new WT_Date('EST @#DFRENCH R@ FRUC 12'), + '@#DFRENCH R@ 03 COMP 12' =>new WT_Date('@#DFRENCH R@ 03 COMP 12'), // Jewish dates - '@#DHEBREW@ 5481' =>new GedcomDate('@#DHEBREW@ 5481'), - '@#DHEBREW@ TSH 5481' =>new GedcomDate('@#DHEBREW@ TSH 5481'), - 'ABT @#DHEBREW@ CSH 5481' =>new GedcomDate('ABT @#DHEBREW@ CSH 5481'), - 'BET @#DHEBREW@ KSL 5481 AND @#DHEBREW@ TVT 5481'=>new GedcomDate('BET @#DHEBREW@ KSL 5481 AND @#DHEBREW@ TVT 5481'), - 'FROM @#DHEBREW@ SHV 5481 TO @#DHEBREW@ ADR 5481'=>new GedcomDate('FROM @#DHEBREW@ SHV 5481 TO @#DHEBREW@ ADR 5481'), - 'AFT @#DHEBREW@ ADS 5481' =>new GedcomDate('AFT @#DHEBREW@ ADS 5481'), - 'BEF @#DHEBREW@ NSN 5481' =>new GedcomDate('BEF @#DHEBREW@ NSN 5481'), - 'ABT @#DHEBREW@ IYR 5481' =>new GedcomDate('ABT @#DHEBREW@ IYR 5481'), - 'FROM @#DHEBREW@ SVN 5481'=>new GedcomDate('FROM @#DHEBREW@ SVN 5481'), - 'TO @#DHEBREW@ TMZ 5481' =>new GedcomDate('TO @#DHEBREW@ TMZ 5481'), - 'EST @#DHEBREW@ AAV 5481' =>new GedcomDate('EST @#DHEBREW@ AAV 5481'), - '@#DHEBREW@ 03 ELL 5481' =>new GedcomDate('@#DHEBREW@ 03 ELL 5481'), + '@#DHEBREW@ 5481' =>new WT_Date('@#DHEBREW@ 5481'), + '@#DHEBREW@ TSH 5481' =>new WT_Date('@#DHEBREW@ TSH 5481'), + 'ABT @#DHEBREW@ CSH 5481' =>new WT_Date('ABT @#DHEBREW@ CSH 5481'), + 'BET @#DHEBREW@ KSL 5481 AND @#DHEBREW@ TVT 5481'=>new WT_Date('BET @#DHEBREW@ KSL 5481 AND @#DHEBREW@ TVT 5481'), + 'FROM @#DHEBREW@ SHV 5481 TO @#DHEBREW@ ADR 5481'=>new WT_Date('FROM @#DHEBREW@ SHV 5481 TO @#DHEBREW@ ADR 5481'), + 'AFT @#DHEBREW@ ADS 5481' =>new WT_Date('AFT @#DHEBREW@ ADS 5481'), + 'BEF @#DHEBREW@ NSN 5481' =>new WT_Date('BEF @#DHEBREW@ NSN 5481'), + 'ABT @#DHEBREW@ IYR 5481' =>new WT_Date('ABT @#DHEBREW@ IYR 5481'), + 'FROM @#DHEBREW@ SVN 5481' =>new WT_Date('FROM @#DHEBREW@ SVN 5481'), + 'TO @#DHEBREW@ TMZ 5481' =>new WT_Date('TO @#DHEBREW@ TMZ 5481'), + 'EST @#DHEBREW@ AAV 5481' =>new WT_Date('EST @#DHEBREW@ AAV 5481'), + '@#DHEBREW@ 03 ELL 5481' =>new WT_Date('@#DHEBREW@ 03 ELL 5481'), ); foreach ($dates as &$date) { diff --git a/includes/classes/class_date.php b/includes/classes/class_date.php deleted file mode 100644 index 8863e871e8..0000000000 --- a/includes/classes/class_date.php +++ /dev/null @@ -1,1776 +0,0 @@ -<?php -/** - * Classes for Gedcom Date/Calendar functionality. - * - * webtrees: Web based Family History software - * Copyright (C) 2010 webtrees development team. - * - * Derived from PhpGedView - * Copyright (C) 2007 to 2010 Greg Roach - * - * 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. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * @package webtrees - * @author Greg Roach - * @version $Id$ - * - * NOTE: Since different calendars start their days at different times, (civil - * midnight, solar midnight, sunset, sunrise, etc.), we convert on the basis of - * midday. - * - * NOTE: We assume that years start on the first day of the first month. Where - * this is not the case (e.g. England prior to 1752), we need to use modified - * years or the OS/NS notation "4 FEB 1750/51". - * - * NOTE: WT should only be using the GedcomDate class. The other classes - * are all for internal use only. - */ - -if (!defined('WT_WEBTREES')) { - header('HTTP/1.0 403 Forbidden'); - exit; -} - -define('WT_CLASS_DATE_PHP', ''); - -//////////////////////////////////////////////////////////////////////////////// -// -// CalendarDate is a base class for classes such as GregorianDate, etc. -// -// + All supported calendars have non-zero days/months/years. -// + We store dates as both Y/M/D and Julian Days. -// + For imprecise dates such as "JAN 2000" we store the start/end julian day. -// -//////////////////////////////////////////////////////////////////////////////// -class CalendarDate { - var $y, $m, $d; // Numeric year/month/day - var $minJD, $maxJD; // Julian Day numbers - - function __construct($date) { - // Construct from an integer (a julian day number) - if (is_numeric($date)) { - $this->minJD=$date; - $this->maxJD=$date; - list($this->y, $this->m, $this->d)=$this->JDtoYMD($date); - return; - } - - // 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]); - } else { - $this->m=0; - $this->d=0; - } - $this->y=$this->ExtractYear($date[0]); - $this->SetJDfromYMD(); - return; - } - - // Construct from an equivalent xxxxDate object - if ($this->CALENDAR_ESCAPE()==$date->CALENDAR_ESCAPE()) { - // 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; - $this->minJD=$date->minJD; - $this->maxJD=$date->maxJD; - return; - } - - // ...else construct an inequivalent xxxxDate object - if ($date->y==0) { - // Incomplete date - convert on basis of anniversary in current year - $today=$date->TodayYMD(); - $jd=$date->YMDtoJD($today[0], $date->m, $date->d==0?$today[2]:$date->d); - } else { - // Complete date - $jd=floor(($date->maxJD+$date->minJD)/2); - } - list($this->y, $this->m, $this->d)=$this->JDtoYMD($jd); - // New date has same precision as original date - if ($date->y==0) $this->y=0; - if ($date->m==0) $this->m=0; - if ($date->d==0) $this->d=0; - $this->SetJDfromYMD(); - } - - // Set the object's JD from a potentially incomplete YMD - function SetJDfromYMD() { - if ($this->y==0) { - $this->minJD=0; - $this->maxJD=0; - } else - if ($this->m==0) { - $this->minJD=$this->YMDtoJD($this->y, 1, 1); - $this->maxJD=$this->YMDtoJD($this->NextYear($this->y), 1, 1)-1; - } else { - if ($this->d==0) { - list($ny,$nm)=$this->NextMonth(); - $this->minJD=$this->YMDtoJD($this->y, $this->m, 1); - $this->maxJD=$this->YMDtoJD($ny, $nm, 1)-1; - } else { - $this->minJD=$this->YMDtoJD($this->y, $this->m, $this->d); - $this->maxJD=$this->minJD; - } - } - } - - // 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) { - case 1: return i18n::translate_c('NOMINATIVE', 'January'); - case 2: return i18n::translate_c('NOMINATIVE', 'February'); - case 3: return i18n::translate_c('NOMINATIVE', 'March'); - case 4: return i18n::translate_c('NOMINATIVE', 'April'); - case 5: return i18n::translate_c('NOMINATIVE', 'May'); - case 6: return i18n::translate_c('NOMINATIVE', 'June'); - case 7: return i18n::translate_c('NOMINATIVE', 'July'); - case 8: return i18n::translate_c('NOMINATIVE', 'August'); - case 9: return i18n::translate_c('NOMINATIVE', 'September'); - case 10: return i18n::translate_c('NOMINATIVE', 'October'); - case 11: return i18n::translate_c('NOMINATIVE', 'November'); - case 12: return i18n::translate_c('NOMINATIVE', 'December'); - default: return ''; - } - } - static function NUM_TO_MONTH_GENITIVE($n, $leap_year) { - switch ($n) { - case 1: return i18n::translate_c('GENITIVE', 'January'); - case 2: return i18n::translate_c('GENITIVE', 'February'); - case 3: return i18n::translate_c('GENITIVE', 'March'); - case 4: return i18n::translate_c('GENITIVE', 'April'); - case 5: return i18n::translate_c('GENITIVE', 'May'); - case 6: return i18n::translate_c('GENITIVE', 'June'); - case 7: return i18n::translate_c('GENITIVE', 'July'); - case 8: return i18n::translate_c('GENITIVE', 'August'); - case 9: return i18n::translate_c('GENITIVE', 'September'); - case 10: return i18n::translate_c('GENITIVE', 'October'); - case 11: return i18n::translate_c('GENITIVE', 'November'); - case 12: return i18n::translate_c('GENITIVE', 'December'); - default: return ''; - } - } - static function NUM_TO_MONTH_LOCATIVE($n, $leap_year) { - switch ($n) { - case 1: return i18n::translate_c('LOCATIVE', 'January'); - case 2: return i18n::translate_c('LOCATIVE', 'February'); - case 3: return i18n::translate_c('LOCATIVE', 'March'); - case 4: return i18n::translate_c('LOCATIVE', 'April'); - case 5: return i18n::translate_c('LOCATIVE', 'May'); - case 6: return i18n::translate_c('LOCATIVE', 'June'); - case 7: return i18n::translate_c('LOCATIVE', 'July'); - case 8: return i18n::translate_c('LOCATIVE', 'August'); - case 9: return i18n::translate_c('LOCATIVE', 'September'); - case 10: return i18n::translate_c('LOCATIVE', 'October'); - case 11: return i18n::translate_c('LOCATIVE', 'November'); - case 12: return i18n::translate_c('LOCATIVE', 'December'); - default: return ''; - } - } - static function NUM_TO_MONTH_INSTRUMENTAL($n, $leap_year) { - switch ($n) { - case 1: return i18n::translate_c('INSTRUMENTAL', 'January'); - case 2: return i18n::translate_c('INSTRUMENTAL', 'February'); - case 3: return i18n::translate_c('INSTRUMENTAL', 'March'); - case 4: return i18n::translate_c('INSTRUMENTAL', 'April'); - case 5: return i18n::translate_c('INSTRUMENTAL', 'May'); - case 6: return i18n::translate_c('INSTRUMENTAL', 'June'); - case 7: return i18n::translate_c('INSTRUMENTAL', 'July'); - case 8: return i18n::translate_c('INSTRUMENTAL', 'August'); - case 9: return i18n::translate_c('INSTRUMENTAL', 'September'); - case 10: return i18n::translate_c('INSTRUMENTAL', 'October'); - case 11: return i18n::translate_c('INSTRUMENTAL', 'November'); - case 12: return i18n::translate_c('INSTRUMENTAL', 'December'); - default: return ''; - } - } - static function NUM_TO_SHORT_MONTH($n, $leap_year) { - switch ($n) { - case 1: return i18n::translate_c('Abbreviation for January', 'Jan'); - case 2: return i18n::translate_c('Abbreviation for February', 'Feb'); - case 3: return i18n::translate_c('Abbreviation for March', 'Mar'); - case 4: return i18n::translate_c('Abbreviation for April', 'Apr'); - case 5: return i18n::translate_c('Abbreviation for May', 'May'); - case 6: return i18n::translate_c('Abbreviation for June', 'Jun'); - case 7: return i18n::translate_c('Abbreviation for July', 'Jul'); - case 8: return i18n::translate_c('Abbreviation for August', 'Aug'); - case 9: return i18n::translate_c('Abbreviation for September', 'Sep'); - case 10: return i18n::translate_c('Abbreviation for October', 'Oct'); - case 11: return i18n::translate_c('Abbreviation for November', 'Nov'); - case 12: return i18n::translate_c('Abbreviation for December', 'Dec'); - 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 i18n::translate('Monday'); - case 1: return i18n::translate('Tuesday'); - case 2: return i18n::translate('Wednesday'); - case 3: return i18n::translate('Thursday'); - case 4: return i18n::translate('Friday'); - case 5: return i18n::translate('Saturday'); - case 6: return i18n::translate('Sunday'); - } - } - static function SHORT_DAYS_OF_WEEK($n) { - switch ($n) { - case 0: return i18n::translate('Mon'); - case 1: return i18n::translate('Tue'); - case 2: return i18n::translate('Wed'); - case 3: return i18n::translate('Thu'); - case 4: return i18n::translate('Fri'); - case 5: return i18n::translate('Sat'); - case 6: return i18n::translate('Sun'); - } - } - static function YMDtoJD($y, $m, $d) { - return 0; - } - static function JDtoYMD($j) { - return array(0, 0, 0); - } - // Most years are 1 more than the previous, but not always (e.g. 1BC->1AD) - 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) { - return (int)$year; - } - // Leap years may have extra days, extra months, etc. - function IsLeapYear() { - return false; - } - - // Compare two dates - helper function for sorting by date - static function Compare($d1, $d2) { - if ($d1->maxJD < $d2->minJD) - return -1; - if ($d2->minJD > $d1->maxJD) - return 1; - return 0; - } - - // How long between an event and a given julian day - // Return result as either a number of years or - // a gedcom-style age string. - // bool $full: true=gedcom style, false=just years - // int $jd: date for calculation - // TODO: JewishDate needs to redefine this to cope with leap months - function GetAge($full, $jd, $warn_on_negative=true) { - if ($this->y==0 || $jd==0) { - return ''; - } - if ($this->minJD < $jd && $this->maxJD > $jd) { - return ''; - } - if ($this->minJD==$jd) { - return $full?'':'0'; - } - if ($warn_on_negative && $jd<$this->minJD) { - return '<img alt="" src="images/warning.gif" />'; - } - list($y,$m,$d)=$this->JDtoYMD($jd); - $dy=$y-$this->y; - $dm=$m-max($this->m,1); - $dd=$d-max($this->d,1); - if ($dd<0) { - $dd+=$this->DaysInMonth(); - $dm--; - } - if ($dm<0) { - $dm+=$this->NUM_MONTHS(); - $dy--; - } - // Not a full age? Then just the years - if (!$full) - return $dy; - // Age in years? - if ($dy>1) - return $dy.'y'; - $dm+=$dy*$this->NUM_MONTHS(); - // Age in months? - if ($dm>1) - return $dm.'m'; - // Age in days? - return ($jd-$this->minJD)."d"; - } - - // Convert a date from one calendar to another. - function convert_to_cal($calendar) { - switch ($calendar) { - case 'gregorian': - return new GregorianDate($this); - case 'julian': - return new JulianDate($this); - case 'jewish': - if (WT_LOCALE!='he') - return new JewishDate($this); - // no break - case 'hebrew': - return new HebrewDate($this); - case 'french': - return new FrenchRDate($this); - case 'arabic': - if (WT_LOCALE!='ar') - return new ArabicDate($this); - // no break - case 'hijri': - return new HijriDate($this); - default: - return $this; - } - } - - // 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(); - } - - // How many days in the current month - 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(); - } - - // 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 - if (!$this->d) { - // The comma is for US "M D, Y" dates - $format=preg_replace('/%[djlDNSwz][,]?/', '', $format); - } - if (!$this->m) { - $format=str_replace(array('%F', '%m', '%M', '%n', '%t'), '', $format); - } - if (!$this->y) { - $format=str_replace(array('%t', '%L', '%G', '%y', '%Y'), '', $format); - } - // If we've trimmed the format, also trim the punctuation - if (!$this->d || !$this->m || !$this->y) { - $format=trim($format, ',. ;/-'); - } - if ($this->d && preg_match('/%[djlDNSwz]/', $format)) { - // If we have a day-number *and* we are being asked to display it, then genitive - $case='GENITIVE'; - } else { - switch ($qualifier) { - case '': - case 'int': - case 'est': - case 'cal': $case='NOMINATIVE'; break; - case 'to': - case 'abt': - case 'from': $case='GENITIVE'; break; - case 'aft': $case='LOCATIVE'; break; - case 'bef': - case 'bet': - case 'and': $case='INSTRUMENTAL'; break; - } - } - // Build up the formated date, character at a time - preg_match_all('/%[^%]/', $format, $matches); - foreach ($matches[0] as $match) { - switch ($match) { - case '%d': $format=str_replace($match, $this->FormatDayZeros(), $format); break; - case '%j': $format=str_replace($match, $this->FormatDay(), $format); break; - case '%l': $format=str_replace($match, $this->FormatLongWeekday(), $format); break; - case '%D': $format=str_replace($match, $this->FormatShortWeekday(), $format); break; - case '%N': $format=str_replace($match, $this->FormatISOWeekday(), $format); break; - case '%S': $format=str_replace($match, $this->FormatOrdinalSuffix(), $format); break; - case '%w': $format=str_replace($match, $this->FormatNumericWeekday(), $format); break; - case '%z': $format=str_replace($match, $this->FormatDayOfYear(), $format); break; - case '%F': $format=str_replace($match, $this->FormatLongMonth($case), $format); break; - case '%m': $format=str_replace($match, $this->FormatMonthZeros(), $format); break; - case '%M': $format=str_replace($match, $this->FormatShortMonth(), $format); break; - case '%n': $format=str_replace($match, $this->FormatMonth(), $format); break; - case '%t': $format=str_replace($match, $this->DaysInMonth(), $format); break; - case '%L': $format=str_replace($match, (int)$this->IsLeapYear(), $format); break; - 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 '%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; - } - } - return $format; - } - - // Functions to extract bits of the date in various formats. Individual calendars - // will want to redefine some of these. - function FormatDayZeros() { - if ($this->d<10) - return '0'.$this->d; - else - return $this->d; - } - - function FormatDay() { - return $this->d; - } - - function FormatLongWeekday() { - return $this->LONG_DAYS_OF_WEEK($this->minJD % $this->NUM_DAYS_OF_WEEK()); - } - - function FormatShortWeekday() { - return $this->SHORT_DAYS_OF_WEEK($this->minJD % $this->NUM_DAYS_OF_WEEK()); - } - - function FormatISOWeekday() { - return $this->minJD % 7 + 1; - } - - function FormatOrdinalSuffix() { - $func="ordinal_suffix_".WT_LOCALE; - if (function_exists($func)) - return $func($this->d); - else - return ''; - } - - function FormatNumericWeekday() { - return ($this->minJD + 1) % $this->NUM_DAYS_OF_WEEK(); - } - - function FormatDayOfYear() { - return $this->minJD - $this->YMDtoJD($this->y, 1, 1); - } - - function FormatMonth() { - return $this->m; - } - - function FormatMonthZeros() { - if ($this->m > 9) - return $this->m; - else - return '0'.$this->m; - } - - 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()); - case 'LOCATIVE': return $this->NUM_TO_MONTH_LOCATIVE ($this->m, $this->IsLeapYear()); - case 'INSTRUMENTAL': return $this->NUM_TO_MONTH_INSTRUMENTAL($this->m, $this->IsLeapYear()); - } - } - - 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() { - return $this->y; - } - - function FormatGedcomDay() { - if ($this->d==0) - return ''; - else - return sprintf('%02d', $this->d); - } - - function FormatGedcomMonth() { - return $this->NUM_TO_GEDCOM_MONTH($this->m, $this->IsLeapYear()); - } - - function FormatGedcomYear() { - if ($this->y==0) - return ''; - else - return sprintf('%04d', $this->y); - } - - function FormatLongYear() { - return $this->y; - } - - // Calendars with leap-months should redefine this. - function NextMonth() { - return array( - $this->m==$this->NUM_MONTHS() ? $this->NextYear($this->y) : $this->y, - ($this->m%$this->NUM_MONTHS())+1 - ); - } - - // Convert a decimal number to roman numerals - static function NumToRoman($num) { - 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'); - if ($num<1) return $num; - $roman=''; - foreach ($lookup as $key=>$value) - while ($num>=$key) { - $roman.=$value; - $num-=$key; - } - return $roman; - } - - // Convert a roman numeral to decimal - 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) - if (strpos($roman, $value)===0) { - $num+=$key; - $roman=substr($roman, strlen($value)); - } - return $num; - } - - // Get today's date in the current calendar - function TodayYMD() { - return $this->JDtoYMD(GregorianDate::YMDtoJD(date('Y'), date('n'), date('j'))); - } - function Today() { - $tmp=clone $this; - $ymd=$tmp->TodayYMD(); - $tmp->y=$ymd[0]; - $tmp->m=$ymd[1]; - $tmp->d=$ymd[2]; - $tmp->SetJDfromYMD(); - return $tmp; - } - - // Create a URL that links this date to the WT calendar - function CalendarURL($date_fmt="") { - global $DATE_FORMAT; - if (empty($date_fmt)) { - $date_fmt=$DATE_FORMAT; - } - $URL='calendar.php?cal='.$this->CALENDAR_ESCAPE(); - $action="year"; - if (strpos($date_fmt, "Y")!==false - || strpos($date_fmt, "y")!==false) { - $URL.='&year='.$this->FormatGedcomYear(); - } - if (strpos($date_fmt, "F")!==false - || strpos($date_fmt, "M")!==false - || strpos($date_fmt, "m")!==false - || strpos($date_fmt, "n")!==false) { - $URL.='&month='.$this->FormatGedcomMonth(); - if ($this->m>0) - $action="calendar"; - } - if (strpos($date_fmt, "d")!==false - || strpos($date_fmt, "D")!==false - || strpos($date_fmt, "j")!==false) { - $URL.='&day='.$this->FormatGedcomDay(); - if ($this->d>0) - $action="today"; - } - return $URL.'&action='.$action; - } -} // class CalendarDate - -//////////////////////////////////////////////////////////////////////////////// -// Definitions for the Gregorian calendar -//////////////////////////////////////////////////////////////////////////////// -class GregorianDate extends CalendarDate { - static function CALENDAR_ESCAPE() { - return '@#DGREGORIAN@'; - } - static function CAL_START_JD() { - return 2299161; // 15 OCT 1582 - } - - function IsLeapYear() { - return $this->y%4==0 && $this->y%100!=0 || $this->y%400==0; - } - - static function YMDtoJD($y, $m, $d) { - if ($y<0) // 0=1BC, -1=2BC, etc. - ++$y; - $a=floor((14-$m)/12); - $y=$y+4800-$a; - $m=$m+12*$a-3; - return $d+floor((153*$m+2)/5)+365*$y+floor($y/4)-floor($y/100)+floor($y/400)-32045; - } - - static function JDtoYMD($j) { - $a=$j+32044; - $b=floor((4*$a+3)/146097); - $c=$a-floor($b*146097/4); - $d=floor((4*$c+3)/1461); - $e=$c-floor((1461*$d)/4); - $m=floor((5*$e+2)/153); - $day=$e-floor((153*$m+2)/5)+1; - $month=$m+3-12*floor($m/10); - $year=$b*100+$d-4800+floor($m/10); - if ($year<1) // 0=1BC, -1=2BC, etc. - --$year; - return array($year, $month, $day); - } - -} // class GregorianDate - -//////////////////////////////////////////////////////////////////////////////// -// Definitions for the Julian Proleptic calendar -// (Proleptic means we extend it backwards, prior to its introduction in 46BC) -//////////////////////////////////////////////////////////////////////////////// -class JulianDate extends CalendarDate { - var $new_old_style=false; - - static function CALENDAR_ESCAPE() { - return '@#DJULIAN@'; - } - - static function NextYear($y) { - if ($y==-1) - return 1; - else - return $y+1; - } - - function IsLeapYear() { - return $this->y%4==0; - } - - static function YMDtoJD($y, $m, $d) { - if ($y<0) // 0=1BC, -1=2BC, etc. - ++$y; - $a=floor((14-$m)/12); - $y=$y+4800-$a; - $m=$m+12*$a-3; - return $d+floor((153*$m+2)/5)+365*$y+floor($y/4)-32083; - } - - static function JDtoYMD($j) { - $c=$j+32082; - $d=floor((4*$c+3)/1461); - $e=$c-floor(1461*$d/4); - $m=floor((5*$e+2)/153); - $day=$e-floor((153*$m+2)/5)+1; - $month=$m+3-12*floor($m/10); - $year=$d-4800+floor($m/10); - if ($year<1) // 0=1BC, -1=2BC, etc. - --$year; - return array($year, $month, $day); - } - - // Process new-style/old-style years and years BC - function ExtractYear($year) { - if (preg_match('/^(\d\d\d\d) \/ \d{1,4}$/', $year, $match)) { // Assume the first year is correct - $this->new_old_style=true; - return $match[1]+1; - } else - if (preg_match('/^(\d+) b ?c$/', $year, $match)) - return -$match[1]; - else - return (int)$year; - } - - function FormatLongYear() { - if ($this->y<0) { - // I18N: Number of years "before christ" - return i18n::translate('%d B.C.', -$this->y); - } else { - if ($this->new_old_style) { - return sprintf('%d/%02d', $this->y-1, $this->y % 100); - } else - return $this->y; - } - } - - function FormatGedcomYear() { - if ($this->y<0) - return sprintf('%04dB.C.', -$this->y); - else - if ($this->new_old_style) { - return sprintf('%04d/%02d', $this->y-1, $this->y % 100); - } else - return sprintf('%04d', $this->y); - } -} // class JulianDate - -//////////////////////////////////////////////////////////////////////////////// -// Definitions for the Jewish calendar -//////////////////////////////////////////////////////////////////////////////// -class JewishDate extends CalendarDate { - static function CALENDAR_ESCAPE() { - return '@#DHEBREW@'; - } - - 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 i18n::translate_c('NOMINATIVE', 'Tishrei'); - case 2: return i18n::translate_c('NOMINATIVE', 'Heshvan'); - case 3: return i18n::translate_c('NOMINATIVE', 'Kislev'); - case 4: return i18n::translate_c('NOMINATIVE', 'Tevet'); - case 5: return i18n::translate_c('NOMINATIVE', 'Shevat'); - case 6: if ($leap_year) return i18n::translate_c('NOMINATIVE', 'Adar'); else return i18n::translate_c('NOMINATIVE', 'Adar I'); - case 7: return i18n::translate_c('NOMINATIVE', 'Adar II'); - case 8: return i18n::translate_c('NOMINATIVE', 'Nissan'); - case 9: return i18n::translate_c('NOMINATIVE', 'Iyar'); - case 10: return i18n::translate_c('NOMINATIVE', 'Sivan'); - case 11: return i18n::translate_c('NOMINATIVE', 'Tamuz'); - case 12: return i18n::translate_c('NOMINATIVE', 'Av'); - case 13: return i18n::translate_c('NOMINATIVE', 'Elul'); - default: return ''; - } - } - static function NUM_TO_MONTH_GENITIVE($n, $leap_year) { - switch ($n) { - case 1: return i18n::translate_c('GENITIVE', 'Tishrei'); - case 2: return i18n::translate_c('GENITIVE', 'Heshvan'); - case 3: return i18n::translate_c('GENITIVE', 'Kislev'); - case 4: return i18n::translate_c('GENITIVE', 'Tevet'); - case 5: return i18n::translate_c('GENITIVE', 'Shevat'); - case 6: if ($leap_year) return i18n::translate_c('GENITIVE', 'Adar'); else return i18n::translate_c('GENITIVE', 'Adar I'); - case 7: return i18n::translate_c('GENITIVE', 'Adar II'); - case 8: return i18n::translate_c('GENITIVE', 'Nissan'); - case 9: return i18n::translate_c('GENITIVE', 'Iyar'); - case 10: return i18n::translate_c('GENITIVE', 'Sivan'); - case 11: return i18n::translate_c('GENITIVE', 'Tamuz'); - case 12: return i18n::translate_c('GENITIVE', 'Av'); - case 13: return i18n::translate_c('GENITIVE', 'Elul'); - default: return ''; - } - } - static function NUM_TO_MONTH_LOCATIVE($n, $leap_year) { - switch ($n) { - case 1: return i18n::translate_c('LOCATIVE', 'Tishrei'); - case 2: return i18n::translate_c('LOCATIVE', 'Heshvan'); - case 3: return i18n::translate_c('LOCATIVE', 'Kislev'); - case 4: return i18n::translate_c('LOCATIVE', 'Tevet'); - case 5: return i18n::translate_c('LOCATIVE', 'Shevat'); - case 6: if ($leap_year) return i18n::translate_c('LOCATIVE', 'Adar'); else return i18n::translate_c('LOCATIVE', 'Adar I'); - case 7: return i18n::translate_c('LOCATIVE', 'Adar II'); - case 8: return i18n::translate_c('LOCATIVE', 'Nissan'); - case 9: return i18n::translate_c('LOCATIVE', 'Iyar'); - case 10: return i18n::translate_c('LOCATIVE', 'Sivan'); - case 11: return i18n::translate_c('LOCATIVE', 'Tamuz'); - case 12: return i18n::translate_c('LOCATIVE', 'Av'); - case 13: return i18n::translate_c('LOCATIVE', 'Elul'); - default: return ''; - } - } - static function NUM_TO_MONTH_INSTRUMENTAL($n, $leap_year) { - switch ($n) { - case 1: return i18n::translate_c('INSTRUMENTAL', 'Tishrei'); - case 2: return i18n::translate_c('INSTRUMENTAL', 'Heshvan'); - case 3: return i18n::translate_c('INSTRUMENTAL', 'Kislev'); - case 4: return i18n::translate_c('INSTRUMENTAL', 'Tevet'); - case 5: return i18n::translate_c('INSTRUMENTAL', 'Shevat'); - case 6: if ($leap_year) return i18n::translate_c('INSTRUMENTAL', 'Adar'); else return i18n::translate_c('INSTRUMENTAL', 'Adar I'); - case 7: return i18n::translate_c('INSTRUMENTAL', 'Adar II'); - case 8: return i18n::translate_c('INSTRUMENTAL', 'Nissan'); - case 9: return i18n::translate_c('INSTRUMENTAL', 'Iyar'); - case 10: return i18n::translate_c('INSTRUMENTAL', 'Sivan'); - case 11: return i18n::translate_c('INSTRUMENTAL', 'Tamuz'); - case 12: return i18n::translate_c('INSTRUMENTAL', 'Av'); - case 13: return i18n::translate_c('INSTRUMENTAL', 'Elul'); - 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) { - // TODO: Do these have short names in English? - 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()) - return array($this->y, 8); - else - return array($this->y+($this->m==13?1:0), ($this->m%13)+1); - } - - function IsLeapYear() { - return ((7*$this->y+1)%19)<7; - } - - // TODO implement this function locally - static function YMDtoJD($y, $mh, $d) { - if (function_exists('JewishToJD')) - return JewishToJD($mh, $d, $y); - else - return 0; - } - - // TODO implement this function locally - static function JDtoYMD($j) { - if (function_exists('JdToJewish')) - list($m, $d, $y)=explode('/', JDToJewish($j)); - else - list($m, $d, $y)=array(0, 0, 0); - return array($y, $m, $d); - } -} // class JewishDate - -//////////////////////////////////////////////////////////////////////////////// -// Definitions for the Hebrew calendar. -// NOTE - this is the same as the Jewish Calendar, but displays dates in hebrew -// rather than the local language. -//////////////////////////////////////////////////////////////////////////////// -class HebrewDate extends JewishDate { - const GERSHAYIM="״"; - const GERSH="׳"; - const ALAFIM="אלפים"; - - function FormatDayZeros() { - return $this->NumToHebrew($this->d); - } - - function FormatDay() { - return $this->NumToHebrew($this->d); - } - - static function LONG_DAYS_OF_WEEK($n) { - // Do not translate these - they are supposed to be hebrew, whatever language is shown. - switch ($n) { - case 0: return 'שני'; - case 1: return 'שלישי'; - case 2: return 'רביעי'; - case 3: return 'חמישי'; - case 4: return 'ששי'; - case 5: return 'שבת'; - case 6: return 'ראשון'; - } - } - static function SHORT_DAYS_OF_WEEK($n) { - // TODO: Do these have short names? - return LONG_DAYS_OF_WEEK($n); - } - - static function NUM_TO_MONTH_NOMINATIVE($n, $leap_year) { - // Do not translate these - they are supposed to be hebrew, whatever language is shown. - switch ($n) { - case 1: return 'תשרי'; - case 2: return 'חשוון'; - case 3: return 'כסלו'; - case 4: return 'טבת'; - case 5: return 'שבט'; - case 6: if ($leap_year) return 'אדר א׳'; else return 'אדר'; - case 7: return 'אדר ב׳'; - case 8: return 'ניסן'; - case 9: return 'אייר'; - case 10: return 'סיוון'; - case 11: return 'תמוז'; - case 12: return 'אב'; - case 13: return 'אלול'; - default: return ''; - } - } - - static function NUM_TO_MONTH_GENITIVE($n, $leap_year) { - // Hebrew does not have genitive forms - return self::NUM_TO_MONTH_NOMINATIVE($n, $leap_year); - } - - static function NUM_TO_MONTH_LOCATIVE($n, $leap_year) { - // Hebrew does not have locative forms - return self::NUM_TO_MONTH_NOMINATIVE($n, $leap_year); - } - - static function NUM_TO_MONTH_INSTRUMENTAL($n, $leap_year) { - // Hebrew does not have instrumental forms - return self::NUM_TO_MONTH_NOMINATIVE($n, $leap_year); - } - - static function NUM_TO_SHORT_MONTH($n, $leap_year) { - // TODO: Do these have short names? - return self::NUM_TO_MONTH_NOMINATIVE($n, $leap_year); - } - - function FormatShortYear() { - return $this->NumToHebrew($this->y%1000); - } - - function FormatLongYear() { - return $this->NumToHebrew($this->y); - } - // Convert a decimal number to hebrew - like roman numerals, but with extra punctuation - // and special rules. - static function NumToHebrew($num) { - global $DISPLAY_JEWISH_THOUSANDS; - - static $jHundreds = array("", "ק", "ר", "ש", "ת", "תק", "תר","תש", "תת", "תתק"); - static $jTens = array("", "י", "כ", "ל", "מ", "נ", "ס", "ע", "פ", "צ"); - static $jTenEnds = array("", "י", "ך", "ל", "ם", "ן", "ס", "ע", "ף", "ץ"); - static $tavTaz = array("ט״ו", "ט״ז"); - static $jOnes = array("", "א", "ב", "ג", "ד", "ה", "ו", "ז", "ח", "ט"); - - $shortYear = $num %1000; //discard thousands - //next check for all possible single Hebrew digit years - $singleDigitYear=($shortYear < 11 || ($shortYear <100 && $shortYear % 10 == 0) || ($shortYear <= 400 && $shortYear % 100 ==0)); - $thousands = $num / 1000; //get # thousands - $sb = ""; - //append thousands to String - if ($num % 1000 == 0) { // in year is 5000, 4000 etc - $sb .= $jOnes[$thousands]; - $sb .= self::GERSH; - $sb .= " "; - $sb .= self::ALAFIM; //add # of thousands plus word thousand (overide alafim boolean) - } else if ($DISPLAY_JEWISH_THOUSANDS) { // if alafim boolean display thousands - $sb .= $jOnes[$thousands]; - $sb .= self::GERSH; //append thousands quote - $sb .= " "; - } - $num = $num % 1000; //remove 1000s - $hundreds = $num / 100; // # of hundreds - $sb .= $jHundreds[$hundreds]; //add hundreds to String - $num = $num % 100; //remove 100s - if ($num == 15) { //special case 15 - $sb .= $tavTaz[0]; - } else if ($num == 16) { //special case 16 - $sb .= $tavTaz[1]; - } else { - $tens = $num / 10; - if ($num % 10 == 0) { // if evenly divisable by 10 - if ($singleDigitYear == false) { - $sb .= $jTenEnds[$tens]; // use end letters so that for example 5750 will end with an end nun - } else { - $sb .= $jTens[$tens]; // use standard letters so that for example 5050 will end with a regular nun - } - } else { - $sb .= $jTens[$tens]; - $num = $num % 10; - $sb .= $jOnes[$num]; - } - } - if ($singleDigitYear == true) { - $sb .= self::GERSH; //append single quote - } else { // append double quote before last digit - $pos1 = strlen($sb)-2; - $sb = substr($sb, 0, $pos1) . self::GERSHAYIM . substr($sb, $pos1); - $sb = str_replace(self::GERSHAYIM . self::GERSHAYIM, self::GERSHAYIM, $sb); //replace double gershayim with single instance - } - return $sb; - } - -} // class HebrewDate - -//////////////////////////////////////////////////////////////////////////////// -// Definitions for the French Republican calendar -//////////////////////////////////////////////////////////////////////////////// -class FrenchRDate extends CalendarDate { - static function CALENDAR_ESCAPE() { - return '@#DFRENCH R@'; - } - - 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 i18n::translate_c('NOMINATIVE', 'Vendémiaire'); - case 2: return i18n::translate_c('NOMINATIVE', 'Brumaire'); - case 3: return i18n::translate_c('NOMINATIVE', 'Frimaire'); - case 4: return i18n::translate_c('NOMINATIVE', 'Nivôse'); - case 5: return i18n::translate_c('NOMINATIVE', 'Pluviôse'); - case 6: return i18n::translate_c('NOMINATIVE', 'Ventôse'); - case 7: return i18n::translate_c('NOMINATIVE', 'Germinal'); - case 8: return i18n::translate_c('NOMINATIVE', 'Floréal'); - case 9: return i18n::translate_c('NOMINATIVE', 'Prairial'); - case 10: return i18n::translate_c('NOMINATIVE', 'Messidor'); - case 11: return i18n::translate_c('NOMINATIVE', 'Thermidor'); - case 12: return i18n::translate_c('NOMINATIVE', 'Fructidor'); - case 13: return i18n::translate_c('NOMINATIVE', 'jours complémentaires'); - } - } - static function NUM_TO_MONTH_GENITIVE($n, $leap_year) { - switch ($n) { - case 1: return i18n::translate_c('GENITIVE', 'Vendémiaire'); - case 2: return i18n::translate_c('GENITIVE', 'Brumaire'); - case 3: return i18n::translate_c('GENITIVE', 'Frimaire'); - case 4: return i18n::translate_c('GENITIVE', 'Nivôse'); - case 5: return i18n::translate_c('GENITIVE', 'Pluviôse'); - case 6: return i18n::translate_c('GENITIVE', 'Ventôse'); - case 7: return i18n::translate_c('GENITIVE', 'Germinal'); - case 8: return i18n::translate_c('GENITIVE', 'Floréal'); - case 9: return i18n::translate_c('GENITIVE', 'Prairial'); - case 10: return i18n::translate_c('GENITIVE', 'Messidor'); - case 11: return i18n::translate_c('GENITIVE', 'Thermidor'); - case 12: return i18n::translate_c('GENITIVE', 'Fructidor'); - case 13: return i18n::translate_c('GENITIVE', 'jours complémentaires'); - } - } - static function NUM_TO_MONTH_LOCATIVE($n, $leap_year) { - switch ($n) { - case 1: return i18n::translate_c('LOCATIVE', 'Vendémiaire'); - case 2: return i18n::translate_c('LOCATIVE', 'Brumaire'); - case 3: return i18n::translate_c('LOCATIVE', 'Frimaire'); - case 4: return i18n::translate_c('LOCATIVE', 'Nivôse'); - case 5: return i18n::translate_c('LOCATIVE', 'Pluviôse'); - case 6: return i18n::translate_c('LOCATIVE', 'Ventôse'); - case 7: return i18n::translate_c('LOCATIVE', 'Germinal'); - case 8: return i18n::translate_c('LOCATIVE', 'Floréal'); - case 9: return i18n::translate_c('LOCATIVE', 'Prairial'); - case 10: return i18n::translate_c('LOCATIVE', 'Messidor'); - case 11: return i18n::translate_c('LOCATIVE', 'Thermidor'); - case 12: return i18n::translate_c('LOCATIVE', 'Fructidor'); - case 13: return i18n::translate_c('LOCATIVE', 'jours complémentaires'); - } - } - static function NUM_TO_MONTH_INSTRUMENTAL($n, $leap_year) { - switch ($n) { - case 1: return i18n::translate_c('INSTRUMENTAL', 'Vendémiaire'); - case 2: return i18n::translate_c('INSTRUMENTAL', 'Brumaire'); - case 3: return i18n::translate_c('INSTRUMENTAL', 'Frimaire'); - case 4: return i18n::translate_c('INSTRUMENTAL', 'Nivôse'); - case 5: return i18n::translate_c('INSTRUMENTAL', 'Pluviôse'); - case 6: return i18n::translate_c('INSTRUMENTAL', 'Ventôse'); - case 7: return i18n::translate_c('INSTRUMENTAL', 'Germinal'); - case 8: return i18n::translate_c('INSTRUMENTAL', 'Floréal'); - case 9: return i18n::translate_c('INSTRUMENTAL', 'Prairial'); - case 10: return i18n::translate_c('INSTRUMENTAL', 'Messidor'); - case 11: return i18n::translate_c('INSTRUMENTAL', 'Thermidor'); - case 12: return i18n::translate_c('INSTRUMENTAL', 'Fructidor'); - case 13: return i18n::translate_c('INSTRUMENTAL', 'jours complémentaires'); - } - } - 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 '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 i18n::translate('Primidi'); - case 1: return i18n::translate('Duodi'); - case 2: return i18n::translate('Tridi'); - case 3: return i18n::translate('Quartidi'); - case 4: return i18n::translate('Quintidi'); - case 5: return i18n::translate('Sextidi'); - case 6: return i18n::translate('Septidi'); - case 7: return i18n::translate('Octidi'); - case 8: return i18n::translate('Nonidi'); - case 9: return i18n::translate('Decidi'); - } - } - static function SHORT_DAYS_OF_WEEK($n) { - // 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 - // but never implemented. These functions are valid over the range years 1-14. - function IsLeapYear() { - return $this->y%4==3; - } - - static function YMDtoJD($y, $m, $d) { - return 2375444+$d+$m*30+$y*365+floor($y/4); - } - - static function JDtoYMD($j) { - $y=floor(($j-2375109)*4/1461)-1; - $m=floor(($j-2375475-$y*365-floor($y/4))/30)+1; - $d=$j-2375444-$m*30-$y*365-floor($y/4); - return array($y, $m, $d); - } - - // Years were written using roman numerals - function FormatLongYear() { - return $this->NumToRoman($this->y); - } -} // class FrenchRDate - -//////////////////////////////////////////////////////////////////////////////// -// Definitions for the Hijri calendar. Note that these are "theoretical" dates. -// "True" dates are based on local lunar observations, and can be a +/- one day. -//////////////////////////////////////////////////////////////////////////////// -class HijriDate extends CalendarDate { - static function CALENDAR_ESCAPE() { - return '@#DHIJRI@'; - } - 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::translate_c('NOMINATIVE', 'Muharram'); - case 2: return i18n::translate_c('NOMINATIVE', 'Safar'); - case 3: return i18n::translate_c('NOMINATIVE', 'Rabi\' al-awwal'); - case 4: return i18n::translate_c('NOMINATIVE', 'Rabi\' al-thani'); - case 5: return i18n::translate_c('NOMINATIVE', 'Jumada al-awwal'); - case 6: return i18n::translate_c('NOMINATIVE', 'Jumada al-thani'); - case 7: return i18n::translate_c('NOMINATIVE', 'Rajab'); - case 8: return i18n::translate_c('NOMINATIVE', 'Sha\'aban'); - case 9: return i18n::translate_c('NOMINATIVE', 'Ramadan'); - case 10: return i18n::translate_c('NOMINATIVE', 'Shawwal'); - case 11: return i18n::translate_c('NOMINATIVE', 'Dhu al-Qi\'dah'); - case 12: return i18n::translate_c('NOMINATIVE', 'Dhu al-Hijjah'); - default: return ''; - } - } - static function NUM_TO_MONTH_GENITIVE($n, $leap_year) { - switch ($n) { - case 1: return i18n::translate_c('GENITIVE', 'Muharram'); - case 2: return i18n::translate_c('GENITIVE', 'Safar'); - case 3: return i18n::translate_c('GENITIVE', 'Rabi\' al-awwal'); - case 4: return i18n::translate_c('GENITIVE', 'Rabi\' al-thani'); - case 5: return i18n::translate_c('GENITIVE', 'Jumada al-awwal'); - case 6: return i18n::translate_c('GENITIVE', 'Jumada al-thani'); - case 7: return i18n::translate_c('GENITIVE', 'Rajab'); - case 8: return i18n::translate_c('GENITIVE', 'Sha\'aban'); - case 9: return i18n::translate_c('GENITIVE', 'Ramadan'); - case 10: return i18n::translate_c('GENITIVE', 'Shawwal'); - case 11: return i18n::translate_c('GENITIVE', 'Dhu al-Qi\'dah'); - case 12: return i18n::translate_c('GENITIVE', 'Dhu al-Hijjah'); - default: return ''; - } - } - static function NUM_TO_MONTH_LOCATIVE($n, $leap_year) { - switch ($n) { - case 1: return i18n::translate_c('LOCATIVE', 'Muharram'); - case 2: return i18n::translate_c('LOCATIVE', 'Safar'); - case 3: return i18n::translate_c('LOCATIVE', 'Rabi\' al-awwal'); - case 4: return i18n::translate_c('LOCATIVE', 'Rabi\' al-thani'); - case 5: return i18n::translate_c('LOCATIVE', 'Jumada al-awwal'); - case 6: return i18n::translate_c('LOCATIVE', 'Jumada al-thani'); - case 7: return i18n::translate_c('LOCATIVE', 'Rajab'); - case 8: return i18n::translate_c('LOCATIVE', 'Sha\'aban'); - case 9: return i18n::translate_c('LOCATIVE', 'Ramadan'); - case 10: return i18n::translate_c('LOCATIVE', 'Shawwal'); - case 11: return i18n::translate_c('LOCATIVE', 'Dhu al-Qi\'dah'); - case 12: return i18n::translate_c('LOCATIVE', 'Dhu al-Hijjah'); - default: return ''; - } - } - static function NUM_TO_MONTH_INSTRUMENTAL($n, $leap_year) { - switch ($n) { - case 1: return i18n::translate_c('INSTRUMENTAL', 'Muharram'); - case 2: return i18n::translate_c('INSTRUMENTAL', 'Safar'); - case 3: return i18n::translate_c('INSTRUMENTAL', 'Rabi\' al-awwal'); - case 4: return i18n::translate_c('INSTRUMENTAL', 'Rabi\' al-thani'); - case 5: return i18n::translate_c('INSTRUMENTAL', 'Jumada al-awwal'); - case 6: return i18n::translate_c('INSTRUMENTAL', 'Jumada al-thani'); - case 7: return i18n::translate_c('INSTRUMENTAL', 'Rajab'); - case 8: return i18n::translate_c('INSTRUMENTAL', 'Sha\'aban'); - case 9: return i18n::translate_c('INSTRUMENTAL', 'Ramadan'); - case 10: return i18n::translate_c('INSTRUMENTAL', 'Shawwal'); - case 11: return i18n::translate_c('INSTRUMENTAL', 'Dhu al-Qi\'dah'); - case 12: return i18n::translate_c('INSTRUMENTAL', 'Dhu al-Hijjah'); - default: return ''; - } - } - static function NUM_TO_SHORT_MONTH($n, $leap_year) { - // TODO: Do these have short names? - return $this->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; - } - - static function YMDtoJD($y, $m, $d) { - return $d+29*($m-1)+floor((6*$m-1)/11)+$y*354+floor((3+11*$y)/30)+1948085; - } - - static function JDtoYMD($j) { - $y=floor((30*($j-1948440)+10646)/10631); - $m=floor((11*($j-$y*354-floor((3+11*$y)/30)-1948086)+330)/325); - $d=$j-29*($m-1)-floor((6*$m-1)/11)-$y*354-floor((3+11*$y)/30)-1948085; - return array($y, $m, $d); - } -} // class HijriDate - -//////////////////////////////////////////////////////////////////////////////// -// Definitions for the Arabic calendar. -// NOTE - this is the same as the Hijri Calendar, but displays dates in arabic -// rather than the local language. -//////////////////////////////////////////////////////////////////////////////// -class ArabicDate extends HijriDate { - static $ARABIC_DAYS=array("الأثنين", "الثلاثاء", "الأربعاء", "الخميس", "الجمعه", "السبت", "الأحد"); - - static function NUM_TO_MONTH_NOMINATIVE($n, $leap_year) { - // Do not translate these - they are supposed to be arabic, whatever language is shown. - switch ($n) { - case 1: return 'محرّم'; - case 2: return 'صفر'; - case 3: return 'ربيع الأول'; - case 4: return 'ربيع الثانى'; - case 5: return 'جمادى الأول'; - case 6: return 'جمادى الثاني'; - case 7: return 'رجب'; - case 8: return 'شعبان'; - case 9: return 'رمضان'; - case 10: return 'شوّال'; - case 11: return 'ذو القعدة'; - case 12: return 'ذو الحجة'; - default: return ''; - } - } - static function NUM_TO_MONTH_GENITIVE($n, $leap_year) { - // Arabic does not have genitive forms - return self::NUM_TO_MONTH_NOMINATIVE($n, $leap_year); - } - static function NUM_TO_MONTH_LOCATIVE($n, $leap_year) { - // Arabic does not have locative forms - return self::NUM_TO_MONTH_NOMINATIVE($n, $leap_year); - } - - static function NUM_TO_MONTH_INSTRUMENTAL($n, $leap_year) { - // Arabic does not have instrumental forms - return self::NUM_TO_MONTH_NOMINATIVE($n, $leap_year); - } - - static function NUM_TO_SHORT_MONTH($n, $leap_year) { - // TODO: Do these have short names? - return self::NUM_TO_MONTH_NOMINATIVE($n, $leap_year); - } - - function FormatLongWeekday() { - return $this->$ARABIC_DAYS[$this->minJD % $this->NUM_DAYS_OF_WEEK()]; - } - - function FormatShortWeekday() { - return $this->$ARABIC_DAYS[$this->minJD % $this->NUM_DAYS_OF_WEEK()]; - } -} // class ArabicDate - -//////////////////////////////////////////////////////////////////////////////// -// Definitions for the Roman calendar -// TODO The 5.5.1 gedcom spec mentions this calendar, but gives no details of -// how it is to be represented.... This class is just a place holder so that -// webtrees won't compain if it receives one. -//////////////////////////////////////////////////////////////////////////////// -class RomanDate extends CalendarDate { - static function CALENDAR_ESCAPE() { - return '@#DROMAN@'; - } - - function FormatGedcomYear() { - return sprintf('%04dAUC',$this->y); - } - - function FormatLongYear() { - return $this->y.'AUC'; - } -} // class RomanDate - -//////////////////////////////////////////////////////////////////////////////// -// -// GedcomDate represents the date or date range from a gedcom DATE record. -// -//////////////////////////////////////////////////////////////////////////////// -class GedcomDate { - var $qual1=null; // Optional qualifier, such as BEF, FROM, ABT - var $date1=null; // The first (or only) date - var $qual2=null; // Optional qualifier, such as TO, AND - var $date2=null; // Optional second date - var $text =null; // Optional text, as included with an INTerpreted date - - function __construct($date) { - // Extract any explanatory text - if (preg_match('/^(.*) ?[(](.*)[)]/', $date, $match)) { - $date=$match[1]; - $this->text=$match[2]; - } - // Ignore punctuation and normalise whitespace - $date=preg_replace( - array('/(\d+|@#[^@]+@)/', '/[\s;:.,-]+/', '/^ /', '/ $/'), - array(' $1 ', ' ', '', ''), - strtolower($date) - ); - if (preg_match('/^(from|bet) (.+) (and|to) (.+)/', $date, $match)) { - $this->qual1=$match[1]; - $this->date1=$this->ParseDate($match[2]); - $this->qual2=$match[3]; - $this->date2=$this->ParseDate($match[4]); - } elseif (preg_match('/^(from|bet|to|and|bef|aft|cal|est|int|abt) (.+)/', $date, $match)) { - $this->qual1=$match[1]; - $this->date1=$this->ParseDate($match[2]); - } else { - $this->date1=$this->ParseDate($date); - } - } - - // Need to "deep-clone" nested objects - function __clone() { - $this->date1=clone $this->date1; - if (is_object($this->date2)) { - $this->date2=clone $this->date2; - } - } - - // Convert an individual gedcom date string into a CalendarDate object - static function ParseDate($date) { - // Valid calendar escape specified? - use it - if (preg_match('/^(@#d(?:gregorian|julian|hebrew|hijri|french r|roman)+@) ?(.*)/', $date, $match)) { - $cal=$match[1]; - $date=$match[2]; - } else { - $cal=''; - } - // A date with a month: DM, M, MY or DMY - if (preg_match('/^(\d?\d?) ?(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec|tsh|csh|ksl|tvt|shv|adr|ads|nsn|iyr|svn|tmz|aav|ell|vend|brum|frim|nivo|pluv|vent|germ|flor|prai|mess|ther|fruc|comp|muhar|safar|rabi[at]|juma[at]|rajab|shaab|ramad|shaww|dhuaq|dhuah) ?((?:\d+(?: b ?c)?|\d\d\d\d \/ \d{1,4})?)$/', $date, $match)) { - $d=$match[1]; - $m=$match[2]; - $y=$match[3]; - } else - // A date with just a year - if (preg_match('/^(\d+(?: b ?c)?|\d\d\d\d \/ \d{1,4})$/', $date, $match)) { - $d=''; - $m=''; - $y=$match[1]; - } else { - // An invalid date - do the best we can. - $d=''; - $m=''; - $y=''; - // Look for a 3/4 digit year anywhere in the date - if (preg_match('/\b(\d{3,4})\b/', $date, $match)) { - $y=$match[1]; - } - // Look for a month anywhere in the date - if (preg_match('/(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec|tsh|csh|ksl|tvt|shv|adr|ads|nsn|iyr|svn|tmz|aav|ell|vend|brum|frim|nivo|pluv|vent|germ|flor|prai|mess|ther|fruc|comp|muhar|safar|rabi[at]|juma[at]|rajab|shaab|ramad|shaww|dhuaq|dhuah)/', $date, $match)) { - $m=$match[1]; - // Look for a day number anywhere in the date - if (preg_match('/\b(\d\d?)\b/', $date, $match)) - $d=$match[1]; - } - } - // Unambiguous dates - override calendar escape - if (preg_match('/^(tsh|csh|ksl|tvt|shv|adr|ads|nsn|iyr|svn|tmz|aav|ell)$/', $m)) { - $cal='@#dhebrew@'; - } else { - if (preg_match('/^(vend|brum|frim|nivo|pluv|vent|germ|flor|prai|mess|ther|fruc|comp)$/', $m)) { - $cal='@#dfrench r@'; - } else { - if (preg_match('/^(muhar|safar|rabi[at]|juma[at]|rajab|shaab|ramad|shaww|dhuaq|dhuah)$/', $m)) { - $cal='@#dhijri@'; // This is a WT extension - } elseif (preg_match('/^\d+( b ?c)|\d\d\d\d \/ \d{1,4}$/', $y)) { - $cal='@#djulian@'; - } - } - } - // Ambiguous dates - don't override calendar escape - if ($cal=='') { - if (preg_match('/^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)$/', $m)) { - $cal='@#dgregorian@'; - } else { - if (preg_match('/^[345]\d\d\d$/', $y)) { // Year 3000-5999 - $cal='@#dhebrew@'; - } else { - $cal='@#dgregorian@'; - } - } - } - // Now construct an object of the correct type - switch ($cal) { - case '@#dgregorian@': - return new GregorianDate(array($y, $m, $d)); - case '@#djulian@': - return new JulianDate(array($y, $m, $d)); - case '@#dhebrew@': - if (WT_LOCALE=='he') - return new HebrewDate(array($y, $m, $d)); - else - return new JewishDate(array($y, $m, $d)); - case '@#dhijri@': - if (WT_LOCALE=='ar') - return new ArabicDate(array($y, $m, $d)); - else - return new HijriDate(array($y, $m, $d)); - case '@#dfrench r@': - return new FrenchRDate(array($y, $m, $d)); - case '@#droman@': - return new RomanDate(array($y, $m, $d)); - } - } - - // Convert a date to the prefered format and calendar(s) display. - // Optionally make the date a URL to the calendar. - function Display($url=false, $date_fmt=null, $cal_fmts=null) { - global $TEXT_DIRECTION, $DATE_FORMAT, $CALENDAR_FORMAT; - - // Convert dates to given calendars and given formats - if (!$date_fmt) { - $date_fmt=$DATE_FORMAT; - } - if (is_null($cal_fmts)) - $cal_fmts=explode('_and_', $CALENDAR_FORMAT); - - // Allow special processing for different languages - $func="date_localisation_".WT_LOCALE; - if (!function_exists($func)) - $func="DefaultDateLocalisation"; - - // Two dates with text before, between and after - $q1=$this->qual1; - $d1=$this->date1->Format($date_fmt, $this->qual1); - $q2=$this->qual2; - if (is_null($this->date2)) - $d2=''; - else - $d2=$this->date2->Format($date_fmt, $this->qual2); - $q3=''; - $func($q1, $d1, $q2, $d2, $q3); - // Convert to other calendars, if requested - $conv1=''; - $conv2=''; - foreach ($cal_fmts as $cal_fmt) - if ($cal_fmt!='none') { - $d1conv=$this->date1->convert_to_cal($cal_fmt); - if ($d1conv->InValidRange()) { - $d1tmp=$d1conv->Format($date_fmt, $this->qual1); - } else { - $d1tmp=''; - } - $q1tmp=$this->qual1; - if (is_null($this->date2)) { - $d2conv=null; - $d2tmp=''; - } else { - $d2conv=$this->date2->convert_to_cal($cal_fmt); - if ($d2conv->InValidRange()) { - $d2tmp=$d2conv->Format($date_fmt, $this->qual2); - } else { - $d2tmp=''; - } - } - $q2tmp=$this->qual2; - $q3tmp=''; - // Localise the date - $func($q1tmp, $d1tmp, $q2tmp, $d2tmp, $q3tmp); - // If the date is different to the unconverted date, add it to the date string. - if ($d1!=$d1tmp && $d1tmp!='') { - if ($url) { - if ($CALENDAR_FORMAT!="none") { - $conv1.=' <span dir="'.$TEXT_DIRECTION.'">(<a href="'.$d1conv->CalendarURL($date_fmt).'">'.$d1tmp.'</a>)</span>'; - } else { - $conv1.=' <span dir="'.$TEXT_DIRECTION.'"><br /><a href="'.$d1conv->CalendarURL($date_fmt).'">'.$d1tmp.'</a></span>'; - } - } else { - $conv1.=' <span dir="'.$TEXT_DIRECTION.'">('.$d1tmp.')</span>'; - } - } - if (!is_null($this->date2) && $d2!=$d2tmp && $d1tmp!='') { - if ($url) { - $conv2.=' <span dir="'.$TEXT_DIRECTION.'">(<a href="'.$d2conv->CalendarURL($date_fmt).'">'.$d2tmp.'</a>)</span>'; - } else { - $conv2.=' <span dir="'.$TEXT_DIRECTION.'">('.$d2tmp.')</span>'; - } - } - } - - // Add URLs, if requested - if ($url) { - $d1='<a href="'.$this->date1->CalendarURL($date_fmt).'">'.$d1.'</a>'; - if (!is_null($this->date2)) - $d2='<a href="'.$this->date2->CalendarURL($date_fmt).'">'.$d2.'</a>'; - } - - // Localise the date - // TODO, use separate translations for nominative, genitive, etc. - switch ($q1.$q2) { - case '': $tmp=$d1.$conv1; break; - case 'abt': /* I18N: Gedcom ABT dates */ $tmp=i18n::translate('about %s', $d1.$conv1); break; - case 'cal': /* I18N: Gedcom CAL dates */ $tmp=i18n::translate('calculated %s', $d1.$conv1); break; - case 'est': /* I18N: Gedcom EST dates */ $tmp=i18n::translate('estimated %s', $d1.$conv1); break; - case 'int': /* I18N: Gedcom INT dates */ $tmp=i18n::translate('interpreted %s (%s)', $d1.$conv1, $this->text); break; - case 'bef': /* I18N: Gedcom BEF dates */ $tmp=i18n::translate('before %s', $d1.$conv1); break; - case 'aft': /* I18N: Gedcom AFT dates */ $tmp=i18n::translate('after %s', $d1.$conv1); break; - case 'from': /* I18N: Gedcom FROM dates */ $tmp=i18n::translate('from %s', $d1.$conv1); break; - case 'to': /* I18N: Gedcom TO dates */ $tmp=i18n::translate('to %s', $d1.$conv1); break; - case 'betand': /* I18N: Gedcom BET-AND dates */ $tmp=i18n::translate('between %s and %s', $d1.$conv1, $d2.$conv2); break; - case 'fromto': /* I18N: Gedcom FROM-TO dates */ $tmp=i18n::translate('from %s to %s', $d1.$conv1, $d2.$conv2); break; - default: $tmp=i18n::translate('Invalid date'); break; // e.g. BET without AND - } - - // Return at least one printable character, for better formatting in tables. - if (strip_tags($tmp)=='') - return ' '; - else - return "<span class=\"date\">{$tmp}</span>"; - } - - // Get the earliest/latest date/JD from this date - function MinDate() { - return $this->date1; - } - function MaxDate() { - if (is_null($this->date2)) - return $this->date1; - else - return $this->date2; - } - function MinJD() { - $tmp=$this->MinDate(); - return $tmp->minJD; - } - function MaxJD() { - $tmp=$this->MaxDate(); - return $tmp->maxJD; - } - function JD() { - return floor(($this->MinJD()+$this->MaxJD())/2); - } - - // Offset this date by N years, and round to the whole year - function AddYears($n, $qual='') { - $tmp=clone $this; - $tmp->date1->y+=$n; - $tmp->date1->m=0; - $tmp->date1->d=0; - $tmp->date1->SetJDfromYMD(); - $tmp->qual1=$qual; - $tmp->qual2=''; - $tmp->date2=null; - return $tmp; - } - - // Calculate the number of full years between two events. - // Return the result as either a number of years (for indi lists, etc.) - static function GetAgeYears($d1, $d2=null, $warn_on_negative=true) { - if (!is_object($d1)) return; - if (!is_object($d2)) - return $d1->date1->GetAge(false, WT_CLIENT_JD, $warn_on_negative ); - else - return $d1->date1->GetAge(false, $d2->MinJD(), $warn_on_negative); - } - - // Calculate the years/months/days between two events - // Return a gedcom style age string: "1y 2m 3d" (for fact details) - static function GetAgeGedcom($d1, $d2=null, $warn_on_negative=true) { - if (is_null($d2)) { - return $d1->date1->GetAge(true, WT_CLIENT_JD, $warn_on_negative); - } else { - // If dates overlap, then can't calculate age. - if (GedcomDate::Compare($d1, $d2)) { - return $d1->date1->GetAge(true, $d2->MinJD(), $warn_on_negative); - } if (GedcomDate::Compare($d1, $d2)==0 && $d1->date1->minJD==$d2->MinJD()) { - return '0d'; - } else { - return ''; - } - } - } - - // Static function to compare two dates. - // return <0 if $a<$b - // return >0 if $b>$a - // return 0 if dates same/overlap - // BEF/AFT sort as the day before/after. - static function Compare($a, $b) { - // Get min/max JD for each date. - switch ($a->qual1) { - case 'bef': - $amin=$a->MinJD()-1; - $amax=$amin; - break; - case 'aft': - $amax=$a->MaxJD()+1; - $amin=$amax; - break; - default: - $amin=$a->MinJD(); - $amax=$a->MaxJD(); - break; - } - switch ($b->qual1) { - case 'bef': - $bmin=$b->MinJD()-1; - $bmax=$bmin; - break; - case 'aft': - $bmax=$b->MaxJD()+1; - $bmin=$bmax; - break; - default: - $bmin=$b->MinJD(); - $bmax=$b->MaxJD(); - break; - } - if ($amax<$bmin) { - return -1; - } else { - if ($amin>$bmax && $bmax>0) { - return 1; - } else { - if ($amin<$bmin && $amax<=$bmax) { - return -1; - } elseif ($amin>$bmin && $amax>=$bmax && $bmax>0) { - return 1; - } else { - return 0; - } - } - } - } - - // Check whether a gedcom date contains usable calendar date(s). - function isOK() { - return $this->MinJD() && $this->MaxJD(); - } - - // Calculate the gregorian year for a date. This should NOT be used internally - // within WT - we should keep the code "calendar neutral" to allow support for - // jewish/arabic users. This is only for interfacing with external entities, - // such as the ancestry.com search interface or the dated fact icons. - function gregorianYear() { - if ($this->isOK()) { - list($y)=GregorianDate::JDtoYMD($this->JD()); - return $y; - } else { - return 0; - } - } -} - -// Localise a date. This is a default function, and may be overridden in extras.xx.php -function DefaultDateLocalisation(&$q1, &$d1, &$q2, &$d2, &$q3) { -} diff --git a/includes/classes/class_event.php b/includes/classes/class_event.php index 9d178ada8a..76695066dd 100644 --- a/includes/classes/class_event.php +++ b/includes/classes/class_event.php @@ -35,8 +35,6 @@ if (!defined('WT_WEBTREES')) { define('WT_CLASS_EVENT_PHP', ''); -require_once WT_ROOT.'includes/classes/class_date.php'; - /** * Event * @@ -180,11 +178,11 @@ class Event { /** * Get the date object for this event * - * @return GedcomDate + * @return WT_Date */ function getDate($estimate = true) { if (is_null($this->date)) - $this->date=new GedcomDate($this->getValue('DATE')); + $this->date=new WT_Date($this->getValue('DATE')); if (!$estimate && $this->dest) return null; return $this->date; @@ -193,7 +191,7 @@ class Event { /** * Set the date of this event. This method should only be used to force a date. * - * @param GedcomDate $date + * @param WT_Date $date */ function setDate(&$date) { $this->date = $date; @@ -312,7 +310,7 @@ class Event { if ($date->date1->y==0 && is_object($this->parentObject) && $this->parentObject->getType()=='INDI') $date=$this->parentObject->getEstimatedBirthDate(); - $gdate=new GregorianDate($date->MinDate()); + $gdate=new WT_Date_Gregorian($date->MinDate()); $century=floor($gdate->y/100).'00'; $decade=floor($gdate->y/10).'0'; @@ -364,7 +362,7 @@ class Event { } elseif (is_null($bdate) && !is_null($b->sortDate)) { $ret = $a->sortOrder - $b->sortOrder; } else { - $ret = GedcomDate::Compare($adate, $bdate); + $ret = WT_Date::Compare($adate, $bdate); } if ($ret==0) { $ret = $a->sortOrder - $b->sortOrder; diff --git a/includes/classes/class_reportbase.php b/includes/classes/class_reportbase.php index c1ff61aef0..11f866d161 100644 --- a/includes/classes/class_reportbase.php +++ b/includes/classes/class_reportbase.php @@ -441,22 +441,11 @@ class ReportBase { // static callback functions to sort data static function CompareBirthDate($x, $y) { - return GedcomDate::Compare($x->getBirthDate(), $y->getBirthDate()); + return WT_Date::Compare($x->getBirthDate(), $y->getBirthDate()); } static function CompareDeathDate($x, $y) { - return GedcomDate::Compare($x->getDeathDate(), $y->getDeathDate()); + return WT_Date::Compare($x->getDeathDate(), $y->getDeathDate()); } - - /** - * @deprecated - * @todo Is this a deprecated function or a future feature? - * - function get_type() { - // remove this die line only if it's cousing problem - It confirms that it's not used - die("<strong>REPORT ERROR ReportBase::get_type: </strong> It is used"); - return "ReportBase"; - } -*/ } /** @@ -2466,7 +2455,7 @@ function varSHandler($attrs) { // Check if variable is set as a date and reformat the date if (isset($attrs["date"])) { if ($attrs["date"] === "1") { - $g = new GedcomDate($var); + $g = new WT_Date($var); $var = $g->Display(); } } @@ -2896,11 +2885,11 @@ function AgeAtDeathSHandler() { if ($death_event) { $death_date=$death_event->getDate(); } else { - $death_date=new GedcomDate(''); + $death_date=new WT_Date(''); } $value = ''; - if (GedcomDate::Compare($birth_date, $death_date)<=0 || !$person->isDead()) { - $age=GedcomDate::GetAgeGedcom($birth_date, $death_date); + if (WT_Date::Compare($birth_date, $death_date)<=0 || !$person->isDead()) { + $age=WT_Date::GetAgeGedcom($birth_date, $death_date); // Only show calculated age if it differs from recorded age if ($age!='' && $age!="0d") { if ( @@ -3233,7 +3222,7 @@ function ListSHandler($attrs) { if (preg_match('/^(\w+):DATE (LTE|GTE) (.+)$/', $value, $match)) { $sql_join[]="JOIN `##dates` AS {$attr} ON ({$attr}.d_file={$sql_col_prefix}file AND {$attr}.d_gid={$sql_col_prefix}id)"; $sql_where[]="{$attr}.d_fact='{$match[1]}'"; - $date=new GedcomDate($match[3]); + $date=new WT_Date($match[3]); if ($match[2]=="LTE") { $sql_where[]="{$attr}.d_julianday2<=".$date->minJD(); } else { @@ -3437,18 +3426,18 @@ function ListSHandler($attrs) { switch ($expr) { case "GTE": if ($t=="DATE") { - $date1 = new GedcomDate($v); - $date2 = new GedcomDate($val); - $keep = (GedcomDate::Compare($date1, $date2)>=0); + $date1 = new WT_Date($v); + $date2 = new WT_Date($val); + $keep = (WT_Date::Compare($date1, $date2)>=0); } elseif ($val >= $v) { $keep=true; } break; case "LTE": if ($t=="DATE") { - $date1 = new GedcomDate($v); - $date2 = new GedcomDate($val); - $keep = (GedcomDate::Compare($date1, $date2)<=0); + $date1 = new WT_Date($v); + $date2 = new WT_Date($val); + $keep = (WT_Date::Compare($date1, $date2)<=0); } elseif ($val >= $v) { $keep=true; } diff --git a/includes/classes/class_stats.php b/includes/classes/class_stats.php index 6b5d854759..2c1f3080a6 100644 --- a/includes/classes/class_stats.php +++ b/includes/classes/class_stats.php @@ -271,7 +271,7 @@ class stats { $head=find_other_record('HEAD', $this->_ged_id); if (preg_match("/1 DATE (.+)/", $head, $match)) { - $date=new GedcomDate($match[1]); + $date=new WT_Date($match[1]); return $date->Display(false, $DATE_FORMAT); // Override $PUBLIC_DATE_FORMAT } return ''; @@ -283,7 +283,7 @@ class stats { ->execute(array($this->_ged_id, 'CHAN')) ->fetchOneRow(); if ($row) { - $date=new GedcomDate("{$row->d_day} {$row->d_month} {$row->d_year}"); + $date=new WT_Date("{$row->d_day} {$row->d_month} {$row->d_year}"); return $date->Display(false); } else { return self::gedcomDate(); @@ -947,7 +947,7 @@ class stats { } break; case 'year': - $date=new GedcomDate($row['d_type'].' '.$row['d_year']); + $date=new WT_Date($row['d_type'].' '.$row['d_year']); $result=$date->Display(true); break; case 'name': @@ -1905,7 +1905,7 @@ class stats { } break; case 'year': - $date=new GedcomDate($row['type'].' '.$row['year']); + $date=new WT_Date($row['type'].' '.$row['year']); $result=$date->Display(true); break; case 'type': diff --git a/includes/functions/functions.php b/includes/functions/functions.php index 9a0228a7cf..3d5eaf0cc6 100644 --- a/includes/functions/functions.php +++ b/includes/functions/functions.php @@ -656,7 +656,7 @@ function get_gedcom_value($tag, $level, $gedrec, $truncate='', $convert=true) { $value = trim($value); //-- if it is a date value then convert the date if ($convert && $t=="DATE") { - $g = new GedcomDate($value); + $g = new WT_Date($value); $value = $g->Display(); if (!empty($truncate)) { if (utf8_strlen($value)>$truncate) { @@ -1146,8 +1146,8 @@ function compare_facts_date($arec, $brec) { return 0; } - $adate = new GedcomDate($amatch[1]); - $bdate = new GedcomDate($bmatch[1]); + $adate = new WT_Date($amatch[1]); + $bdate = new WT_Date($bmatch[1]); // If either date can't be parsed, don't sort. if (!$adate->isOK() || !$bdate->isOK()) { if (preg_match('/2 _SORT (\d+)/', $arec, $match1) && preg_match('/2 _SORT (\d+)/', $brec, $match2)) { diff --git a/includes/functions/functions_date.php b/includes/functions/functions_date.php index 60f78fe6fa..e05f0c85c6 100644 --- a/includes/functions/functions_date.php +++ b/includes/functions/functions_date.php @@ -33,8 +33,6 @@ if (!defined('WT_WEBTREES')) { define('WT_FUNCTIONS_DATE_PHP', ''); -require_once WT_ROOT.'includes/classes/class_date.php'; - /** * translate gedcom age string * @@ -134,10 +132,10 @@ function timestamp_to_jd($time) { } //////////////////////////////////////////////////////////////////////////////// -// Convert a unix-style timestamp into a GedcomDate object +// Convert a unix-style timestamp into a WT_Date object //////////////////////////////////////////////////////////////////////////////// function timestamp_to_gedcom_date($time) { - return new GedcomDate(strtoupper(date('j M Y', $time))); + return new WT_Date(strtoupper(date('j M Y', $time))); } //////////////////////////////////////////////////////////////////////////////// diff --git a/includes/functions/functions_db.php b/includes/functions/functions_db.php index 1da558a98f..da4946032a 100644 --- a/includes/functions/functions_db.php +++ b/includes/functions/functions_db.php @@ -1252,8 +1252,8 @@ function search_indis_year_range($startyear, $endyear) { // TODO: We should use Julian-days, rather than gregorian years, // to allow // the lifespan chart, etc., to use other calendars. - $startjd=GregorianDate::YMDtoJD($startyear, 1, 1); - $endjd =GregorianDate::YMDtoJD($endyear+1, 1, 1)-1; + $startjd=WT_Date_Gregorian::YMDtoJD($startyear, 1, 1); + $endjd =WT_Date_Gregorian::YMDtoJD($endyear+1, 1, 1)-1; return search_indis_daterange($startjd, $endjd, ''); } @@ -1709,7 +1709,7 @@ function get_anniversary_events($jd, $facts='', $ged_id=WT_GED_ID) { } $found_facts=array(); - foreach (array(new GregorianDate($jd), new JulianDate($jd), new FrenchRDate($jd), new JewishDate($jd), new HijriDate($jd)) as $anniv) { + foreach (array(new WT_Date_Gregorian($jd), new WT_Date_Julian($jd), new WT_Date_French($jd), new WT_Date_Jewish($jd), new WT_Date_Hijri($jd)) as $anniv) { // Build a SQL where clause to match anniversaries in the appropriate calendar. $where="WHERE d_type='".$anniv->CALENDAR_ESCAPE()."'"; // SIMPLE CASES: @@ -1746,7 +1746,7 @@ function get_anniversary_events($jd, $facts='', $ged_id=WT_GED_ID) { // 1 KSL includes 30 CSH (if this year didn't have 30 CSH) // 29 KSL does not include 30 KSL (but would include an invalid 31 KSL if there were no 30 KSL) if ($anniv->d==1) { - $tmp=new JewishDate(array($anniv->y, 'csh', 1)); + $tmp=new WT_Date_Jewish(array($anniv->y, 'csh', 1)); if ($tmp->DaysInMonth()==29) { $where.=" AND (d_day<=1 AND d_mon=3 OR d_day=30 AND d_mon=2)"; } else { @@ -1764,7 +1764,7 @@ function get_anniversary_events($jd, $facts='', $ged_id=WT_GED_ID) { case 4: // 1 TVT includes 30 KSL (if this year didn't have 30 KSL) if ($anniv->d==1) { - $tmp=new JewishDate($anniv->y, 'ksl', 1); + $tmp=new WT_Date_Jewish($anniv->y, 'ksl', 1); if ($tmp->DaysInMonth()==29) { $where.=" AND (d_day<=1 AND d_mon=4 OR d_day=30 AND d_mon=3)"; } else { @@ -1854,7 +1854,7 @@ function get_anniversary_events($jd, $facts='', $ged_id=WT_GED_ID) { $ged_date_regex="/2 DATE.*(".($row['d_day']>0 ? "0?{$row['d_day']}\s*" : "").$row['d_month']."\s*".($row['d_year']!=0 ? $year_regex : "").")/i"; foreach (get_all_subrecords($row['gedrec'], $skipfacts, false, false) as $factrec) { if (preg_match("/(^1 {$row['d_fact']}|^1 (FACT|EVEN).*\n2 TYPE {$row['d_fact']})/s", $factrec) && preg_match($ged_date_regex, $factrec) && preg_match('/2 DATE (.+)/', $factrec, $match)) { - $date=new GedcomDate($match[1]); + $date=new WT_Date($match[1]); if (preg_match('/2 PLAC (.+)/', $factrec, $match)) { $plac=$match[1]; } else { @@ -1936,7 +1936,7 @@ function get_calendar_events($jd1, $jd2, $facts='', $ged_id=WT_GED_ID) { $ged_date_regex="/2 DATE.*(".($row[4]>0 ? "0?{$row[4]}\s*" : "").$row[5]."\s*".($row[6]!=0 ? $year_regex : "").")/i"; foreach (get_all_subrecords($row[1], $skipfacts, false, false) as $factrec) { if (preg_match("/(^1 {$row[7]}|^1 (FACT|EVEN).*\n2 TYPE {$row[7]})/s", $factrec) && preg_match($ged_date_regex, $factrec) && preg_match('/2 DATE (.+)/', $factrec, $match)) { - $date=new GedcomDate($match[1]); + $date=new WT_Date($match[1]); if (preg_match('/2 PLAC (.+)/', $factrec, $match)) { $plac=$match[1]; } else { diff --git a/includes/functions/functions_edit.php b/includes/functions/functions_edit.php index 1237035277..53c2edb893 100644 --- a/includes/functions/functions_edit.php +++ b/includes/functions/functions_edit.php @@ -1723,7 +1723,7 @@ function add_simple_tag($tag, $upperlevel='', $label='', $readOnly='', $noClose= // current value if ($TEXT_DIRECTION=="ltr") { if ($fact=="DATE") { - $date=new GedcomDate($value); + $date=new WT_Date($value); echo $date->Display(false); } if (($fact=="ASSO" || $fact=="SOUR" || $fact=="OBJE" || ($fact=="NOTE" && $islink)) && $value) { @@ -1737,7 +1737,7 @@ function add_simple_tag($tag, $upperlevel='', $label='', $readOnly='', $noClose= } } else { if ($fact=="DATE") { - $date=new GedcomDate($value); + $date=new WT_Date($value); echo getRLM(), $date->Display(false), getRLM(); } if (($fact=="ASSO" || $fact=="SOUR" || $fact=="OBJE" || ($fact=="NOTE" && $islink)) && $value) { diff --git a/includes/functions/functions_import.php b/includes/functions/functions_import.php index b54321581f..8e81175b73 100644 --- a/includes/functions/functions_import.php +++ b/includes/functions/functions_import.php @@ -838,7 +838,7 @@ function update_dates($xref, $ged_id, $gedrec) { if (($fact=='FACT' || $fact=='EVEN') && preg_match("/\n2 TYPE ([A-Z]{3,5})/", $match[0], $tmatch)) { $fact=$tmatch[1]; } - $date=new GedcomDate($match[2]); + $date=new WT_Date($match[2]); $sql_insert_date->execute(array($date->date1->d, $date->date1->Format('%O'), $date->date1->m, $date->date1->y, $date->date1->minJD, $date->date1->maxJD, $fact, $xref, $ged_id, $date->date1->CALENDAR_ESCAPE())); if ($date->date2) { $sql_insert_date->execute(array($date->date2->d, $date->date2->Format('%O'), $date->date2->m, $date->date2->y, $date->date2->minJD, $date->date2->maxJD, $fact, $xref, $ged_id, $date->date2->CALENDAR_ESCAPE())); diff --git a/includes/functions/functions_print.php b/includes/functions/functions_print.php index 75f463e44d..d44a69d50f 100644 --- a/includes/functions/functions_print.php +++ b/includes/functions/functions_print.php @@ -1454,7 +1454,7 @@ function format_parents_age($pid, $birth_date=null) { $family=current($families); // Allow for same-sex parents foreach (array($family->getHusband(), $family->getWife()) as $parent) { - if ($parent && $age=GedcomDate::GetAgeYears($parent->getBirthDate(), $birth_date)) { + if ($parent && $age=WT_Date::GetAgeYears($parent->getBirthDate(), $birth_date)) { $deatdate=$parent->getDeathDate(); $class=''; switch ($parent->getSex()) { @@ -1518,7 +1518,7 @@ function format_fact_date(&$eventObj, $anchor=false, $time=false) { // Calculated age if (preg_match('/2 DATE (.+)/', $factrec, $match)) { - $date=new GedcomDate($match[1]); + $date=new WT_Date($match[1]); $html.=' '.$date->Display($anchor && !$SEARCH_SPIDER); // time if ($time) { @@ -1547,12 +1547,12 @@ function format_fact_date(&$eventObj, $anchor=false, $time=false) { if ($death_event) { $death_date=$death_event->getDate(); } else { - $death_date=new GedcomDate(''); + $death_date=new WT_Date(''); } $ageText = ''; - if ((GedcomDate::Compare($date, $death_date)<=0 || !$person->isDead()) || $fact=='DEAT') { + if ((WT_Date::Compare($date, $death_date)<=0 || !$person->isDead()) || $fact=='DEAT') { // Before death, print age - $age=GedcomDate::GetAgeGedcom($birth_date, $date); + $age=WT_Date::GetAgeGedcom($birth_date, $date); // Only show calculated age if it differs from recorded age if ($age!='') { if ( @@ -1567,11 +1567,11 @@ function format_fact_date(&$eventObj, $anchor=false, $time=false) { } } } - if ($fact!='DEAT' && GedcomDate::Compare($date, $death_date)>=0) { + if ($fact!='DEAT' && WT_Date::Compare($date, $death_date)>=0) { // After death, print time since death - $age=get_age_at_event(GedcomDate::GetAgeGedcom($death_date, $date), true); + $age=get_age_at_event(WT_Date::GetAgeGedcom($death_date, $date), true); if ($age!='') { - if (GedcomDate::GetAgeGedcom($death_date, $date)=="0d") { + if (WT_Date::GetAgeGedcom($death_date, $date)=="0d") { $ageText = '('.i18n::translate('on the date of death').')'; } else { $ageText = '('.$age.' '.i18n::translate('after death').')'; @@ -1587,8 +1587,8 @@ function format_fact_date(&$eventObj, $anchor=false, $time=false) { $birth_date=$indi->getBirthDate(); $death_date=$indi->getDeathDate(); $ageText = ''; - if (GedcomDate::Compare($date, $death_date)<=0) { - $age=GedcomDate::GetAgeGedcom($birth_date, $date); + if (WT_Date::Compare($date, $death_date)<=0) { + $age=WT_Date::GetAgeGedcom($birth_date, $date); // Only show calculated age if it differs from recorded age if ($age!='' && $age>0) { if ( @@ -1728,7 +1728,7 @@ function format_fact_place(&$eventObj, $anchor=false, $sub=false, $lds=false) { if (preg_match('/2 STAT (.*)/', $factrec, $match)) { $html.='<br />'.i18n::translate('Status').': '.(array_key_exists($match[1], $STATUS_CODES) ? $STATUS_CODES[$match[1]] : $match[1]); if (preg_match('/3 DATE (.*)/', $factrec, $match)) { - $date=new GedcomDate($match[1]); + $date=new WT_Date($match[1]); $html.=', '.translate_fact('STAT:DATE').': '.$date->Display(false); } } @@ -1812,7 +1812,7 @@ function print_add_new_fact($id, $usedfacts, $type) { echo '<option value="clipboard_', $key, '">', $fact_type; // TODO use the event class to store/parse the clipboard events if (preg_match('/^2 DATE (.+)/m', $fact['factrec'], $match)) { - $tmp=new GedcomDate($match[1]); + $tmp=new WT_Date($match[1]); echo '; ', $tmp->minDate()->Format('%Y'); } if (preg_match('/^2 PLAC ([^,\n]+)/m', $fact['factrec'], $match)) { diff --git a/includes/functions/functions_print_facts.php b/includes/functions/functions_print_facts.php index de0c4c7443..73d215ca87 100644 --- a/includes/functions/functions_print_facts.php +++ b/includes/functions/functions_print_facts.php @@ -389,7 +389,7 @@ function print_fact(&$eventObj) { if (!empty($data_rec)) { for ($even_num=1; $even_rec=get_sub_record(2, "2 EVEN", $data_rec, $even_num); ++$even_num) { $tmp1=get_gedcom_value('EVEN', 2, $even_rec, $truncate='', $convert=false); - $tmp2=new GedcomDate(get_gedcom_value('DATE', 3, $even_rec, $truncate='', $convert=false)); + $tmp2=new WT_Date(get_gedcom_value('DATE', 3, $even_rec, $truncate='', $convert=false)); $tmp3=get_gedcom_value('PLAC', 3, $even_rec, $truncate='', $convert=false); $fact_string = ""; if ($even_num>1) @@ -425,7 +425,7 @@ function print_fact(&$eventObj) { } echo htmlspecialchars($match[$i][2]); $sub_rec = get_sub_record(2, "2 ".$factref, $factrec, 1); - $tmp=new GedcomDate(get_gedcom_value('DATE', 3, $sub_rec, $truncate='', $convert=false)); + $tmp=new WT_Date(get_gedcom_value('DATE', 3, $sub_rec, $truncate='', $convert=false)); if ($tmp->Display(true)!=" ") echo " - ".$tmp->Display(true); echo "<br />"; } @@ -664,7 +664,7 @@ function print_media_links($factrec, $level, $pid='') { } } if (preg_match('/2 DATE (.+)/', get_sub_record("FILE", 1, $row["m_gedrec"]), $match)) { - $media_date=new GedcomDate($match[1]); + $media_date=new WT_Date($match[1]); $md = $media_date->Display(true); echo "<br /><span class=\"label\">", translate_fact('DATE'), ": </span> ", $md; } @@ -978,7 +978,7 @@ function printSourceStructure($textSOUR) { if ($textSOUR['DATE'] || count($textSOUR['TEXT'])) { if ($textSOUR['DATE']) { - $date=new GedcomDate($textSOUR['DATE']); + $date=new WT_Date($textSOUR['DATE']); $html.='<div class="indent"><span class="label">'.translate_fact('DATA:DATE').':</span> <span class="field">'.$date->Display(false).'</span></div>'; } foreach ($textSOUR['TEXT'] as $text) { @@ -1491,7 +1491,7 @@ function print_main_media_row($rtype, $rowm, $pid) { } } if (preg_match('/2 DATE (.+)/', get_sub_record("FILE", 1, $rowm["m_gedrec"]), $match)) { - $media_date=new GedcomDate($match[1]); + $media_date=new WT_Date($match[1]); $md = $media_date->Display(true); echo "<br /><span class=\"label\">", translate_fact('DATE'), ": </span> ", $md; } diff --git a/includes/functions/functions_print_lists.php b/includes/functions/functions_print_lists.php index cc0311b3a4..e2feacbe4d 100644 --- a/includes/functions/functions_print_lists.php +++ b/includes/functions/functions_print_lists.php @@ -130,7 +130,7 @@ function print_indi_table($datalist, $legend="", $option="") { echo "<tbody>"; $hidden = 0; $n = 0; - $d100y=new GedcomDate(date('Y')-100); // 100 years ago + $d100y=new WT_Date(date('Y')-100); // 100 years ago $dateY = date("Y"); $unique_indis=array(); // Don't double-count indis with multiple names. foreach ($datalist as $key => $value) { @@ -234,13 +234,13 @@ function print_indi_table($datalist, $legend="", $option="") { } else { echo '<span class="date"><a name="', $birth_jd, '"/> </span>'; // span needed for alive-in-year filter } - $birth_dates[0]=new GedcomDate(''); + $birth_dates[0]=new WT_Date(''); } echo '</td>'; //-- Birth anniversary if ($tiny) { echo '<td class="list_value_wrap rela">'; - $bage =GedcomDate::GetAgeYears($birth_dates[0]); + $bage =WT_Date::GetAgeYears($birth_dates[0]); if (empty($bage)) { echo " "; } else { @@ -294,14 +294,14 @@ function print_indi_table($datalist, $legend="", $option="") { } else { echo '<span class="date"><a name="', $death_jd, '"> </span>'; // span needed for alive-in-year filter } - $death_dates[0]=new GedcomDate(''); + $death_dates[0]=new WT_Date(''); } echo "</td>"; //-- Death anniversary if ($tiny) { echo "<td class=\"list_value_wrap rela\">"; if ($death_dates[0]->isOK()) - echo "<span class=\"age\">", GedcomDate::GetAgeYears($death_dates[0]), "</span>"; + echo "<span class=\"age\">", WT_Date::GetAgeYears($death_dates[0]), "</span>"; else echo " "; echo '</td>'; @@ -309,7 +309,7 @@ function print_indi_table($datalist, $legend="", $option="") { //-- Age at death echo "<td class=\"list_value_wrap\">"; if ($birth_dates[0]->isOK() && $death_dates[0]->isOK()) { - $age = GedcomDate::GetAgeYears($birth_dates[0], $death_dates[0]); + $age = WT_Date::GetAgeYears($birth_dates[0], $death_dates[0]); $age_jd = $death_dates[0]->MinJD()-$birth_dates[0]->MinJD(); echo '<a name="', $age_jd, '" class="list_item age">', $age, '</a>'; if (!isset($unique_indis[$person->getXref()])) { @@ -346,7 +346,7 @@ function print_indi_table($datalist, $legend="", $option="") { echo "</td>"; //-- Filtering by birth date echo "<td style=\"display:none\">"; - if (!$person->canDisplayDetails() || GedcomDate::Compare($birth_dates[0], $d100y)>0) { + if (!$person->canDisplayDetails() || WT_Date::Compare($birth_dates[0], $d100y)>0) { echo "Y100"; } else { echo "YES"; @@ -355,7 +355,7 @@ function print_indi_table($datalist, $legend="", $option="") { //-- Filtering by death date echo "<td style=\"display:none\">"; if ($person->isDead()) { - if (GedcomDate::Compare($death_dates[0], $d100y)>0) { + if (WT_Date::Compare($death_dates[0], $d100y)>0) { echo "Y100"; } else { echo "YES"; @@ -500,7 +500,7 @@ function print_fam_table($datalist, $legend="", $option="") { echo "<tbody>"; $hidden = 0; $num = 0; - $d100y=new GedcomDate(date('Y')-100); // 100 years ago + $d100y=new WT_Date(date('Y')-100); // 100 years ago foreach ($datalist as $key => $value) { if (is_object($value)) { // Array of objects $family=$value; @@ -564,7 +564,7 @@ function print_fam_table($datalist, $legend="", $option="") { $birt_by_decade[floor($hdate->gregorianYear()/10)*10] .= $husb->getSex(); } if ($mdate->isOK()) { - $hage=GedcomDate::GetAgeYears($hdate, $mdate); + $hage=WT_Date::GetAgeYears($hdate, $mdate); $hage_jd = $mdate->MinJD()-$hdate->MinJD(); echo '<a name="', $hage_jd, '" class="list_item age">', $hage, '</a>'; $marr_by_age[max(0, min($max_age, $hage))] .= $husb->getSex(); @@ -610,7 +610,7 @@ function print_fam_table($datalist, $legend="", $option="") { $birt_by_decade[floor($wdate->gregorianYear()/10)*10] .= $wife->getSex(); } if ($mdate->isOK()) { - $wage=GedcomDate::GetAgeYears($wdate, $mdate); + $wage=WT_Date::GetAgeYears($wdate, $mdate); $wage_jd = $mdate->MinJD()-$wdate->MinJD(); echo '<a name="', $wage_jd, '" class="list_item age">', $wage, '</a>'; $marr_by_age[max(0, min($max_age, $wage))] .= $wife->getSex(); @@ -662,7 +662,7 @@ function print_fam_table($datalist, $legend="", $option="") { //-- Marriage anniversary if ($tiny) { echo "<td class=\"list_value_wrap rela\">"; - $mage=GedcomDate::GetAgeYears($mdate); + $mage=WT_Date::GetAgeYears($mdate); if (empty($mage)) echo " "; else echo "<span class=\"age\">", $mage, "</span>"; echo "</td>"; @@ -698,7 +698,7 @@ function print_fam_table($datalist, $legend="", $option="") { if (!$family->canDisplayDetails() || !$mdate->isOK()) { echo "U"; } else { - if (GedcomDate::Compare($mdate, $d100y)>0) { + if (WT_Date::Compare($mdate, $d100y)>0) { echo "Y100"; } else { echo "YES"; diff --git a/includes/functions/functions_privacy.php b/includes/functions/functions_privacy.php index 2fab5fbdc9..a1d05dfcd4 100644 --- a/includes/functions/functions_privacy.php +++ b/includes/functions/functions_privacy.php @@ -74,7 +74,7 @@ function is_dead($indirec, $gedcom_id) { // If any event occured more than $MAX_ALIVE_AGE years ago, then assume the person is dead preg_match_all('/\n2 DATE (.+)/', $indirec, $date_matches); foreach ($date_matches[1] as $date_match) { - $date=new GedcomDate($date_match); + $date=new WT_Date($date_match); if ($date->isOK() && $date->MaxJD() <= WT_SERVER_JD - 365*$MAX_ALIVE_AGE) { return true; } @@ -89,7 +89,7 @@ function is_dead($indirec, $gedcom_id) { if (!empty($parents['HUSB'])) { preg_match_all('/\n2 DATE (.+)/', find_person_record($parents['HUSB'], $gedcom_id), $date_matches); foreach ($date_matches[1] as $date_match) { - $date=new GedcomDate($date_match); + $date=new WT_Date($date_match); // Assume fathers are no more than 40 years older than their children if ($date->isOK() && $date->MaxJD() <= WT_SERVER_JD - 365*($MAX_ALIVE_AGE+40)) { return true; @@ -99,7 +99,7 @@ function is_dead($indirec, $gedcom_id) { if (!empty($parents['WIFE'])) { preg_match_all('/\n2 DATE (.+)/', find_person_record($parents['WIFE'], $gedcom_id), $date_matches); foreach ($date_matches[1] as $date_match) { - $date=new GedcomDate($date_match); + $date=new WT_Date($date_match); // Assume mothers are no more than 40 years older than their children if ($date->isOK() && $date->MaxJD() <= WT_SERVER_JD - 365*($MAX_ALIVE_AGE+40)) { return true; @@ -115,7 +115,7 @@ function is_dead($indirec, $gedcom_id) { // Check all marriage events preg_match_all('/\n1 (?:'.WT_EVENTS_MARR.')(?:\n[2-9].+)*\n2 DATE (.+)/', $indirec, $date_matches); foreach ($date_matches[1] as $date_match) { - $date=new GedcomDate($date_match); + $date=new WT_Date($date_match); // Assume marriage occurs after age of 10 if ($date->isOK() && $date->MaxJD() <= WT_SERVER_JD - 365*($MAX_ALIVE_AGE-10)) { return true; @@ -131,7 +131,7 @@ function is_dead($indirec, $gedcom_id) { } preg_match_all('/\n2 DATE (.+)/', find_person_record($spid, $gedcom_id), $date_matches); foreach ($date_matches[1] as $date_match) { - $date=new GedcomDate($date_match); + $date=new WT_Date($date_match); // Assume max age difference between spouses of 40 years if ($date->isOK() && $date->MaxJD() <= WT_SERVER_JD - 365*($MAX_ALIVE_AGE+40)) { return true; @@ -145,7 +145,7 @@ function is_dead($indirec, $gedcom_id) { preg_match_all('/\n2 DATE (.+)/', $childrec, $date_matches); // Assume children born after age of 15 foreach ($date_matches[1] as $date_match) { - $date=new GedcomDate($date_match); + $date=new WT_Date($date_match); if ($date->isOK() && $date->MaxJD() <= WT_SERVER_JD - 365*($MAX_ALIVE_AGE-15)) { return true; } @@ -159,7 +159,7 @@ function is_dead($indirec, $gedcom_id) { preg_match_all('/\n2 DATE (.+)/', $grandchildrec, $date_matches); // Assume grandchildren born after age of 30 foreach ($date_matches[1] as $date_match) { - $date=new GedcomDate($date_match); + $date=new WT_Date($date_match); if ($date->isOK() && $date->MaxJD() <= WT_SERVER_JD - 365*($MAX_ALIVE_AGE-30)) { return true; } @@ -278,7 +278,7 @@ function canDisplayRecord($ged_id, $gedrec) { if ($KEEP_ALIVE_YEARS_BIRTH) { preg_match_all('/\n1 (?:'.WT_EVENTS_BIRT.').*(?:\n[2-9].*)*(?:\n2 DATE (.+))/', $gedrec, $matches, PREG_SET_ORDER); foreach ($matches as $match) { - $date=new GedcomDate($match[1]); + $date=new WT_Date($match[1]); if ($date->isOK() && $date->gregorianYear()+$KEEP_ALIVE_YEARS_BIRTH > date('Y')) { $keep_alive=true; break; @@ -288,7 +288,7 @@ function canDisplayRecord($ged_id, $gedrec) { if ($KEEP_ALIVE_YEARS_DEATH) { preg_match_all('/\n1 (?:'.WT_EVENTS_DEAT.').*(?:\n[2-9].*)*(?:\n2 DATE (.+))/', $gedrec, $matches, PREG_SET_ORDER); foreach ($matches as $match) { - $date=new GedcomDate($match[1]); + $date=new WT_Date($match[1]); if ($date->isOK() && $date->gregorianYear()+$KEEP_ALIVE_YEARS_DEATH > date('Y')) { $keep_alive=true; break; diff --git a/individual.php b/individual.php index 7ec2696786..0252c08bd6 100644 --- a/individual.php +++ b/individual.php @@ -154,7 +154,7 @@ jQuery(document).ready(function() { // If alive display age if (!$controller->indi->isDead()) { $bdate=$controller->indi->getBirthDate(); - $age = GedcomDate::GetAgeGedcom($bdate); + $age = WT_Date::GetAgeGedcom($bdate); if ($age!="") $summary.= "<dl><dt class=\"label\">".i18n::translate('Age')."</dt><span class=\"field\">".get_age_at_event($age, true)."</span></dl>"; } $summary.=$controller->indi->format_first_major_fact(WT_EVENTS_DEAT, 2); diff --git a/library/WT/Controller/AdvancedSearch.php b/library/WT/Controller/AdvancedSearch.php index 926205bdc6..a652ca60d6 100644 --- a/library/WT/Controller/AdvancedSearch.php +++ b/library/WT/Controller/AdvancedSearch.php @@ -2,7 +2,7 @@ // Controller for the Advanced Search Page // // webtrees: Web based Family History software -// Copyright (C) 2010 webtrees development team. +// Copyright (C) 2011 webtrees development team. // // Derived from PhpGedView // Copyright (C) 2002 to 2009 PGV Development Team. All rights reserved. @@ -28,18 +28,12 @@ if (!defined('WT_WEBTREES')) { exit; } -define('WT_ADVANCED_SEARCH_PHP', ''); - class WT_Controller_AdvancedSearch extends WT_Controller_Search { - var $fields = array(); var $values = array(); var $plusminus = array(); var $errors = array(); - /** - * constructor - */ function __construct() { parent::__construct(); } @@ -270,7 +264,7 @@ class WT_Controller_AdvancedSearch extends WT_Controller_Search { $datesTable = true; } $sqlwhere .= " AND (d_fact='".$parts[0]."'"; - $date = new GedcomDate($value); + $date = new WT_Date($value); if ($date->isOK()) { $jd1 = $date->date1->minJD; if ($date->date2) $jd2 = $date->date2->maxJD; diff --git a/library/WT/Controller/Ancestry.php b/library/WT/Controller/Ancestry.php index 57559fe96a..263e0c7090 100644 --- a/library/WT/Controller/Ancestry.php +++ b/library/WT/Controller/Ancestry.php @@ -2,7 +2,7 @@ // Controller for the Ancestry Page // // webtrees: Web based Family History software -// Copyright (C) 2010 webtrees development team. +// Copyright (C) 2011 webtrees development team. // // Derived from PhpGedView // Copyright (C) 2002 to 2009 PGV Development Team. All rights reserved. @@ -28,8 +28,6 @@ if (!defined('WT_WEBTREES')) { exit; } -define('WT_ANCESTRY_CTRL_PHP', ''); - require_once WT_ROOT.'includes/functions/functions_charts.php'; class WT_Controller_Ancestry extends WT_Controller_Base { diff --git a/library/WT/Controller/Base.php b/library/WT/Controller/Base.php index 7039031426..9b3cbddc81 100644 --- a/library/WT/Controller/Base.php +++ b/library/WT/Controller/Base.php @@ -2,7 +2,7 @@ // Base controller for all controller classes // // webtrees: Web based Family History software -// Copyright (C) 2010 webtrees development team. +// Copyright (C) 2011 webtrees development team. // // Derived from PhpGedView // Copyright (C) 2002 to 2009 PGV Development Team. All rights reserved. @@ -28,8 +28,6 @@ if (!defined('WT_WEBTREES')) { exit; } -define('WT_BASECONTROL_PHP', ''); - class WT_Controller_Base { var $action =null; var $show_changes=null; diff --git a/library/WT/Controller/Descendancy.php b/library/WT/Controller/Descendancy.php index 76e091e724..a1c6bd8acf 100644 --- a/library/WT/Controller/Descendancy.php +++ b/library/WT/Controller/Descendancy.php @@ -2,7 +2,7 @@ // Controller for the Descendancy Page // // webtrees: Web based Family History software -// Copyright (C) 2010 webtrees development team. +// Copyright (C) 2011 webtrees development team. // // Derived from PhpGedView // Copyright (C) 2002 to 2009 PGV Development Team. All rights reserved. @@ -28,8 +28,6 @@ if (!defined('WT_WEBTREES')) { exit; } -define('WT_DESCENDANCY_PHP', ''); - require_once WT_ROOT.'includes/functions/functions_charts.php'; class WT_Controller_Descendancy extends WT_Controller_Base { diff --git a/library/WT/Controller/Family.php b/library/WT/Controller/Family.php index 5255148186..6a8d683742 100644 --- a/library/WT/Controller/Family.php +++ b/library/WT/Controller/Family.php @@ -2,7 +2,7 @@ // Controller for the Family Page // // webtrees: Web based Family History software -// Copyright (C) 2010 webtrees development team. +// Copyright (C) 2011 webtrees development team. // // Derived from PhpGedView // Copyright (C) 2002 to 2010 PGV Development Team. All rights reserved. @@ -28,8 +28,6 @@ if (!defined('WT_WEBTREES')) { exit; } -define('WT_FAMILY_CTRL_PHP', ''); - require_once WT_ROOT.'includes/functions/functions_print_facts.php'; require_once WT_ROOT.'includes/classes/class_menu.php'; require_once WT_ROOT.'includes/functions/functions_import.php'; diff --git a/library/WT/Controller/Hourglass.php b/library/WT/Controller/Hourglass.php index 99a4ff7158..f44a55ca03 100644 --- a/library/WT/Controller/Hourglass.php +++ b/library/WT/Controller/Hourglass.php @@ -2,7 +2,7 @@ // Controller for the Hourglass Page // // webtrees: Web based Family History software -// Copyright (C) 2010 webtrees development team. +// Copyright (C) 2011 webtrees development team. // // Derived from PhpGedView // Copyright (C) 2002 to 2009 PGV Development Team. All rights reserved. @@ -28,8 +28,6 @@ if (!defined('WT_WEBTREES')) { exit; } -define('WT_HOURGLASS_CTRL_PHP', ''); - require_once WT_ROOT.'includes/functions/functions_charts.php'; // -- array of GEDCOM elements that will be found but should not be displayed diff --git a/library/WT/Controller/Individual.php b/library/WT/Controller/Individual.php index b7f31d5e15..2fe4b3dc12 100644 --- a/library/WT/Controller/Individual.php +++ b/library/WT/Controller/Individual.php @@ -2,7 +2,7 @@ // Controller for the Individual Page // // webtrees: Web based Family History software -// Copyright (C) 2010 webtrees development team. +// Copyright (C) 2011 webtrees development team. // // Derived from PhpGedView // Copyright (C) 2002 to 2010 PGV Development Team. All rights reserved. @@ -28,8 +28,6 @@ if (!defined('WT_WEBTREES')) { exit; } -define('WT_INDIVIDUAL_CTRL_PHP', ''); - require_once WT_ROOT.'includes/functions/functions_print_facts.php'; require_once WT_ROOT.'includes/classes/class_menu.php'; require_once WT_ROOT.'includes/functions/functions_import.php'; diff --git a/library/WT/Controller/Lifespan.php b/library/WT/Controller/Lifespan.php index e8d278bc41..63aca4506b 100644 --- a/library/WT/Controller/Lifespan.php +++ b/library/WT/Controller/Lifespan.php @@ -2,7 +2,7 @@ // Controller for the timeline chart // // webtrees: Web based Family History software -// Copyright (C) 2010 webtrees development team. +// Copyright (C) 2011 webtrees development team. // // Derived from PhpGedView // Copyright (C) 2002 to 2010 PGV Development Team. All rights reserved. @@ -28,12 +28,10 @@ if (!defined('WT_WEBTREES')) { exit; } -define('WT_LIFESPAN_CTRL_PHP', ''); - require_once WT_ROOT.'includes/functions/functions_charts.php'; function compare_people($a, $b) { - return GedcomDate::Compare($a->getEstimatedBirthDate(), $b->getEstimatedBirthDate()); + return WT_Date::Compare($a->getEstimatedBirthDate(), $b->getEstimatedBirthDate()); } class WT_Controller_Lifespan extends WT_Controller_Base { diff --git a/library/WT/Controller/Media.php b/library/WT/Controller/Media.php index 990e797645..866189f52b 100644 --- a/library/WT/Controller/Media.php +++ b/library/WT/Controller/Media.php @@ -2,7 +2,7 @@ // Controller for the Media Menu // // webtrees: Web based Family History software -// Copyright (C) 2010 webtrees development team. +// Copyright (C) 2011 webtrees development team. // // Derived from PhpGedView // Copyright (C) 2002 to 2009 PGV Development Team. All rights reserved. @@ -28,8 +28,6 @@ if (!defined('WT_WEBTREES')) { exit; } -define('WT_MEDIA_CTRL_PHP', ''); - require_once WT_ROOT.'includes/functions/functions_print_facts.php'; require_once WT_ROOT.'includes/classes/class_menu.php'; require_once WT_ROOT.'includes/functions/functions_import.php'; diff --git a/library/WT/Controller/Note.php b/library/WT/Controller/Note.php index 0ee2f95a36..5047dd103e 100644 --- a/library/WT/Controller/Note.php +++ b/library/WT/Controller/Note.php @@ -2,7 +2,7 @@ // Controller for the Shared Note Page // // webtrees: Web based Family History software -// Copyright (C) 2010 webtrees development team. +// Copyright (C) 2011 webtrees development team. // // Derived from PhpGedView // Copyright (C) 2009 PGV Development Team. All rights reserved. @@ -28,8 +28,6 @@ if (!defined('WT_WEBTREES')) { exit; } -define('WT_NOTE_CTRL_PHP', ''); - require_once WT_ROOT.'includes/functions/functions_print_facts.php'; require_once WT_ROOT.'includes/classes/class_menu.php'; require_once WT_ROOT.'includes/functions/functions_import.php'; diff --git a/library/WT/Controller/Pedigree.php b/library/WT/Controller/Pedigree.php index 8f12fee31c..0ccae80ee1 100644 --- a/library/WT/Controller/Pedigree.php +++ b/library/WT/Controller/Pedigree.php @@ -1,6 +1,6 @@ <?php // webtrees: Web based Family History software -// Copyright (C) 2010 webtrees development team. +// Copyright (C) 2011 webtrees development team. // // Derived from PhpGedView // Copyright (C) 2002 to 2009 PGV Development Team. All rights reserved. @@ -26,8 +26,6 @@ if (!defined('WT_WEBTREES')) { exit; } -define('WT_PEDIGREE_CTRL_PHP', ''); - require_once WT_ROOT.'includes/functions/functions_charts.php'; class WT_Controller_Pedigree extends WT_Controller_Base { diff --git a/library/WT/Controller/Repository.php b/library/WT/Controller/Repository.php index d637360f80..ce9a453fa3 100644 --- a/library/WT/Controller/Repository.php +++ b/library/WT/Controller/Repository.php @@ -2,7 +2,7 @@ // Controller for the Repository Page // // webtrees: Web based Family History software -// Copyright (C) 2010 webtrees development team. +// Copyright (C) 2011 webtrees development team. // // Derived from PhpGedView // Copyright (C) 2002 to 2010 PGV Development Team. All rights reserved. @@ -28,8 +28,6 @@ if (!defined('WT_WEBTREES')) { exit; } -define('WT_REPOSITORY_CTRL_PHP', ''); - require_once WT_ROOT.'includes/functions/functions_print_facts.php'; require_once WT_ROOT.'includes/classes/class_menu.php'; require_once WT_ROOT.'includes/functions/functions_import.php'; diff --git a/library/WT/Controller/Search.php b/library/WT/Controller/Search.php index 40187915d9..191406aebc 100644 --- a/library/WT/Controller/Search.php +++ b/library/WT/Controller/Search.php @@ -2,7 +2,7 @@ // Controller for the Search Page // // webtrees: Web based Family History software -// Copyright (C) 2010 webtrees development team. +// Copyright (C) 2011 webtrees development team. // // Derived from PhpGedView // Copyright (C) 2002 to 2009 PGV Development Team. All rights reserved. @@ -29,8 +29,6 @@ if (!defined('WT_WEBTREES')) { exit; } -define('WT_SEARCH_CTRL_PHP', ''); - class WT_Controller_Search extends WT_Controller_Base { var $isPostBack = false; var $topsearch; diff --git a/library/WT/Controller/Source.php b/library/WT/Controller/Source.php index 1b0fcffa3b..8dc6b2b26b 100644 --- a/library/WT/Controller/Source.php +++ b/library/WT/Controller/Source.php @@ -2,7 +2,7 @@ // Controller for the Source Page // // webtrees: Web based Family History software -// Copyright (C) 2010 webtrees development team. +// Copyright (C) 2011 webtrees development team. // // Derived from PhpGedView // Copyright (C) 2002 to 2010 PGV Development Team. All rights reserved. @@ -28,8 +28,6 @@ if (!defined('WT_WEBTREES')) { exit; } -define('WT_SOURCE_CTRL_PHP', ''); - require_once WT_ROOT.'includes/functions/functions_print_facts.php'; require_once WT_ROOT.'includes/classes/class_menu.php'; require_once WT_ROOT.'includes/functions/functions_import.php'; diff --git a/library/WT/Controller/Timeline.php b/library/WT/Controller/Timeline.php index d3a0151fcd..883e40c4ad 100644 --- a/library/WT/Controller/Timeline.php +++ b/library/WT/Controller/Timeline.php @@ -2,7 +2,7 @@ // Controller for the timeline chart // // webtrees: Web based Family History software -// Copyright (C) 2010 webtrees development team. +// Copyright (C) 2011 webtrees development team. // // Derived from PhpGedView // Copyright (C) 2002 to 2009 PGV Development Team. All rights reserved. @@ -28,8 +28,6 @@ if (!defined('WT_WEBTREES')) { exit; } -define('WT_TIMELINE_CTRL_PHP', ''); - require_once WT_ROOT.'includes/functions/functions_charts.php'; class WT_Controller_Timeline extends WT_Controller_Base { @@ -232,13 +230,13 @@ class WT_Controller_Timeline extends WT_Controller_Base { $husb=$family->getHusband(); if (is_null($husb)) $husb = new WT_Person(''); $hdate=$husb->getBirthDate(); - if ($hdate->isOK()) $ageh=get_age_at_event(GedcomDate::GetAgeGedcom($hdate, $gdate), false); + if ($hdate->isOK()) $ageh=get_age_at_event(WT_Date::GetAgeGedcom($hdate, $gdate), false); } else if ($this->pids[$p]==$wifeid) { $wife=$family->getWife(); if (is_null($wife)) $wife = new WT_Person(''); $wdate=$wife->getBirthDate(); - if ($wdate->isOK()) $agew=get_age_at_event(GedcomDate::GetAgeGedcom($wdate, $gdate), false); + if ($wdate->isOK()) $agew=get_age_at_event(WT_Date::GetAgeGedcom($wdate, $gdate), false); } } if (!empty($ageh) && $ageh > 0) { diff --git a/library/WT/DB.php b/library/WT/DB.php index 489413d041..d467822bf7 100644 --- a/library/WT/DB.php +++ b/library/WT/DB.php @@ -4,7 +4,7 @@ // PDOStatement classes to provide database access with logging, etc. // // webtrees: Web based Family History software -// Copyright (C) 2010 webtrees development team. +// Copyright (C) 2011 webtrees development team. // // Derived from PhpGedView // Copyright (c) 2009-2010 Greg Roach @@ -23,7 +23,6 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// @package webtrees // @version $Id$ if (!defined('WT_WEBTREES')) { @@ -31,8 +30,6 @@ if (!defined('WT_WEBTREES')) { exit; } -define('WT_WT_DB_PHP', ''); - class WT_DB { ////////////////////////////////////////////////////////////////////////////// // CONSTRUCTION diff --git a/library/WT/DBStatement.php b/library/WT/DBStatement.php index 8263d8a38a..d948388fcc 100644 --- a/library/WT/DBStatement.php +++ b/library/WT/DBStatement.php @@ -1,13 +1,9 @@ <?php -// // Class file for the database access. Extend PHP's native PDO and // PDOStatement classes to provide database access with logging, etc. // // webtrees: Web based Family History software -// Copyright (C) 2010 webtrees development team. -// -// Derived from PhpGedView -// Copyright (c) 2009-2010 Greg Roach +// Copyright (C) 2011 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 @@ -23,7 +19,7 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// @package webtrees +// @author Greg Roach // @version $Id$ if (!defined('WT_WEBTREES')) { @@ -31,8 +27,6 @@ if (!defined('WT_WEBTREES')) { exit; } -define('WT_WT_DB_STATEMENT_PHP', ''); - class WT_DBStatement { ////////////////////////////////////////////////////////////////////////////// // CONSTRUCTION diff --git a/library/WT/Date.php b/library/WT/Date.php new file mode 100644 index 0000000000..cc494e52ee --- /dev/null +++ b/library/WT/Date.php @@ -0,0 +1,394 @@ +<?php +// Classes for Gedcom Date/Calendar functionality. +// +// WT_Date represents the date or date range from a gedcom DATE record. +// +// NOTE: Since different calendars start their days at different times, (civil +// midnight, solar midnight, sunset, sunrise, etc.), we convert on the basis of +// midday. +// +// NOTE: We assume that years start on the first day of the first month. Where +// this is not the case (e.g. England prior to 1752), we need to use modified +// years or the OS/NS notation "4 FEB 1750/51". +// +// NOTE: WT should only be using the WT_Date class. The other classes +// are all for internal use only. +// +// webtrees: Web based Family History software +// Copyright (C) 2011 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 +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// @author Greg Roach +// @version $Id$ + +if (!defined('WT_WEBTREES')) { + header('HTTP/1.0 403 Forbidden'); + exit; +} + +class WT_Date { + var $qual1=null; // Optional qualifier, such as BEF, FROM, ABT + var $date1=null; // The first (or only) date + var $qual2=null; // Optional qualifier, such as TO, AND + var $date2=null; // Optional second date + var $text =null; // Optional text, as included with an INTerpreted date + + function __construct($date) { + // Extract any explanatory text + if (preg_match('/^(.*) ?[(](.*)[)]/', $date, $match)) { + $date=$match[1]; + $this->text=$match[2]; + } + // Ignore punctuation and normalise whitespace + $date=preg_replace( + array('/(\d+|@#[^@]+@)/', '/[\s;:.,-]+/', '/^ /', '/ $/'), + array(' $1 ', ' ', '', ''), + strtolower($date) + ); + if (preg_match('/^(from|bet) (.+) (and|to) (.+)/', $date, $match)) { + $this->qual1=$match[1]; + $this->date1=$this->ParseDate($match[2]); + $this->qual2=$match[3]; + $this->date2=$this->ParseDate($match[4]); + } elseif (preg_match('/^(from|bet|to|and|bef|aft|cal|est|int|abt) (.+)/', $date, $match)) { + $this->qual1=$match[1]; + $this->date1=$this->ParseDate($match[2]); + } else { + $this->date1=$this->ParseDate($date); + } + } + + // Need to "deep-clone" nested objects + function __clone() { + $this->date1=clone $this->date1; + if (is_object($this->date2)) { + $this->date2=clone $this->date2; + } + } + + // Convert an individual gedcom date string into a WT_Date_Calendar object + static function ParseDate($date) { + // Valid calendar escape specified? - use it + if (preg_match('/^(@#d(?:gregorian|julian|hebrew|hijri|french r|roman)+@) ?(.*)/', $date, $match)) { + $cal=$match[1]; + $date=$match[2]; + } else { + $cal=''; + } + // A date with a month: DM, M, MY or DMY + if (preg_match('/^(\d?\d?) ?(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec|tsh|csh|ksl|tvt|shv|adr|ads|nsn|iyr|svn|tmz|aav|ell|vend|brum|frim|nivo|pluv|vent|germ|flor|prai|mess|ther|fruc|comp|muhar|safar|rabi[at]|juma[at]|rajab|shaab|ramad|shaww|dhuaq|dhuah) ?((?:\d+(?: b ?c)?|\d\d\d\d \/ \d{1,4})?)$/', $date, $match)) { + $d=$match[1]; + $m=$match[2]; + $y=$match[3]; + } else + // A date with just a year + if (preg_match('/^(\d+(?: b ?c)?|\d\d\d\d \/ \d{1,4})$/', $date, $match)) { + $d=''; + $m=''; + $y=$match[1]; + } else { + // An invalid date - do the best we can. + $d=''; + $m=''; + $y=''; + // Look for a 3/4 digit year anywhere in the date + if (preg_match('/\b(\d{3,4})\b/', $date, $match)) { + $y=$match[1]; + } + // Look for a month anywhere in the date + if (preg_match('/(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec|tsh|csh|ksl|tvt|shv|adr|ads|nsn|iyr|svn|tmz|aav|ell|vend|brum|frim|nivo|pluv|vent|germ|flor|prai|mess|ther|fruc|comp|muhar|safar|rabi[at]|juma[at]|rajab|shaab|ramad|shaww|dhuaq|dhuah)/', $date, $match)) { + $m=$match[1]; + // Look for a day number anywhere in the date + if (preg_match('/\b(\d\d?)\b/', $date, $match)) + $d=$match[1]; + } + } + // Unambiguous dates - override calendar escape + if (preg_match('/^(tsh|csh|ksl|tvt|shv|adr|ads|nsn|iyr|svn|tmz|aav|ell)$/', $m)) { + $cal='@#dhebrew@'; + } else { + if (preg_match('/^(vend|brum|frim|nivo|pluv|vent|germ|flor|prai|mess|ther|fruc|comp)$/', $m)) { + $cal='@#dfrench r@'; + } else { + if (preg_match('/^(muhar|safar|rabi[at]|juma[at]|rajab|shaab|ramad|shaww|dhuaq|dhuah)$/', $m)) { + $cal='@#dhijri@'; // This is a WT extension + } elseif (preg_match('/^\d+( b ?c)|\d\d\d\d \/ \d{1,4}$/', $y)) { + $cal='@#djulian@'; + } + } + } + // Ambiguous dates - don't override calendar escape + if ($cal=='') { + if (preg_match('/^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)$/', $m)) { + $cal='@#dgregorian@'; + } else { + if (preg_match('/^[345]\d\d\d$/', $y)) { // Year 3000-5999 + $cal='@#dhebrew@'; + } else { + $cal='@#dgregorian@'; + } + } + } + // Now construct an object of the correct type + switch ($cal) { + case '@#dgregorian@': + return new WT_Date_Gregorian(array($y, $m, $d)); + case '@#djulian@': + return new WT_Date_Julian(array($y, $m, $d)); + case '@#dhebrew@': + if (WT_LOCALE=='he') + return new WT_Date_Hebrew(array($y, $m, $d)); + else + return new WT_Date_Jewish(array($y, $m, $d)); + case '@#dhijri@': + if (WT_LOCALE=='ar') + return new WT_Date_Arabic(array($y, $m, $d)); + else + return new WT_Date_Hijri(array($y, $m, $d)); + case '@#dfrench r@': + return new WT_Date_French(array($y, $m, $d)); + case '@#droman@': + return new WT_Date_Roman(array($y, $m, $d)); + } + } + + // Convert a date to the prefered format and calendar(s) display. + // Optionally make the date a URL to the calendar. + function Display($url=false, $date_fmt=null, $cal_fmts=null) { + global $TEXT_DIRECTION, $DATE_FORMAT, $CALENDAR_FORMAT; + + // Convert dates to given calendars and given formats + if (!$date_fmt) { + $date_fmt=$DATE_FORMAT; + } + if (is_null($cal_fmts)) + $cal_fmts=explode('_and_', $CALENDAR_FORMAT); + + // Two dates with text before, between and after + $q1=$this->qual1; + $d1=$this->date1->Format($date_fmt, $this->qual1); + $q2=$this->qual2; + if (is_null($this->date2)) + $d2=''; + else + $d2=$this->date2->Format($date_fmt, $this->qual2); + // Convert to other calendars, if requested + $conv1=''; + $conv2=''; + foreach ($cal_fmts as $cal_fmt) + if ($cal_fmt!='none') { + $d1conv=$this->date1->convert_to_cal($cal_fmt); + if ($d1conv->InValidRange()) { + $d1tmp=$d1conv->Format($date_fmt, $this->qual1); + } else { + $d1tmp=''; + } + $q1tmp=$this->qual1; + if (is_null($this->date2)) { + $d2conv=null; + $d2tmp=''; + } else { + $d2conv=$this->date2->convert_to_cal($cal_fmt); + if ($d2conv->InValidRange()) { + $d2tmp=$d2conv->Format($date_fmt, $this->qual2); + } else { + $d2tmp=''; + } + } + $q2tmp=$this->qual2; + // If the date is different to the unconverted date, add it to the date string. + if ($d1!=$d1tmp && $d1tmp!='') { + if ($url) { + if ($CALENDAR_FORMAT!="none") { + $conv1.=' <span dir="'.$TEXT_DIRECTION.'">(<a href="'.$d1conv->CalendarURL($date_fmt).'">'.$d1tmp.'</a>)</span>'; + } else { + $conv1.=' <span dir="'.$TEXT_DIRECTION.'"><br /><a href="'.$d1conv->CalendarURL($date_fmt).'">'.$d1tmp.'</a></span>'; + } + } else { + $conv1.=' <span dir="'.$TEXT_DIRECTION.'">('.$d1tmp.')</span>'; + } + } + if (!is_null($this->date2) && $d2!=$d2tmp && $d1tmp!='') { + if ($url) { + $conv2.=' <span dir="'.$TEXT_DIRECTION.'">(<a href="'.$d2conv->CalendarURL($date_fmt).'">'.$d2tmp.'</a>)</span>'; + } else { + $conv2.=' <span dir="'.$TEXT_DIRECTION.'">('.$d2tmp.')</span>'; + } + } + } + + // Add URLs, if requested + if ($url) { + $d1='<a href="'.$this->date1->CalendarURL($date_fmt).'">'.$d1.'</a>'; + if (!is_null($this->date2)) + $d2='<a href="'.$this->date2->CalendarURL($date_fmt).'">'.$d2.'</a>'; + } + + // Localise the date + switch ($q1.$q2) { + case '': $tmp=$d1.$conv1; break; + case 'abt': /* I18N: Gedcom ABT dates */ $tmp=i18n::translate('about %s', $d1.$conv1); break; + case 'cal': /* I18N: Gedcom CAL dates */ $tmp=i18n::translate('calculated %s', $d1.$conv1); break; + case 'est': /* I18N: Gedcom EST dates */ $tmp=i18n::translate('estimated %s', $d1.$conv1); break; + case 'int': /* I18N: Gedcom INT dates */ $tmp=i18n::translate('interpreted %s (%s)', $d1.$conv1, $this->text); break; + case 'bef': /* I18N: Gedcom BEF dates */ $tmp=i18n::translate('before %s', $d1.$conv1); break; + case 'aft': /* I18N: Gedcom AFT dates */ $tmp=i18n::translate('after %s', $d1.$conv1); break; + case 'from': /* I18N: Gedcom FROM dates */ $tmp=i18n::translate('from %s', $d1.$conv1); break; + case 'to': /* I18N: Gedcom TO dates */ $tmp=i18n::translate('to %s', $d1.$conv1); break; + case 'betand': /* I18N: Gedcom BET-AND dates */ $tmp=i18n::translate('between %s and %s', $d1.$conv1, $d2.$conv2); break; + case 'fromto': /* I18N: Gedcom FROM-TO dates */ $tmp=i18n::translate('from %s to %s', $d1.$conv1, $d2.$conv2); break; + default: $tmp=i18n::translate('Invalid date'); break; // e.g. BET without AND + } + + // Return at least one printable character, for better formatting in tables. + if (strip_tags($tmp)=='') + return ' '; + else + return "<span class=\"date\">{$tmp}</span>"; + } + + // Get the earliest/latest date/JD from this date + function MinDate() { + return $this->date1; + } + function MaxDate() { + if (is_null($this->date2)) + return $this->date1; + else + return $this->date2; + } + function MinJD() { + $tmp=$this->MinDate(); + return $tmp->minJD; + } + function MaxJD() { + $tmp=$this->MaxDate(); + return $tmp->maxJD; + } + function JD() { + return floor(($this->MinJD()+$this->MaxJD())/2); + } + + // Offset this date by N years, and round to the whole year + function AddYears($n, $qual='') { + $tmp=clone $this; + $tmp->date1->y+=$n; + $tmp->date1->m=0; + $tmp->date1->d=0; + $tmp->date1->SetJDfromYMD(); + $tmp->qual1=$qual; + $tmp->qual2=''; + $tmp->date2=null; + return $tmp; + } + + // Calculate the number of full years between two events. + // Return the result as either a number of years (for indi lists, etc.) + static function GetAgeYears($d1, $d2=null, $warn_on_negative=true) { + if (!is_object($d1)) return; + if (!is_object($d2)) + return $d1->date1->GetAge(false, WT_CLIENT_JD, $warn_on_negative ); + else + return $d1->date1->GetAge(false, $d2->MinJD(), $warn_on_negative); + } + + // Calculate the years/months/days between two events + // Return a gedcom style age string: "1y 2m 3d" (for fact details) + static function GetAgeGedcom($d1, $d2=null, $warn_on_negative=true) { + if (is_null($d2)) { + return $d1->date1->GetAge(true, WT_CLIENT_JD, $warn_on_negative); + } else { + // If dates overlap, then can't calculate age. + if (WT_Date::Compare($d1, $d2)) { + return $d1->date1->GetAge(true, $d2->MinJD(), $warn_on_negative); + } if (WT_Date::Compare($d1, $d2)==0 && $d1->date1->minJD==$d2->MinJD()) { + return '0d'; + } else { + return ''; + } + } + } + + // Static function to compare two dates. + // return <0 if $a<$b + // return >0 if $b>$a + // return 0 if dates same/overlap + // BEF/AFT sort as the day before/after. + static function Compare($a, $b) { + // Get min/max JD for each date. + switch ($a->qual1) { + case 'bef': + $amin=$a->MinJD()-1; + $amax=$amin; + break; + case 'aft': + $amax=$a->MaxJD()+1; + $amin=$amax; + break; + default: + $amin=$a->MinJD(); + $amax=$a->MaxJD(); + break; + } + switch ($b->qual1) { + case 'bef': + $bmin=$b->MinJD()-1; + $bmax=$bmin; + break; + case 'aft': + $bmax=$b->MaxJD()+1; + $bmin=$bmax; + break; + default: + $bmin=$b->MinJD(); + $bmax=$b->MaxJD(); + break; + } + if ($amax<$bmin) { + return -1; + } else { + if ($amin>$bmax && $bmax>0) { + return 1; + } else { + if ($amin<$bmin && $amax<=$bmax) { + return -1; + } elseif ($amin>$bmin && $amax>=$bmax && $bmax>0) { + return 1; + } else { + return 0; + } + } + } + } + + // Check whether a gedcom date contains usable calendar date(s). + function isOK() { + return $this->MinJD() && $this->MaxJD(); + } + + // Calculate the gregorian year for a date. This should NOT be used internally + // within WT - we should keep the code "calendar neutral" to allow support for + // jewish/arabic users. This is only for interfacing with external entities, + // such as the ancestry.com search interface or the dated fact icons. + function gregorianYear() { + if ($this->isOK()) { + list($y)=WT_Date_Gregorian::JDtoYMD($this->JD()); + return $y; + } else { + return 0; + } + } +} diff --git a/library/WT/Date/Arabic.php b/library/WT/Date/Arabic.php new file mode 100644 index 0000000000..11739b2667 --- /dev/null +++ b/library/WT/Date/Arabic.php @@ -0,0 +1,84 @@ +<?php +// Classes for Gedcom Date/Calendar functionality. +// +// Definitions for the Arabic calendar. +// NOTE - this is the same as the Hijri Calendar, but displays dates in arabic +// rather than the local language. +// +// NOTE: Since different calendars start their days at different times, (civil +// midnight, solar midnight, sunset, sunrise, etc.), we convert on the basis of +// midday. +// +// webtrees: Web based Family History software +// Copyright (C) 2011 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 +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// @author Greg Roach +// @version $Id$ + +if (!defined('WT_WEBTREES')) { + header('HTTP/1.0 403 Forbidden'); + exit; +} + +class WT_Date_Arabic extends WT_Date_Hijri { + static $ARABIC_DAYS=array("الأثنين", "الثلاثاء", "الأربعاء", "الخميس", "الجمعه", "السبت", "الأحد"); + + static function NUM_TO_MONTH_NOMINATIVE($n, $leap_year) { + // Do not translate these - they are supposed to be arabic, whatever language is shown. + switch ($n) { + case 1: return 'محرّم'; + case 2: return 'صفر'; + case 3: return 'ربيع الأول'; + case 4: return 'ربيع الثانى'; + case 5: return 'جمادى الأول'; + case 6: return 'جمادى الثاني'; + case 7: return 'رجب'; + case 8: return 'شعبان'; + case 9: return 'رمضان'; + case 10: return 'شوّال'; + case 11: return 'ذو القعدة'; + case 12: return 'ذو الحجة'; + default: return ''; + } + } + static function NUM_TO_MONTH_GENITIVE($n, $leap_year) { + // Arabic does not have genitive forms + return self::NUM_TO_MONTH_NOMINATIVE($n, $leap_year); + } + static function NUM_TO_MONTH_LOCATIVE($n, $leap_year) { + // Arabic does not have locative forms + return self::NUM_TO_MONTH_NOMINATIVE($n, $leap_year); + } + + static function NUM_TO_MONTH_INSTRUMENTAL($n, $leap_year) { + // Arabic does not have instrumental forms + return self::NUM_TO_MONTH_NOMINATIVE($n, $leap_year); + } + + static function NUM_TO_SHORT_MONTH($n, $leap_year) { + // TODO: Do these have short names? + return self::NUM_TO_MONTH_NOMINATIVE($n, $leap_year); + } + + function FormatLongWeekday() { + return $this->$ARABIC_DAYS[$this->minJD % $this->NUM_DAYS_OF_WEEK()]; + } + + function FormatShortWeekday() { + return $this->$ARABIC_DAYS[$this->minJD % $this->NUM_DAYS_OF_WEEK()]; + } +} diff --git a/library/WT/Date/Calendar.php b/library/WT/Date/Calendar.php new file mode 100644 index 0000000000..802ae926c0 --- /dev/null +++ b/library/WT/Date/Calendar.php @@ -0,0 +1,615 @@ +<?php +// Classes for Gedcom Date/Calendar functionality. +// +// WT_Date_Calendar is a base class for classes such as WT_Date_Gregorian, etc. +// +// + All supported calendars have non-zero days/months/years. +// + We store dates as both Y/M/D and Julian Days. +// + For imprecise dates such as "JAN 2000" we store the start/end julian day. +// +// NOTE: Since different calendars start their days at different times, (civil +// midnight, solar midnight, sunset, sunrise, etc.), we convert on the basis of +// midday. +// +// webtrees: Web based Family History software +// Copyright (C) 2011 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 +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// @author Greg Roach +// @version $Id$ + +if (!defined('WT_WEBTREES')) { + header('HTTP/1.0 403 Forbidden'); + exit; +} + +class WT_Date_Calendar { + var $y, $m, $d; // Numeric year/month/day + var $minJD, $maxJD; // Julian Day numbers + + function __construct($date) { + // Construct from an integer (a julian day number) + if (is_numeric($date)) { + $this->minJD=$date; + $this->maxJD=$date; + list($this->y, $this->m, $this->d)=$this->JDtoYMD($date); + return; + } + + // 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]); + } else { + $this->m=0; + $this->d=0; + } + $this->y=$this->ExtractYear($date[0]); + $this->SetJDfromYMD(); + return; + } + + // Construct from an equivalent xxxxDate object + if ($this->CALENDAR_ESCAPE()==$date->CALENDAR_ESCAPE()) { + // 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; + $this->minJD=$date->minJD; + $this->maxJD=$date->maxJD; + return; + } + + // ...else construct an inequivalent xxxxDate object + if ($date->y==0) { + // Incomplete date - convert on basis of anniversary in current year + $today=$date->TodayYMD(); + $jd=$date->YMDtoJD($today[0], $date->m, $date->d==0?$today[2]:$date->d); + } else { + // Complete date + $jd=floor(($date->maxJD+$date->minJD)/2); + } + list($this->y, $this->m, $this->d)=$this->JDtoYMD($jd); + // New date has same precision as original date + if ($date->y==0) $this->y=0; + if ($date->m==0) $this->m=0; + if ($date->d==0) $this->d=0; + $this->SetJDfromYMD(); + } + + // Set the object's JD from a potentially incomplete YMD + function SetJDfromYMD() { + if ($this->y==0) { + $this->minJD=0; + $this->maxJD=0; + } else + if ($this->m==0) { + $this->minJD=$this->YMDtoJD($this->y, 1, 1); + $this->maxJD=$this->YMDtoJD($this->NextYear($this->y), 1, 1)-1; + } else { + if ($this->d==0) { + list($ny,$nm)=$this->NextMonth(); + $this->minJD=$this->YMDtoJD($this->y, $this->m, 1); + $this->maxJD=$this->YMDtoJD($ny, $nm, 1)-1; + } else { + $this->minJD=$this->YMDtoJD($this->y, $this->m, $this->d); + $this->maxJD=$this->minJD; + } + } + } + + // 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) { + case 1: return i18n::translate_c('NOMINATIVE', 'January'); + case 2: return i18n::translate_c('NOMINATIVE', 'February'); + case 3: return i18n::translate_c('NOMINATIVE', 'March'); + case 4: return i18n::translate_c('NOMINATIVE', 'April'); + case 5: return i18n::translate_c('NOMINATIVE', 'May'); + case 6: return i18n::translate_c('NOMINATIVE', 'June'); + case 7: return i18n::translate_c('NOMINATIVE', 'July'); + case 8: return i18n::translate_c('NOMINATIVE', 'August'); + case 9: return i18n::translate_c('NOMINATIVE', 'September'); + case 10: return i18n::translate_c('NOMINATIVE', 'October'); + case 11: return i18n::translate_c('NOMINATIVE', 'November'); + case 12: return i18n::translate_c('NOMINATIVE', 'December'); + default: return ''; + } + } + static function NUM_TO_MONTH_GENITIVE($n, $leap_year) { + switch ($n) { + case 1: return i18n::translate_c('GENITIVE', 'January'); + case 2: return i18n::translate_c('GENITIVE', 'February'); + case 3: return i18n::translate_c('GENITIVE', 'March'); + case 4: return i18n::translate_c('GENITIVE', 'April'); + case 5: return i18n::translate_c('GENITIVE', 'May'); + case 6: return i18n::translate_c('GENITIVE', 'June'); + case 7: return i18n::translate_c('GENITIVE', 'July'); + case 8: return i18n::translate_c('GENITIVE', 'August'); + case 9: return i18n::translate_c('GENITIVE', 'September'); + case 10: return i18n::translate_c('GENITIVE', 'October'); + case 11: return i18n::translate_c('GENITIVE', 'November'); + case 12: return i18n::translate_c('GENITIVE', 'December'); + default: return ''; + } + } + static function NUM_TO_MONTH_LOCATIVE($n, $leap_year) { + switch ($n) { + case 1: return i18n::translate_c('LOCATIVE', 'January'); + case 2: return i18n::translate_c('LOCATIVE', 'February'); + case 3: return i18n::translate_c('LOCATIVE', 'March'); + case 4: return i18n::translate_c('LOCATIVE', 'April'); + case 5: return i18n::translate_c('LOCATIVE', 'May'); + case 6: return i18n::translate_c('LOCATIVE', 'June'); + case 7: return i18n::translate_c('LOCATIVE', 'July'); + case 8: return i18n::translate_c('LOCATIVE', 'August'); + case 9: return i18n::translate_c('LOCATIVE', 'September'); + case 10: return i18n::translate_c('LOCATIVE', 'October'); + case 11: return i18n::translate_c('LOCATIVE', 'November'); + case 12: return i18n::translate_c('LOCATIVE', 'December'); + default: return ''; + } + } + static function NUM_TO_MONTH_INSTRUMENTAL($n, $leap_year) { + switch ($n) { + case 1: return i18n::translate_c('INSTRUMENTAL', 'January'); + case 2: return i18n::translate_c('INSTRUMENTAL', 'February'); + case 3: return i18n::translate_c('INSTRUMENTAL', 'March'); + case 4: return i18n::translate_c('INSTRUMENTAL', 'April'); + case 5: return i18n::translate_c('INSTRUMENTAL', 'May'); + case 6: return i18n::translate_c('INSTRUMENTAL', 'June'); + case 7: return i18n::translate_c('INSTRUMENTAL', 'July'); + case 8: return i18n::translate_c('INSTRUMENTAL', 'August'); + case 9: return i18n::translate_c('INSTRUMENTAL', 'September'); + case 10: return i18n::translate_c('INSTRUMENTAL', 'October'); + case 11: return i18n::translate_c('INSTRUMENTAL', 'November'); + case 12: return i18n::translate_c('INSTRUMENTAL', 'December'); + default: return ''; + } + } + static function NUM_TO_SHORT_MONTH($n, $leap_year) { + switch ($n) { + case 1: return i18n::translate_c('Abbreviation for January', 'Jan'); + case 2: return i18n::translate_c('Abbreviation for February', 'Feb'); + case 3: return i18n::translate_c('Abbreviation for March', 'Mar'); + case 4: return i18n::translate_c('Abbreviation for April', 'Apr'); + case 5: return i18n::translate_c('Abbreviation for May', 'May'); + case 6: return i18n::translate_c('Abbreviation for June', 'Jun'); + case 7: return i18n::translate_c('Abbreviation for July', 'Jul'); + case 8: return i18n::translate_c('Abbreviation for August', 'Aug'); + case 9: return i18n::translate_c('Abbreviation for September', 'Sep'); + case 10: return i18n::translate_c('Abbreviation for October', 'Oct'); + case 11: return i18n::translate_c('Abbreviation for November', 'Nov'); + case 12: return i18n::translate_c('Abbreviation for December', 'Dec'); + 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 i18n::translate('Monday'); + case 1: return i18n::translate('Tuesday'); + case 2: return i18n::translate('Wednesday'); + case 3: return i18n::translate('Thursday'); + case 4: return i18n::translate('Friday'); + case 5: return i18n::translate('Saturday'); + case 6: return i18n::translate('Sunday'); + } + } + static function SHORT_DAYS_OF_WEEK($n) { + switch ($n) { + case 0: return i18n::translate('Mon'); + case 1: return i18n::translate('Tue'); + case 2: return i18n::translate('Wed'); + case 3: return i18n::translate('Thu'); + case 4: return i18n::translate('Fri'); + case 5: return i18n::translate('Sat'); + case 6: return i18n::translate('Sun'); + } + } + static function YMDtoJD($y, $m, $d) { + return 0; + } + static function JDtoYMD($j) { + return array(0, 0, 0); + } + // Most years are 1 more than the previous, but not always (e.g. 1BC->1AD) + 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) { + return (int)$year; + } + // Leap years may have extra days, extra months, etc. + function IsLeapYear() { + return false; + } + + // Compare two dates - helper function for sorting by date + static function Compare($d1, $d2) { + if ($d1->maxJD < $d2->minJD) + return -1; + if ($d2->minJD > $d1->maxJD) + return 1; + return 0; + } + + // How long between an event and a given julian day + // Return result as either a number of years or + // a gedcom-style age string. + // 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) { + if ($this->y==0 || $jd==0) { + return ''; + } + if ($this->minJD < $jd && $this->maxJD > $jd) { + return ''; + } + if ($this->minJD==$jd) { + return $full?'':'0'; + } + if ($warn_on_negative && $jd<$this->minJD) { + return '<img alt="" src="images/warning.gif" />'; + } + list($y,$m,$d)=$this->JDtoYMD($jd); + $dy=$y-$this->y; + $dm=$m-max($this->m,1); + $dd=$d-max($this->d,1); + if ($dd<0) { + $dd+=$this->DaysInMonth(); + $dm--; + } + if ($dm<0) { + $dm+=$this->NUM_MONTHS(); + $dy--; + } + // Not a full age? Then just the years + if (!$full) + return $dy; + // Age in years? + if ($dy>1) + return $dy.'y'; + $dm+=$dy*$this->NUM_MONTHS(); + // Age in months? + if ($dm>1) + return $dm.'m'; + // Age in days? + return ($jd-$this->minJD)."d"; + } + + // Convert a date from one calendar to another. + function convert_to_cal($calendar) { + switch ($calendar) { + case 'gregorian': + return new WT_Date_Gregorian($this); + case 'julian': + return new WT_Date_Julian($this); + case 'jewish': + if (WT_LOCALE!='he') + return new WT_Date_Jewish($this); + // no break + case 'hebrew': + return new WT_Date_Hebrew($this); + case 'french': + return new WT_Date_French($this); + case 'arabic': + if (WT_LOCALE!='ar') + return new WT_Date_Arabic($this); + // no break + case 'hijri': + return new WT_Date_Hijri($this); + default: + return $this; + } + } + + // 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(); + } + + // How many days in the current month + 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(); + } + + // 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 + if (!$this->d) { + // The comma is for US "M D, Y" dates + $format=preg_replace('/%[djlDNSwz][,]?/', '', $format); + } + if (!$this->m) { + $format=str_replace(array('%F', '%m', '%M', '%n', '%t'), '', $format); + } + if (!$this->y) { + $format=str_replace(array('%t', '%L', '%G', '%y', '%Y'), '', $format); + } + // If we've trimmed the format, also trim the punctuation + if (!$this->d || !$this->m || !$this->y) { + $format=trim($format, ',. ;/-'); + } + if ($this->d && preg_match('/%[djlDNSwz]/', $format)) { + // If we have a day-number *and* we are being asked to display it, then genitive + $case='GENITIVE'; + } else { + switch ($qualifier) { + case '': + case 'int': + case 'est': + case 'cal': $case='NOMINATIVE'; break; + case 'to': + case 'abt': + case 'from': $case='GENITIVE'; break; + case 'aft': $case='LOCATIVE'; break; + case 'bef': + case 'bet': + case 'and': $case='INSTRUMENTAL'; break; + } + } + // Build up the formated date, character at a time + preg_match_all('/%[^%]/', $format, $matches); + foreach ($matches[0] as $match) { + switch ($match) { + case '%d': $format=str_replace($match, $this->FormatDayZeros(), $format); break; + case '%j': $format=str_replace($match, $this->FormatDay(), $format); break; + case '%l': $format=str_replace($match, $this->FormatLongWeekday(), $format); break; + case '%D': $format=str_replace($match, $this->FormatShortWeekday(), $format); break; + case '%N': $format=str_replace($match, $this->FormatISOWeekday(), $format); break; + case '%S': $format=str_replace($match, $this->FormatOrdinalSuffix(), $format); break; + case '%w': $format=str_replace($match, $this->FormatNumericWeekday(), $format); break; + case '%z': $format=str_replace($match, $this->FormatDayOfYear(), $format); break; + case '%F': $format=str_replace($match, $this->FormatLongMonth($case), $format); break; + case '%m': $format=str_replace($match, $this->FormatMonthZeros(), $format); break; + case '%M': $format=str_replace($match, $this->FormatShortMonth(), $format); break; + case '%n': $format=str_replace($match, $this->FormatMonth(), $format); break; + case '%t': $format=str_replace($match, $this->DaysInMonth(), $format); break; + case '%L': $format=str_replace($match, (int)$this->IsLeapYear(), $format); break; + 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 '%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; + } + } + return $format; + } + + // Functions to extract bits of the date in various formats. Individual calendars + // will want to redefine some of these. + function FormatDayZeros() { + if ($this->d<10) + return '0'.$this->d; + else + return $this->d; + } + + function FormatDay() { + return $this->d; + } + + function FormatLongWeekday() { + return $this->LONG_DAYS_OF_WEEK($this->minJD % $this->NUM_DAYS_OF_WEEK()); + } + + function FormatShortWeekday() { + return $this->SHORT_DAYS_OF_WEEK($this->minJD % $this->NUM_DAYS_OF_WEEK()); + } + + function FormatISOWeekday() { + return $this->minJD % 7 + 1; + } + + function FormatOrdinalSuffix() { + $func="ordinal_suffix_".WT_LOCALE; + if (function_exists($func)) + return $func($this->d); + else + return ''; + } + + function FormatNumericWeekday() { + return ($this->minJD + 1) % $this->NUM_DAYS_OF_WEEK(); + } + + function FormatDayOfYear() { + return $this->minJD - $this->YMDtoJD($this->y, 1, 1); + } + + function FormatMonth() { + return $this->m; + } + + function FormatMonthZeros() { + if ($this->m > 9) + return $this->m; + else + return '0'.$this->m; + } + + 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()); + case 'LOCATIVE': return $this->NUM_TO_MONTH_LOCATIVE ($this->m, $this->IsLeapYear()); + case 'INSTRUMENTAL': return $this->NUM_TO_MONTH_INSTRUMENTAL($this->m, $this->IsLeapYear()); + } + } + + 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() { + return $this->y; + } + + function FormatGedcomDay() { + if ($this->d==0) + return ''; + else + return sprintf('%02d', $this->d); + } + + function FormatGedcomMonth() { + return $this->NUM_TO_GEDCOM_MONTH($this->m, $this->IsLeapYear()); + } + + function FormatGedcomYear() { + if ($this->y==0) + return ''; + else + return sprintf('%04d', $this->y); + } + + function FormatLongYear() { + return $this->y; + } + + // Calendars with leap-months should redefine this. + function NextMonth() { + return array( + $this->m==$this->NUM_MONTHS() ? $this->NextYear($this->y) : $this->y, + ($this->m%$this->NUM_MONTHS())+1 + ); + } + + // Convert a decimal number to roman numerals + static function NumToRoman($num) { + 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'); + if ($num<1) return $num; + $roman=''; + foreach ($lookup as $key=>$value) + while ($num>=$key) { + $roman.=$value; + $num-=$key; + } + return $roman; + } + + // Convert a roman numeral to decimal + 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) + if (strpos($roman, $value)===0) { + $num+=$key; + $roman=substr($roman, strlen($value)); + } + return $num; + } + + // Get today's date in the current calendar + function TodayYMD() { + return $this->JDtoYMD(WT_Date_Gregorian::YMDtoJD(date('Y'), date('n'), date('j'))); + } + function Today() { + $tmp=clone $this; + $ymd=$tmp->TodayYMD(); + $tmp->y=$ymd[0]; + $tmp->m=$ymd[1]; + $tmp->d=$ymd[2]; + $tmp->SetJDfromYMD(); + return $tmp; + } + + // Create a URL that links this date to the WT calendar + function CalendarURL($date_fmt="") { + global $DATE_FORMAT; + if (empty($date_fmt)) { + $date_fmt=$DATE_FORMAT; + } + $URL='calendar.php?cal='.$this->CALENDAR_ESCAPE(); + $action="year"; + if (strpos($date_fmt, "Y")!==false + || strpos($date_fmt, "y")!==false) { + $URL.='&year='.$this->FormatGedcomYear(); + } + if (strpos($date_fmt, "F")!==false + || strpos($date_fmt, "M")!==false + || strpos($date_fmt, "m")!==false + || strpos($date_fmt, "n")!==false) { + $URL.='&month='.$this->FormatGedcomMonth(); + if ($this->m>0) + $action="calendar"; + } + if (strpos($date_fmt, "d")!==false + || strpos($date_fmt, "D")!==false + || strpos($date_fmt, "j")!==false) { + $URL.='&day='.$this->FormatGedcomDay(); + if ($this->d>0) + $action="today"; + } + return $URL.'&action='.$action; + } +} diff --git a/library/WT/Date/French.php b/library/WT/Date/French.php new file mode 100644 index 0000000000..9403a91b8e --- /dev/null +++ b/library/WT/Date/French.php @@ -0,0 +1,190 @@ +<?php +// Classes for Gedcom Date/Calendar functionality. +// +// Definitions for the French Republican calendar +// +// NOTE: Since different calendars start their days at different times, (civil +// midnight, solar midnight, sunset, sunrise, etc.), we convert on the basis of +// midday. +// +// webtrees: Web based Family History software +// Copyright (C) 2011 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 +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// @author Greg Roach +// @version $Id$ + +if (!defined('WT_WEBTREES')) { + header('HTTP/1.0 403 Forbidden'); + exit; +} + +class WT_Date_French extends WT_Date_Calendar { + static function CALENDAR_ESCAPE() { + return '@#DFRENCH R@'; + } + + 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 i18n::translate_c('NOMINATIVE', 'Vendémiaire'); + case 2: return i18n::translate_c('NOMINATIVE', 'Brumaire'); + case 3: return i18n::translate_c('NOMINATIVE', 'Frimaire'); + case 4: return i18n::translate_c('NOMINATIVE', 'Nivôse'); + case 5: return i18n::translate_c('NOMINATIVE', 'Pluviôse'); + case 6: return i18n::translate_c('NOMINATIVE', 'Ventôse'); + case 7: return i18n::translate_c('NOMINATIVE', 'Germinal'); + case 8: return i18n::translate_c('NOMINATIVE', 'Floréal'); + case 9: return i18n::translate_c('NOMINATIVE', 'Prairial'); + case 10: return i18n::translate_c('NOMINATIVE', 'Messidor'); + case 11: return i18n::translate_c('NOMINATIVE', 'Thermidor'); + case 12: return i18n::translate_c('NOMINATIVE', 'Fructidor'); + case 13: return i18n::translate_c('NOMINATIVE', 'jours complémentaires'); + } + } + static function NUM_TO_MONTH_GENITIVE($n, $leap_year) { + switch ($n) { + case 1: return i18n::translate_c('GENITIVE', 'Vendémiaire'); + case 2: return i18n::translate_c('GENITIVE', 'Brumaire'); + case 3: return i18n::translate_c('GENITIVE', 'Frimaire'); + case 4: return i18n::translate_c('GENITIVE', 'Nivôse'); + case 5: return i18n::translate_c('GENITIVE', 'Pluviôse'); + case 6: return i18n::translate_c('GENITIVE', 'Ventôse'); + case 7: return i18n::translate_c('GENITIVE', 'Germinal'); + case 8: return i18n::translate_c('GENITIVE', 'Floréal'); + case 9: return i18n::translate_c('GENITIVE', 'Prairial'); + case 10: return i18n::translate_c('GENITIVE', 'Messidor'); + case 11: return i18n::translate_c('GENITIVE', 'Thermidor'); + case 12: return i18n::translate_c('GENITIVE', 'Fructidor'); + case 13: return i18n::translate_c('GENITIVE', 'jours complémentaires'); + } + } + static function NUM_TO_MONTH_LOCATIVE($n, $leap_year) { + switch ($n) { + case 1: return i18n::translate_c('LOCATIVE', 'Vendémiaire'); + case 2: return i18n::translate_c('LOCATIVE', 'Brumaire'); + case 3: return i18n::translate_c('LOCATIVE', 'Frimaire'); + case 4: return i18n::translate_c('LOCATIVE', 'Nivôse'); + case 5: return i18n::translate_c('LOCATIVE', 'Pluviôse'); + case 6: return i18n::translate_c('LOCATIVE', 'Ventôse'); + case 7: return i18n::translate_c('LOCATIVE', 'Germinal'); + case 8: return i18n::translate_c('LOCATIVE', 'Floréal'); + case 9: return i18n::translate_c('LOCATIVE', 'Prairial'); + case 10: return i18n::translate_c('LOCATIVE', 'Messidor'); + case 11: return i18n::translate_c('LOCATIVE', 'Thermidor'); + case 12: return i18n::translate_c('LOCATIVE', 'Fructidor'); + case 13: return i18n::translate_c('LOCATIVE', 'jours complémentaires'); + } + } + static function NUM_TO_MONTH_INSTRUMENTAL($n, $leap_year) { + switch ($n) { + case 1: return i18n::translate_c('INSTRUMENTAL', 'Vendémiaire'); + case 2: return i18n::translate_c('INSTRUMENTAL', 'Brumaire'); + case 3: return i18n::translate_c('INSTRUMENTAL', 'Frimaire'); + case 4: return i18n::translate_c('INSTRUMENTAL', 'Nivôse'); + case 5: return i18n::translate_c('INSTRUMENTAL', 'Pluviôse'); + case 6: return i18n::translate_c('INSTRUMENTAL', 'Ventôse'); + case 7: return i18n::translate_c('INSTRUMENTAL', 'Germinal'); + case 8: return i18n::translate_c('INSTRUMENTAL', 'Floréal'); + case 9: return i18n::translate_c('INSTRUMENTAL', 'Prairial'); + case 10: return i18n::translate_c('INSTRUMENTAL', 'Messidor'); + case 11: return i18n::translate_c('INSTRUMENTAL', 'Thermidor'); + case 12: return i18n::translate_c('INSTRUMENTAL', 'Fructidor'); + case 13: return i18n::translate_c('INSTRUMENTAL', 'jours complémentaires'); + } + } + 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 '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 i18n::translate('Primidi'); + case 1: return i18n::translate('Duodi'); + case 2: return i18n::translate('Tridi'); + case 3: return i18n::translate('Quartidi'); + case 4: return i18n::translate('Quintidi'); + case 5: return i18n::translate('Sextidi'); + case 6: return i18n::translate('Septidi'); + case 7: return i18n::translate('Octidi'); + case 8: return i18n::translate('Nonidi'); + case 9: return i18n::translate('Decidi'); + } + } + static function SHORT_DAYS_OF_WEEK($n) { + // 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 + // but never implemented. These functions are valid over the range years 1-14. + function IsLeapYear() { + return $this->y%4==3; + } + + static function YMDtoJD($y, $m, $d) { + return 2375444+$d+$m*30+$y*365+floor($y/4); + } + + static function JDtoYMD($j) { + $y=floor(($j-2375109)*4/1461)-1; + $m=floor(($j-2375475-$y*365-floor($y/4))/30)+1; + $d=$j-2375444-$m*30-$y*365-floor($y/4); + return array($y, $m, $d); + } + + // Years were written using roman numerals + function FormatLongYear() { + return $this->NumToRoman($this->y); + } +} diff --git a/library/WT/Date/Gregorian.php b/library/WT/Date/Gregorian.php new file mode 100644 index 0000000000..2f5d08dd95 --- /dev/null +++ b/library/WT/Date/Gregorian.php @@ -0,0 +1,70 @@ +<?php +// Classes for Gedcom Date/Calendar functionality. +// +// Definitions for the Gregorian calendar +// +// NOTE: Since different calendars start their days at different times, (civil +// midnight, solar midnight, sunset, sunrise, etc.), we convert on the basis of +// midday. +// +// webtrees: Web based Family History software +// Copyright (C) 2011 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 +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// @author Greg Roach +// @version $Id$ + +if (!defined('WT_WEBTREES')) { + header('HTTP/1.0 403 Forbidden'); + exit; +} + +class WT_Date_Gregorian extends WT_Date_Calendar { + static function CALENDAR_ESCAPE() { + return '@#DGREGORIAN@'; + } + static function CAL_START_JD() { + return 2299161; // 15 OCT 1582 + } + + function IsLeapYear() { + return $this->y%4==0 && $this->y%100!=0 || $this->y%400==0; + } + + static function YMDtoJD($y, $m, $d) { + if ($y<0) // 0=1BC, -1=2BC, etc. + ++$y; + $a=floor((14-$m)/12); + $y=$y+4800-$a; + $m=$m+12*$a-3; + return $d+floor((153*$m+2)/5)+365*$y+floor($y/4)-floor($y/100)+floor($y/400)-32045; + } + + static function JDtoYMD($j) { + $a=$j+32044; + $b=floor((4*$a+3)/146097); + $c=$a-floor($b*146097/4); + $d=floor((4*$c+3)/1461); + $e=$c-floor((1461*$d)/4); + $m=floor((5*$e+2)/153); + $day=$e-floor((153*$m+2)/5)+1; + $month=$m+3-12*floor($m/10); + $year=$b*100+$d-4800+floor($m/10); + if ($year<1) // 0=1BC, -1=2BC, etc. + --$year; + return array($year, $month, $day); + } +} diff --git a/library/WT/Date/Hebrew.php b/library/WT/Date/Hebrew.php new file mode 100644 index 0000000000..1e0f7dfc95 --- /dev/null +++ b/library/WT/Date/Hebrew.php @@ -0,0 +1,172 @@ +<?php +// Classes for Gedcom Date/Calendar functionality. +// +// Definitions for the Hebrew calendar. +// NOTE - this is the same as the Jewish Calendar, but displays dates in hebrew +// rather than the local language. +// +// NOTE: Since different calendars start their days at different times, (civil +// midnight, solar midnight, sunset, sunrise, etc.), we convert on the basis of +// midday. +// +// webtrees: Web based Family History software +// Copyright (C) 2011 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 +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// @author Greg Roach +// @version $Id$ + +if (!defined('WT_WEBTREES')) { + header('HTTP/1.0 403 Forbidden'); + exit; +} + +class WT_Date_Hebrew extends WT_Date_Jewish { + const GERSHAYIM="״"; + const GERSH="׳"; + const ALAFIM="אלפים"; + + function FormatDayZeros() { + return $this->NumToHebrew($this->d); + } + + function FormatDay() { + return $this->NumToHebrew($this->d); + } + + static function LONG_DAYS_OF_WEEK($n) { + // Do not translate these - they are supposed to be hebrew, whatever language is shown. + switch ($n) { + case 0: return 'שני'; + case 1: return 'שלישי'; + case 2: return 'רביעי'; + case 3: return 'חמישי'; + case 4: return 'ששי'; + case 5: return 'שבת'; + case 6: return 'ראשון'; + } + } + static function SHORT_DAYS_OF_WEEK($n) { + // TODO: Do these have short names? + return LONG_DAYS_OF_WEEK($n); + } + + static function NUM_TO_MONTH_NOMINATIVE($n, $leap_year) { + // Do not translate these - they are supposed to be hebrew, whatever language is shown. + switch ($n) { + case 1: return 'תשרי'; + case 2: return 'חשוון'; + case 3: return 'כסלו'; + case 4: return 'טבת'; + case 5: return 'שבט'; + case 6: if ($leap_year) return 'אדר א׳'; else return 'אדר'; + case 7: return 'אדר ב׳'; + case 8: return 'ניסן'; + case 9: return 'אייר'; + case 10: return 'סיוון'; + case 11: return 'תמוז'; + case 12: return 'אב'; + case 13: return 'אלול'; + default: return ''; + } + } + + static function NUM_TO_MONTH_GENITIVE($n, $leap_year) { + // Hebrew does not have genitive forms + return self::NUM_TO_MONTH_NOMINATIVE($n, $leap_year); + } + + static function NUM_TO_MONTH_LOCATIVE($n, $leap_year) { + // Hebrew does not have locative forms + return self::NUM_TO_MONTH_NOMINATIVE($n, $leap_year); + } + + static function NUM_TO_MONTH_INSTRUMENTAL($n, $leap_year) { + // Hebrew does not have instrumental forms + return self::NUM_TO_MONTH_NOMINATIVE($n, $leap_year); + } + + static function NUM_TO_SHORT_MONTH($n, $leap_year) { + // TODO: Do these have short names? + return self::NUM_TO_MONTH_NOMINATIVE($n, $leap_year); + } + + function FormatShortYear() { + return $this->NumToHebrew($this->y%1000); + } + + function FormatLongYear() { + return $this->NumToHebrew($this->y); + } + // Convert a decimal number to hebrew - like roman numerals, but with extra punctuation + // and special rules. + static function NumToHebrew($num) { + global $DISPLAY_JEWISH_THOUSANDS; + + static $jHundreds = array("", "ק", "ר", "ש", "ת", "תק", "תר","תש", "תת", "תתק"); + static $jTens = array("", "י", "כ", "ל", "מ", "נ", "ס", "ע", "פ", "צ"); + static $jTenEnds = array("", "י", "ך", "ל", "ם", "ן", "ס", "ע", "ף", "ץ"); + static $tavTaz = array("ט״ו", "ט״ז"); + static $jOnes = array("", "א", "ב", "ג", "ד", "ה", "ו", "ז", "ח", "ט"); + + $shortYear = $num %1000; //discard thousands + //next check for all possible single Hebrew digit years + $singleDigitYear=($shortYear < 11 || ($shortYear <100 && $shortYear % 10 == 0) || ($shortYear <= 400 && $shortYear % 100 ==0)); + $thousands = $num / 1000; //get # thousands + $sb = ""; + //append thousands to String + if ($num % 1000 == 0) { // in year is 5000, 4000 etc + $sb .= $jOnes[$thousands]; + $sb .= self::GERSH; + $sb .= " "; + $sb .= self::ALAFIM; //add # of thousands plus word thousand (overide alafim boolean) + } else if ($DISPLAY_JEWISH_THOUSANDS) { // if alafim boolean display thousands + $sb .= $jOnes[$thousands]; + $sb .= self::GERSH; //append thousands quote + $sb .= " "; + } + $num = $num % 1000; //remove 1000s + $hundreds = $num / 100; // # of hundreds + $sb .= $jHundreds[$hundreds]; //add hundreds to String + $num = $num % 100; //remove 100s + if ($num == 15) { //special case 15 + $sb .= $tavTaz[0]; + } else if ($num == 16) { //special case 16 + $sb .= $tavTaz[1]; + } else { + $tens = $num / 10; + if ($num % 10 == 0) { // if evenly divisable by 10 + if ($singleDigitYear == false) { + $sb .= $jTenEnds[$tens]; // use end letters so that for example 5750 will end with an end nun + } else { + $sb .= $jTens[$tens]; // use standard letters so that for example 5050 will end with a regular nun + } + } else { + $sb .= $jTens[$tens]; + $num = $num % 10; + $sb .= $jOnes[$num]; + } + } + if ($singleDigitYear == true) { + $sb .= self::GERSH; //append single quote + } else { // append double quote before last digit + $pos1 = strlen($sb)-2; + $sb = substr($sb, 0, $pos1) . self::GERSHAYIM . substr($sb, $pos1); + $sb = str_replace(self::GERSHAYIM . self::GERSHAYIM, self::GERSHAYIM, $sb); //replace double gershayim with single instance + } + return $sb; + } +} diff --git a/library/WT/Date/Hijri.php b/library/WT/Date/Hijri.php new file mode 100644 index 0000000000..ec06d88f9e --- /dev/null +++ b/library/WT/Date/Hijri.php @@ -0,0 +1,155 @@ +<?php +// Classes for Gedcom Date/Calendar functionality. +// +// Definitions for the Hijri calendar. Note that these are "theoretical" dates. +// "True" dates are based on local lunar observations, and can be a +/- one day. +// +// NOTE: Since different calendars start their days at different times, (civil +// midnight, solar midnight, sunset, sunrise, etc.), we convert on the basis of +// midday. +// +// webtrees: Web based Family History software +// Copyright (C) 2011 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 +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// @author Greg Roach +// @version $Id$ + +if (!defined('WT_WEBTREES')) { + header('HTTP/1.0 403 Forbidden'); + exit; +} + +class WT_Date_Hijri extends WT_Date_Calendar { + static function CALENDAR_ESCAPE() { + return '@#DHIJRI@'; + } + 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::translate_c('NOMINATIVE', 'Muharram'); + case 2: return i18n::translate_c('NOMINATIVE', 'Safar'); + case 3: return i18n::translate_c('NOMINATIVE', 'Rabi\' al-awwal'); + case 4: return i18n::translate_c('NOMINATIVE', 'Rabi\' al-thani'); + case 5: return i18n::translate_c('NOMINATIVE', 'Jumada al-awwal'); + case 6: return i18n::translate_c('NOMINATIVE', 'Jumada al-thani'); + case 7: return i18n::translate_c('NOMINATIVE', 'Rajab'); + case 8: return i18n::translate_c('NOMINATIVE', 'Sha\'aban'); + case 9: return i18n::translate_c('NOMINATIVE', 'Ramadan'); + case 10: return i18n::translate_c('NOMINATIVE', 'Shawwal'); + case 11: return i18n::translate_c('NOMINATIVE', 'Dhu al-Qi\'dah'); + case 12: return i18n::translate_c('NOMINATIVE', 'Dhu al-Hijjah'); + default: return ''; + } + } + static function NUM_TO_MONTH_GENITIVE($n, $leap_year) { + switch ($n) { + case 1: return i18n::translate_c('GENITIVE', 'Muharram'); + case 2: return i18n::translate_c('GENITIVE', 'Safar'); + case 3: return i18n::translate_c('GENITIVE', 'Rabi\' al-awwal'); + case 4: return i18n::translate_c('GENITIVE', 'Rabi\' al-thani'); + case 5: return i18n::translate_c('GENITIVE', 'Jumada al-awwal'); + case 6: return i18n::translate_c('GENITIVE', 'Jumada al-thani'); + case 7: return i18n::translate_c('GENITIVE', 'Rajab'); + case 8: return i18n::translate_c('GENITIVE', 'Sha\'aban'); + case 9: return i18n::translate_c('GENITIVE', 'Ramadan'); + case 10: return i18n::translate_c('GENITIVE', 'Shawwal'); + case 11: return i18n::translate_c('GENITIVE', 'Dhu al-Qi\'dah'); + case 12: return i18n::translate_c('GENITIVE', 'Dhu al-Hijjah'); + default: return ''; + } + } + static function NUM_TO_MONTH_LOCATIVE($n, $leap_year) { + switch ($n) { + case 1: return i18n::translate_c('LOCATIVE', 'Muharram'); + case 2: return i18n::translate_c('LOCATIVE', 'Safar'); + case 3: return i18n::translate_c('LOCATIVE', 'Rabi\' al-awwal'); + case 4: return i18n::translate_c('LOCATIVE', 'Rabi\' al-thani'); + case 5: return i18n::translate_c('LOCATIVE', 'Jumada al-awwal'); + case 6: return i18n::translate_c('LOCATIVE', 'Jumada al-thani'); + case 7: return i18n::translate_c('LOCATIVE', 'Rajab'); + case 8: return i18n::translate_c('LOCATIVE', 'Sha\'aban'); + case 9: return i18n::translate_c('LOCATIVE', 'Ramadan'); + case 10: return i18n::translate_c('LOCATIVE', 'Shawwal'); + case 11: return i18n::translate_c('LOCATIVE', 'Dhu al-Qi\'dah'); + case 12: return i18n::translate_c('LOCATIVE', 'Dhu al-Hijjah'); + default: return ''; + } + } + static function NUM_TO_MONTH_INSTRUMENTAL($n, $leap_year) { + switch ($n) { + case 1: return i18n::translate_c('INSTRUMENTAL', 'Muharram'); + case 2: return i18n::translate_c('INSTRUMENTAL', 'Safar'); + case 3: return i18n::translate_c('INSTRUMENTAL', 'Rabi\' al-awwal'); + case 4: return i18n::translate_c('INSTRUMENTAL', 'Rabi\' al-thani'); + case 5: return i18n::translate_c('INSTRUMENTAL', 'Jumada al-awwal'); + case 6: return i18n::translate_c('INSTRUMENTAL', 'Jumada al-thani'); + case 7: return i18n::translate_c('INSTRUMENTAL', 'Rajab'); + case 8: return i18n::translate_c('INSTRUMENTAL', 'Sha\'aban'); + case 9: return i18n::translate_c('INSTRUMENTAL', 'Ramadan'); + case 10: return i18n::translate_c('INSTRUMENTAL', 'Shawwal'); + case 11: return i18n::translate_c('INSTRUMENTAL', 'Dhu al-Qi\'dah'); + case 12: return i18n::translate_c('INSTRUMENTAL', 'Dhu al-Hijjah'); + 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; + } + + static function YMDtoJD($y, $m, $d) { + return $d+29*($m-1)+floor((6*$m-1)/11)+$y*354+floor((3+11*$y)/30)+1948085; + } + + static function JDtoYMD($j) { + $y=floor((30*($j-1948440)+10646)/10631); + $m=floor((11*($j-$y*354-floor((3+11*$y)/30)-1948086)+330)/325); + $d=$j-29*($m-1)-floor((6*$m-1)/11)-$y*354-floor((3+11*$y)/30)-1948085; + return array($y, $m, $d); + } +} diff --git a/library/WT/Date/Jewish.php b/library/WT/Date/Jewish.php new file mode 100644 index 0000000000..4cc3420381 --- /dev/null +++ b/library/WT/Date/Jewish.php @@ -0,0 +1,177 @@ +<?php +// Classes for Gedcom Date/Calendar functionality. +// +// Definitions for the Jewish calendar +// +// NOTE: Since different calendars start their days at different times, (civil +// midnight, solar midnight, sunset, sunrise, etc.), we convert on the basis of +// midday. +// +// webtrees: Web based Family History software +// Copyright (C) 2011 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 +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// @author Greg Roach +// @version $Id$ + +if (!defined('WT_WEBTREES')) { + header('HTTP/1.0 403 Forbidden'); + exit; +} + +class WT_Date_Jewish extends WT_Date_Calendar { + static function CALENDAR_ESCAPE() { + return '@#DHEBREW@'; + } + + 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 i18n::translate_c('NOMINATIVE', 'Tishrei'); + case 2: return i18n::translate_c('NOMINATIVE', 'Heshvan'); + case 3: return i18n::translate_c('NOMINATIVE', 'Kislev'); + case 4: return i18n::translate_c('NOMINATIVE', 'Tevet'); + case 5: return i18n::translate_c('NOMINATIVE', 'Shevat'); + case 6: if ($leap_year) return i18n::translate_c('NOMINATIVE', 'Adar'); else return i18n::translate_c('NOMINATIVE', 'Adar I'); + case 7: return i18n::translate_c('NOMINATIVE', 'Adar II'); + case 8: return i18n::translate_c('NOMINATIVE', 'Nissan'); + case 9: return i18n::translate_c('NOMINATIVE', 'Iyar'); + case 10: return i18n::translate_c('NOMINATIVE', 'Sivan'); + case 11: return i18n::translate_c('NOMINATIVE', 'Tamuz'); + case 12: return i18n::translate_c('NOMINATIVE', 'Av'); + case 13: return i18n::translate_c('NOMINATIVE', 'Elul'); + default: return ''; + } + } + static function NUM_TO_MONTH_GENITIVE($n, $leap_year) { + switch ($n) { + case 1: return i18n::translate_c('GENITIVE', 'Tishrei'); + case 2: return i18n::translate_c('GENITIVE', 'Heshvan'); + case 3: return i18n::translate_c('GENITIVE', 'Kislev'); + case 4: return i18n::translate_c('GENITIVE', 'Tevet'); + case 5: return i18n::translate_c('GENITIVE', 'Shevat'); + case 6: if ($leap_year) return i18n::translate_c('GENITIVE', 'Adar'); else return i18n::translate_c('GENITIVE', 'Adar I'); + case 7: return i18n::translate_c('GENITIVE', 'Adar II'); + case 8: return i18n::translate_c('GENITIVE', 'Nissan'); + case 9: return i18n::translate_c('GENITIVE', 'Iyar'); + case 10: return i18n::translate_c('GENITIVE', 'Sivan'); + case 11: return i18n::translate_c('GENITIVE', 'Tamuz'); + case 12: return i18n::translate_c('GENITIVE', 'Av'); + case 13: return i18n::translate_c('GENITIVE', 'Elul'); + default: return ''; + } + } + static function NUM_TO_MONTH_LOCATIVE($n, $leap_year) { + switch ($n) { + case 1: return i18n::translate_c('LOCATIVE', 'Tishrei'); + case 2: return i18n::translate_c('LOCATIVE', 'Heshvan'); + case 3: return i18n::translate_c('LOCATIVE', 'Kislev'); + case 4: return i18n::translate_c('LOCATIVE', 'Tevet'); + case 5: return i18n::translate_c('LOCATIVE', 'Shevat'); + case 6: if ($leap_year) return i18n::translate_c('LOCATIVE', 'Adar'); else return i18n::translate_c('LOCATIVE', 'Adar I'); + case 7: return i18n::translate_c('LOCATIVE', 'Adar II'); + case 8: return i18n::translate_c('LOCATIVE', 'Nissan'); + case 9: return i18n::translate_c('LOCATIVE', 'Iyar'); + case 10: return i18n::translate_c('LOCATIVE', 'Sivan'); + case 11: return i18n::translate_c('LOCATIVE', 'Tamuz'); + case 12: return i18n::translate_c('LOCATIVE', 'Av'); + case 13: return i18n::translate_c('LOCATIVE', 'Elul'); + default: return ''; + } + } + static function NUM_TO_MONTH_INSTRUMENTAL($n, $leap_year) { + switch ($n) { + case 1: return i18n::translate_c('INSTRUMENTAL', 'Tishrei'); + case 2: return i18n::translate_c('INSTRUMENTAL', 'Heshvan'); + case 3: return i18n::translate_c('INSTRUMENTAL', 'Kislev'); + case 4: return i18n::translate_c('INSTRUMENTAL', 'Tevet'); + case 5: return i18n::translate_c('INSTRUMENTAL', 'Shevat'); + case 6: if ($leap_year) return i18n::translate_c('INSTRUMENTAL', 'Adar'); else return i18n::translate_c('INSTRUMENTAL', 'Adar I'); + case 7: return i18n::translate_c('INSTRUMENTAL', 'Adar II'); + case 8: return i18n::translate_c('INSTRUMENTAL', 'Nissan'); + case 9: return i18n::translate_c('INSTRUMENTAL', 'Iyar'); + case 10: return i18n::translate_c('INSTRUMENTAL', 'Sivan'); + case 11: return i18n::translate_c('INSTRUMENTAL', 'Tamuz'); + case 12: return i18n::translate_c('INSTRUMENTAL', 'Av'); + case 13: return i18n::translate_c('INSTRUMENTAL', 'Elul'); + 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) { + // TODO: Do these have short names in English? + 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()) + return array($this->y, 8); + else + return array($this->y+($this->m==13?1:0), ($this->m%13)+1); + } + + function IsLeapYear() { + return ((7*$this->y+1)%19)<7; + } + + // TODO implement this function locally + static function YMDtoJD($y, $mh, $d) { + if (function_exists('JewishToJD')) + return JewishToJD($mh, $d, $y); + else + return 0; + } + + // TODO implement this function locally + static function JDtoYMD($j) { + if (function_exists('JdToJewish')) + list($m, $d, $y)=explode('/', JDToJewish($j)); + else + list($m, $d, $y)=array(0, 0, 0); + return array($y, $m, $d); + } +} diff --git a/library/WT/Date/Julian.php b/library/WT/Date/Julian.php new file mode 100644 index 0000000000..f900401053 --- /dev/null +++ b/library/WT/Date/Julian.php @@ -0,0 +1,109 @@ +<?php +// Classes for Gedcom Date/Calendar functionality. +// +// Definitions for the Julian Proleptic calendar +// (Proleptic means we extend it backwards, prior to its introduction in 46BC) +// +// NOTE: Since different calendars start their days at different times, (civil +// midnight, solar midnight, sunset, sunrise, etc.), we convert on the basis of +// midday. +// +// webtrees: Web based Family History software +// Copyright (C) 2011 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 +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// @author Greg Roach +// @version $Id$ + +if (!defined('WT_WEBTREES')) { + header('HTTP/1.0 403 Forbidden'); + exit; +} + +class WT_Date_Julian extends WT_Date_Calendar { + var $new_old_style=false; + + static function CALENDAR_ESCAPE() { + return '@#DJULIAN@'; + } + + static function NextYear($y) { + if ($y==-1) + return 1; + else + return $y+1; + } + + function IsLeapYear() { + return $this->y%4==0; + } + + static function YMDtoJD($y, $m, $d) { + if ($y<0) // 0=1BC, -1=2BC, etc. + ++$y; + $a=floor((14-$m)/12); + $y=$y+4800-$a; + $m=$m+12*$a-3; + return $d+floor((153*$m+2)/5)+365*$y+floor($y/4)-32083; + } + + static function JDtoYMD($j) { + $c=$j+32082; + $d=floor((4*$c+3)/1461); + $e=$c-floor(1461*$d/4); + $m=floor((5*$e+2)/153); + $day=$e-floor((153*$m+2)/5)+1; + $month=$m+3-12*floor($m/10); + $year=$d-4800+floor($m/10); + if ($year<1) // 0=1BC, -1=2BC, etc. + --$year; + return array($year, $month, $day); + } + + // Process new-style/old-style years and years BC + function ExtractYear($year) { + if (preg_match('/^(\d\d\d\d) \/ \d{1,4}$/', $year, $match)) { // Assume the first year is correct + $this->new_old_style=true; + return $match[1]+1; + } else + if (preg_match('/^(\d+) b ?c$/', $year, $match)) + return -$match[1]; + else + return (int)$year; + } + + function FormatLongYear() { + if ($this->y<0) { + // I18N: Number of years "before christ" + return i18n::translate('%d B.C.', -$this->y); + } else { + if ($this->new_old_style) { + return sprintf('%d/%02d', $this->y-1, $this->y % 100); + } else + return $this->y; + } + } + + function FormatGedcomYear() { + if ($this->y<0) + return sprintf('%04dB.C.', -$this->y); + else + if ($this->new_old_style) { + return sprintf('%04d/%02d', $this->y-1, $this->y % 100); + } else + return sprintf('%04d', $this->y); + } +} diff --git a/library/WT/Date/Roman.php b/library/WT/Date/Roman.php new file mode 100644 index 0000000000..5d04421bff --- /dev/null +++ b/library/WT/Date/Roman.php @@ -0,0 +1,50 @@ +<?php +// Classes for Gedcom Date/Calendar functionality. +// +// Definitions for the Roman calendar +// TODO The 5.5.1 gedcom spec mentions this calendar, but gives no details of +// how it is to be represented.... This class is just a place holder so that +// webtrees won't compain if it receives one. +// +// NOTE: Since different calendars start their days at different times, (civil +// midnight, solar midnight, sunset, sunrise, etc.), we convert on the basis of +// midday. +// +// webtrees: Web based Family History software +// Copyright (C) 2011 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 +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// @author Greg Roach +// @version $Id$ + +if (!defined('WT_WEBTREES')) { + header('HTTP/1.0 403 Forbidden'); + exit; +} + +class WT_Date_Roman extends WT_Date_Calendar { + static function CALENDAR_ESCAPE() { + return '@#DROMAN@'; + } + + function FormatGedcomYear() { + return sprintf('%04dAUC',$this->y); + } + + function FormatLongYear() { + return $this->y.'AUC'; + } +} diff --git a/library/WT/Family.php b/library/WT/Family.php index f64034be22..fdecbeb823 100644 --- a/library/WT/Family.php +++ b/library/WT/Family.php @@ -1,39 +1,33 @@ <?php -/** - * Class file for a Family - * - * webtrees: Web based Family History software - * Copyright (C) 2010 webtrees development team. - * - * Derived from PhpGedView - * Copyright (C) 2002 to 2009 PGV Development Team. All rights reserved. - * - * 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. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * @package webtrees - * @subpackage DataModel - * @version $Id$ - */ +// Class file for a Family +// +// webtrees: Web based Family History software +// Copyright (C) 2011 webtrees development team. +// +// Derived from PhpGedView +// Copyright (C) 2002 to 2009 PGV Development Team. All rights reserved. +// +// 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. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// @version $Id$ if (!defined('WT_WEBTREES')) { header('HTTP/1.0 403 Forbidden'); exit; } -define('WT_WT_FAMILY_PHP', ''); - class WT_Family extends WT_GedcomRecord { private $husb = null; private $wife = null; @@ -170,7 +164,7 @@ class WT_Family extends WT_GedcomRecord { // Static helper function to sort an array of families by marriage date static function CompareMarrDate($x, $y) { - return GedcomDate::Compare($x->getMarriageDate(), $y->getMarriageDate()); + return WT_Date::Compare($x->getMarriageDate(), $y->getMarriageDate()); } /** @@ -295,7 +289,7 @@ class WT_Family extends WT_GedcomRecord { */ function getMarriageDate() { if (!$this->canDisplayDetails()) { - return new GedcomDate(''); + return new WT_Date(''); } if (is_null($this->marriage)) { $this->_parseMarriageRecord(); @@ -310,7 +304,7 @@ class WT_Family extends WT_GedcomRecord { function getMarriageYear($est = true, $cal = '') { // TODO - change the design to use julian days, not gregorian years. $mdate = $this->getMarriageDate(); - $mdate = $mdate->MinDate(); + $mdate = $mdate->WT_Date(); if ($cal) $mdate = $mdate->convert_to_cal($cal); return $mdate->y; } diff --git a/library/WT/GedcomRecord.php b/library/WT/GedcomRecord.php index 9f3180fb07..2116c167e8 100644 --- a/library/WT/GedcomRecord.php +++ b/library/WT/GedcomRecord.php @@ -1,39 +1,33 @@ <?php -/** -* Base class for all gedcom records -* -* webtrees: Web based Family History software - * Copyright (C) 2010 webtrees development team. - * - * Derived from PhpGedView -* Copyright (C) 2002 to 2009 PGV Development Team. All rights reserved. -* -* 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. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @package webtrees -* @subpackage DataModel -* @version $Id$ -*/ +// Base class for all gedcom records +// +// webtrees: Web based Family History software +// Copyright (C) 2011 webtrees development team. +// +// Derived from PhpGedView +// Copyright (C) 2002 to 2009 PGV Development Team. All rights reserved. +// +// 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. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// @version $Id$ if (!defined('WT_WEBTREES')) { header('HTTP/1.0 403 Forbidden'); exit; } -define('WT_WT_GEDCOMRECORD_PHP', ''); - require_once WT_ROOT.'includes/classes/class_event.php'; class WT_GedcomRecord { @@ -494,7 +488,7 @@ class WT_GedcomRecord { static function CompareChanDate($x, $y) { $chan_x = $x->getChangeEvent(); $chan_y = $y->getChangeEvent(); - $tmp=GedcomDate::Compare($chan_x->getDate(), $chan_y->getDate()); + $tmp=WT_Date::Compare($chan_x->getDate(), $chan_y->getDate()); if ($tmp) { return $tmp; } else { diff --git a/library/WT/Media.php b/library/WT/Media.php index 9189d89e95..2624ed120b 100644 --- a/library/WT/Media.php +++ b/library/WT/Media.php @@ -1,41 +1,35 @@ <?php -/** - * Class that defines a media object - * - * webtrees: Web based Family History software - * Copyright (C) 2010 webtrees development team. - * - * Derived from PhpGedView - * Copyright (C) 2002 to 2009 PGV Development Team. All rights reserved. - * - * Modifications Copyright (c) 2010 Greg Roach - * - * 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. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * @package webtrees - * @subpackage Charts - * @version $Id$ - */ +// Class that defines a media object +// +// webtrees: Web based Family History software +// Copyright (C) 2011 webtrees development team. +// +// Derived from PhpGedView +// Copyright (C) 2002 to 2009 PGV Development Team. All rights reserved. +// +// Modifications Copyright (c) 2010 Greg Roach +// +// 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. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// @version $Id$ if (!defined('WT_WEBTREES')) { header('HTTP/1.0 403 Forbidden'); exit; } -define('WT_WT_MEDIA_PHP', ''); - class WT_Media extends WT_GedcomRecord { var $title =null; var $file =null; diff --git a/library/WT/Note.php b/library/WT/Note.php index 002814e360..f2bc1eb034 100644 --- a/library/WT/Note.php +++ b/library/WT/Note.php @@ -1,39 +1,33 @@ <?php -/** - * Class file for a Shared Note (NOTE) object - * - * webtrees: Web based Family History software - * Copyright (C) 2010 webtrees development team. - * - * Derived from PhpGedView - * Copyright (C) 2009 PGV Development Team. All rights reserved. - * - * 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. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * @package webtrees - * @subpackage DataModel - * @version $Id$ - */ +// Class file for a Shared Note (NOTE) object +// +// webtrees: Web based Family History software +// Copyright (C) 2011 webtrees development team. +// +// Derived from PhpGedView +// Copyright (C) 2009 PGV Development Team. All rights reserved. +// +// 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. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// @version $Id$ if (!defined('WT_WEBTREES')) { header('HTTP/1.0 403 Forbidden'); exit; } -define('WT_WT_NOTE_PHP', ''); - class WT_Note extends WT_GedcomRecord { // Generate a URL to this record, suitable for use in HTML public function getHtmlUrl() { diff --git a/library/WT/Person.php b/library/WT/Person.php index a482d3d629..31101f9335 100644 --- a/library/WT/Person.php +++ b/library/WT/Person.php @@ -1,39 +1,33 @@ <?php -/** -* Class file for a person -* -* webtrees: Web based Family History software - * Copyright (C) 2010 webtrees development team. - * - * Derived from PhpGedView -* Copyright (C) 2002 to 2009 PGV Development Team. All rights reserved. -* -* 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. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @package webtrees -* @subpackage DataModel -* @version $Id$ -*/ +// Class file for a person +// +// webtrees: Web based Family History software +// Copyright (C) 2011 webtrees development team. +// +// Derived from PhpGedView +// Copyright (C) 2002 to 2009 PGV Development Team. All rights reserved. +// +// 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. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// @version $Id$ if (!defined('WT_WEBTREES')) { header('HTTP/1.0 403 Forbidden'); exit; } -define('WT_WT_PERSON_PHP', ''); - require_once WT_ROOT.'includes/classes/class_event.php'; class WT_Person extends WT_GedcomRecord { @@ -83,12 +77,12 @@ class WT_Person extends WT_GedcomRecord { // Static helper function to sort an array of people by birth date static function CompareBirtDate($x, $y) { - return GedcomDate::Compare($x->getEstimatedBirthDate(), $y->getEstimatedBirthDate()); + return WT_Date::Compare($x->getEstimatedBirthDate(), $y->getEstimatedBirthDate()); } // Static helper function to sort an array of people by death date static function CompareDeatDate($x, $y) { - return GedcomDate::Compare($x->getEstimatedDeathDate(), $y->getEstimatedDeathDate()); + return WT_Date::Compare($x->getEstimatedDeathDate(), $y->getEstimatedDeathDate()); } /** @@ -130,10 +124,10 @@ class WT_Person extends WT_GedcomRecord { } } if (is_null($this->_getBirthDate)) { - $this->_getBirthDate=new GedcomDate(''); + $this->_getBirthDate=new WT_Date(''); } } else { - $this->_getBirthDate=new GedcomDate("(".i18n::translate('Private').")"); + $this->_getBirthDate=new WT_Date("(".i18n::translate('Private').")"); } } return $this->_getBirthDate; @@ -213,10 +207,10 @@ class WT_Person extends WT_GedcomRecord { } } if (is_null($this->_getDeathDate)) { - $this->_getDeathDate=new GedcomDate(''); + $this->_getDeathDate=new WT_Date(''); } } else { - $this->_getDeathDate=new GedcomDate("(".i18n::translate('Private').")"); + $this->_getDeathDate=new WT_Date("(".i18n::translate('Private').")"); } } return $this->_getDeathDate; @@ -267,7 +261,7 @@ class WT_Person extends WT_GedcomRecord { if ($age_at_death && $this->getBirthYear() && empty($this->getBirthDate()->qual1) && $this->getDeathYear() && empty($this->getDeathDate()->qual1)) { - $age = get_age_at_event(GedcomDate::GetAgeGedcom($this->getBirthDate(), $this->getDeathDate()), false); + $age = get_age_at_event(WT_Date::GetAgeGedcom($this->getBirthDate(), $this->getDeathDate()), false); if (!empty($age)) { $tmp .= '<span class="age"> ('.i18n::translate('Age').' '.$age.')</span>'; } @@ -404,10 +398,10 @@ class WT_Person extends WT_GedcomRecord { } } if ($min && $max) { - list($y)=GregorianDate::JDtoYMD(floor((max($min)+min($max))/2)); - $this->_getEstimatedBirthDate=new GedcomDate("EST {$y}"); + list($y)=WT_Date_Gregorian::JDtoYMD(floor((max($min)+min($max))/2)); + $this->_getEstimatedBirthDate=new WT_Date("EST {$y}"); } else { - $this->_getEstimatedBirthDate=new GedcomDate(''); // always return a date object + $this->_getEstimatedBirthDate=new WT_Date(''); // always return a date object } } } @@ -429,10 +423,10 @@ class WT_Person extends WT_GedcomRecord { if ($tmp2->MaxJD()<WT_SERVER_JD) { $this->_getEstimatedDeathDate=$tmp2; } else { - $this->_getEstimatedDeathDate=new GedcomDate(''); // always return a date object + $this->_getEstimatedDeathDate=new WT_Date(''); // always return a date object } } else { - $this->_getEstimatedDeathDate=new GedcomDate(''); // always return a date object + $this->_getEstimatedDeathDate=new WT_Date(''); // always return a date object } } } @@ -987,7 +981,7 @@ class WT_Person extends WT_GedcomRecord { if (strstr($SHOW_RELATIVES_EVENTS, '_DEAT'.($sosa==1 ? '_PARE' : '_GPAR'))) { foreach ($parent->getAllFactsByType(explode('|', WT_EVENTS_DEAT)) as $sEvent) { $srec = $sEvent->getGedcomRecord(); - if (GedcomDate::Compare($bDate, $sEvent->getDate())<0 && GedcomDate::Compare($sEvent->getDate(), $dDate)<=0) { + if (WT_Date::Compare($bDate, $sEvent->getDate())<0 && WT_Date::Compare($sEvent->getDate(), $dDate)<=0) { switch ($sosa) { case 1: $factrec='1 _'.$sEvent->getTag().'_PARE'; @@ -1045,7 +1039,7 @@ class WT_Person extends WT_GedcomRecord { if (strstr($SHOW_RELATIVES_EVENTS, '_MARR_PARE')) { $sEvent = $sfamily->getMarriage(); $srec = $sEvent->getGedcomRecord(); - if (GedcomDate::Compare($bDate, $sEvent->getDate())<0 && GedcomDate::Compare($sEvent->getDate(), $dDate)<=0) { + if (WT_Date::Compare($bDate, $sEvent->getDate())<0 && WT_Date::Compare($sEvent->getDate(), $dDate)<=0) { $factrec = '1 '.$fact; $factrec.="\n".get_sub_record(2, '2 DATE', $srec)."\n".get_sub_record(2, '2 PLAC', $srec); $factrec .= "\n2 ASSO @".$parent->getXref().'@'; @@ -1122,7 +1116,7 @@ class WT_Person extends WT_GedcomRecord { $srec = $sEvent->getGedcomRecord(); $sgdate=$sEvent->getDate(); // Always show _BIRT_CHIL, even if the dates are not known - if ($option=='_CHIL' || $sgdate->isOK() && GedcomDate::Compare($this->getEstimatedBirthDate(), $sgdate)<=0 && GedcomDate::Compare($sgdate, $this->getEstimatedDeathDate())<=0) { + if ($option=='_CHIL' || $sgdate->isOK() && WT_Date::Compare($this->getEstimatedBirthDate(), $sgdate)<=0 && WT_Date::Compare($sgdate, $this->getEstimatedDeathDate())<=0) { $factrec='1 _'.$sEvent->getTag(); if ($option=='_GCHI' && $relation=='son') { $factrec.='_GCH1'; @@ -1149,7 +1143,7 @@ class WT_Person extends WT_GedcomRecord { foreach ($child->getAllFactsByType(explode('|', WT_EVENTS_DEAT)) as $sEvent) { $sgdate=$sEvent->getDate(); $srec = $sEvent->getGedcomRecord(); - if ($sgdate->isOK() && GedcomDate::Compare($this->getEstimatedBirthDate(), $sgdate)<=0 && GedcomDate::Compare($sgdate, $this->getEstimatedDeathDate())<=0) { + if ($sgdate->isOK() && WT_Date::Compare($this->getEstimatedBirthDate(), $sgdate)<=0 && WT_Date::Compare($sgdate, $this->getEstimatedDeathDate())<=0) { $factrec='1 _'.$sEvent->getTag(); if ($option=='_GCHI' && $relation=='son') { $factrec.='_GCH1'; @@ -1177,7 +1171,7 @@ class WT_Person extends WT_GedcomRecord { $sEvent = $sfamily->getMarriage(); $sgdate=$sEvent->getDate(); $srec = $sEvent->getGedcomRecord(); - if ($sgdate->isOK() && GedcomDate::Compare($this->getEstimatedBirthDate(), $sgdate)<=0 && GedcomDate::Compare($sgdate, $this->getEstimatedDeathDate())<=0) { + if ($sgdate->isOK() && WT_Date::Compare($this->getEstimatedBirthDate(), $sgdate)<=0 && WT_Date::Compare($sgdate, $this->getEstimatedDeathDate())<=0) { $factrec='1 _'.$sEvent->getTag(); if ($option=='_GCHI' && $relation=='son') { $factrec.='_GCH1'; @@ -1233,7 +1227,7 @@ class WT_Person extends WT_GedcomRecord { foreach ($spouse->getAllFactsByType(explode('|', WT_EVENTS_DEAT)) as $sEvent) { $sdate=$sEvent->getDate(); $srec = $sEvent->getGedcomRecord(); - if ($sdate->isOK() && GedcomDate::Compare($this->getEstimatedBirthDate(), $sdate)<=0 && GedcomDate::Compare($sdate, $this->getEstimatedDeathDate())<=0) { + if ($sdate->isOK() && WT_Date::Compare($this->getEstimatedBirthDate(), $sdate)<=0 && WT_Date::Compare($sdate, $this->getEstimatedDeathDate())<=0) { $srec=preg_replace('/^1 .*/', '1 _'.$sEvent->getTag().'_SPOU ', $srec); $srec.="\n".get_sub_record(2, '2 ASSO @'.$this->xref.'@', $srec); switch ($spouse->getSex()) { @@ -1276,7 +1270,7 @@ class WT_Person extends WT_GedcomRecord { require get_site_setting('INDEX_DIRECTORY').'histo.'.WT_LOCALE.'.php'; foreach ($histo as $indexval=>$hrec) { $sdate=new GedcomDate(get_gedcom_value('DATE', 2, $hrec, '', false)); - if ($sdate->isOK() && GedcomDate::Compare($this->getEstimatedBirthDate(), $sdate)<=0 && GedcomDate::Compare($sdate, $this->getEstimatedDeathDate())<=0) { + if ($sdate->isOK() && WT_Date::Compare($this->getEstimatedBirthDate(), $sdate)<=0 && WT_Date::Compare($sdate, $this->getEstimatedDeathDate())<=0) { $event = new Event($hrec); $event->setParentObject($this); $this->indifacts[] = $event; diff --git a/library/WT/Repository.php b/library/WT/Repository.php index b24a52e478..530229ea2c 100644 --- a/library/WT/Repository.php +++ b/library/WT/Repository.php @@ -1,39 +1,33 @@ <?php -/** - * Class file for a Repository (REPO) object - * - * webtrees: Web based Family History software - * Copyright (C) 2010 webtrees development team. - * - * Derived from PhpGedView - * Copyright (C) 2002 to 2009 PGV Development Team. All rights reserved. - * - * 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. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * @package webtrees - * @subpackage DataModel - * @version $Id$ - */ +// Class file for a Repository (REPO) object +// +// webtrees: Web based Family History software +// Copyright (C) 2011 webtrees development team. +// +// Derived from PhpGedView +// Copyright (C) 2002 to 2009 PGV Development Team. All rights reserved. +// +// 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. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// @version $Id$ if (!defined('WT_WEBTREES')) { header('HTTP/1.0 403 Forbidden'); exit; } -define('WT_WT_REPOSITORY_PHP', ''); - class WT_Repository extends WT_GedcomRecord { // Generate a URL to this record, suitable for use in HTML public function getHtmlUrl() { diff --git a/library/WT/Source.php b/library/WT/Source.php index 976c9e2036..d7e8bd87b9 100644 --- a/library/WT/Source.php +++ b/library/WT/Source.php @@ -1,44 +1,34 @@ <?php -/** - * Class file for a Source (SOUR) object - * - * webtrees: Web based Family History software - * Copyright (C) 2010 webtrees development team. - * - * Derived from PhpGedView - * Copyright (C) 2002 to 2009 PGV Development Team. All rights reserved. - * - * 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. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * @package webtrees - * @subpackage DataModel - * @version $Id$ - */ +// Class file for a Source (SOUR) object +// +// webtrees: Web based Family History software +// Copyright (C) 2011 webtrees development team. +// +// Derived from PhpGedView +// Copyright (C) 2002 to 2009 PGV Development Team. All rights reserved. +// +// 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. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// @version $Id$ if (!defined('WT_WEBTREES')) { header('HTTP/1.0 403 Forbidden'); exit; } -define('WT_WT_SOURCE_PHP', ''); - class WT_Source extends WT_GedcomRecord { - /** - * get the author of this source record - * @return string - */ public function getAuth() { return get_gedcom_value('AUTH', 1, $this->gedrec, '', false); } diff --git a/modules/GEDFact_assistant/CENS_ctrl.php b/modules/GEDFact_assistant/CENS_ctrl.php index 0712d09572..6ac4f0c555 100644 --- a/modules/GEDFact_assistant/CENS_ctrl.php +++ b/modules/GEDFact_assistant/CENS_ctrl.php @@ -45,7 +45,7 @@ global $SEARCH_SPIDER, $GOOGLEMAP_PH_CONTROLS; if (!($controller->indi->isDead())) { // If alive display age $bdate=$controller->indi->getBirthDate(); - $age = GedcomDate::GetAgeGedcom($bdate); + $age = WT_Date::GetAgeGedcom($bdate); if ($age!="") $summary.= "<span class=\"label\">".i18n::translate('Age').":</span><span class=\"field\"> ".get_age_at_event($age, true)."</span>"; } diff --git a/modules/GEDFact_assistant/MEDIA_ctrl.php b/modules/GEDFact_assistant/MEDIA_ctrl.php index 346afd82da..fcadb624f7 100644 --- a/modules/GEDFact_assistant/MEDIA_ctrl.php +++ b/modules/GEDFact_assistant/MEDIA_ctrl.php @@ -48,7 +48,7 @@ global $SEARCH_SPIDER, $GOOGLEMAP_PH_CONTROLS; if (!($controller->indi->isDead())) { // If alive display age $bdate=$controller->indi->getBirthDate(); - $age = GedcomDate::GetAgeGedcom($bdate); + $age = WT_Date::GetAgeGedcom($bdate); //if ($age!="") { //$summary.= "<span class=\"label\">".i18n::translate('Age').":</span><span class=\"field\"> ".get_age_at_event($age, true)."</span>"; //} diff --git a/modules/GEDFact_assistant/_CENS/census_1_ctrl.php b/modules/GEDFact_assistant/_CENS/census_1_ctrl.php index 2f2957bc01..c9bf0e01f1 100644 --- a/modules/GEDFact_assistant/_CENS/census_1_ctrl.php +++ b/modules/GEDFact_assistant/_CENS/census_1_ctrl.php @@ -38,11 +38,11 @@ global $summary, $theme_name, $censyear, $censdate; $pid = safe_get('pid'); -$censdate = new GedcomDate("31 MAR 1901"); +$censdate = new WT_Date("31 MAR 1901"); $censyear = $censdate->date1->y; $ctry = "UK"; -// $married = GedcomDate::Compare($censdate, $marrdate); +// $married = WT_Date::Compare($censdate, $marrdate); // === Set $married to "Not married as we only want the Birth name here" === $married=-1; diff --git a/modules/GEDFact_assistant/_CENS/census_3_search_add.php b/modules/GEDFact_assistant/_CENS/census_3_search_add.php index 82fb2e439d..e4cc76b15e 100644 --- a/modules/GEDFact_assistant/_CENS/census_3_search_add.php +++ b/modules/GEDFact_assistant/_CENS/census_3_search_add.php @@ -152,7 +152,7 @@ if (!defined('WT_WEBTREES')) { } //-- Parents Husbands Details -------------------------------------- - $married = GedcomDate::Compare($censdate, $marrdate); + $married = WT_Date::Compare($censdate, $marrdate); $nam = $people["husb"]->getAllNames(); $fulln = rtrim($nam[0]['givn'],'*')." ".$nam[0]['surname']; $fulln = str_replace("@N.N.", "(".i18n::translate('unknown').")", $fulln); @@ -276,7 +276,7 @@ if (!defined('WT_WEBTREES')) { } //-- Wifes Details -------------------------------------- - $married = GedcomDate::Compare($censdate, $marrdate); + $married = WT_Date::Compare($censdate, $marrdate); $nam = $people["wife"]->getAllNames(); $fulln = rtrim($nam[0]['givn'],'*')." ".$nam[0]['surname']; $fulln = str_replace("@N.N.", "(".i18n::translate('unknown').")", $fulln); @@ -423,7 +423,7 @@ if (!defined('WT_WEBTREES')) { $marrdate=""; foreach ($child->getSpouseFamilies() as $childfamily) { $marrdate=$childfamily->getMarriageDate(); - $married = GedcomDate::Compare($censdate, $marrdate); + $married = WT_Date::Compare($censdate, $marrdate); } $nam = $child->getAllNames(); $fulln = rtrim($nam[0]['givn'],'*')." ".$nam[0]['surname']; @@ -599,7 +599,7 @@ if (!defined('WT_WEBTREES')) { } //-- Step Husbands Details -------------------------------------- - $married = GedcomDate::Compare($censdate, $marrdate); + $married = WT_Date::Compare($censdate, $marrdate); $nam = $people["husb"]->getAllNames(); $fulln = rtrim($nam[0]['givn'],'*')." ".$nam[0]['surname']; $fulln = str_replace("@N.N.", "(".i18n::translate('unknown').")", $fulln); @@ -735,7 +735,7 @@ if (!defined('WT_WEBTREES')) { } //-- Step Wifes Details -------------------------------------- - $married = GedcomDate::Compare($censdate, $marrdate); + $married = WT_Date::Compare($censdate, $marrdate); $nam = $people["wife"]->getAllNames(); $fulln = rtrim($nam[0]['givn'],'*')." ".$nam[0]['surname']; $fulln = str_replace("@N.N.", "(".i18n::translate('unknown').")", $fulln); @@ -1042,7 +1042,7 @@ if (!defined('WT_WEBTREES')) { } //-- Spouse Husbands Details -------------------------------------- - $married = GedcomDate::Compare($censdate, $marrdate); + $married = WT_Date::Compare($censdate, $marrdate); $nam = $people["husb"]->getAllNames(); $fulln = rtrim($nam[0]['givn'],'*')." ".$nam[0]['surname']; $fulln = str_replace("@N.N.", "(".i18n::translate('unknown').")", $fulln); @@ -1177,7 +1177,7 @@ if (!defined('WT_WEBTREES')) { } //-- Spouse Wifes Details -------------------------------------- - $married = GedcomDate::Compare($censdate, $marrdate); + $married = WT_Date::Compare($censdate, $marrdate); $nam = $people["wife"]->getAllNames(); $fulln = rtrim($nam[0]['givn'],'*')." ".$nam[0]['surname']; //$fulln = str_replace('"', '\"', $fulln); @@ -1315,7 +1315,7 @@ if (!defined('WT_WEBTREES')) { $marrdate=""; foreach ($child->getSpouseFamilies() as $childfamily) { $marrdate=$childfamily->getMarriageDate(); - $married = GedcomDate::Compare($censdate, $marrdate); + $married = WT_Date::Compare($censdate, $marrdate); } // Get Child's Children @@ -1532,7 +1532,7 @@ function print_pedigree_person_nav2($pid, $style=1, $count=0, $personcount="1", $fams = $person->getChildFamilies(); foreach ($fams as $famid=>$family) { $marrdate = $family->getMarriageDate(); - $married = GedcomDate::Compare($censdate, $marrdate); + $married = WT_Date::Compare($censdate, $marrdate); if (!is_null($family)) { $husb = $family->getHusband($person); @@ -1677,7 +1677,7 @@ function print_pedigree_person_nav2($pid, $style=1, $count=0, $personcount="1", } $tmp=$wife->getXref(); if ($wife->canDisplayName()) { - $married = GedcomDate::Compare($censdate, $marrdate); + $married = WT_Date::Compare($censdate, $marrdate); $nam = $wife->getAllNames(); $fulln = rtrim($nam[0]['givn'],'*')." ".$nam[0]['surname']; $fulln = str_replace("@N.N.", "(".i18n::translate('unknown').")", $fulln); @@ -1760,7 +1760,7 @@ function print_pedigree_person_nav2($pid, $style=1, $count=0, $personcount="1", $fams = $person->getStepFamilies(); foreach ($fams as $famid=>$family) { $marrdate = $family->getMarriageDate(); - $married = GedcomDate::Compare($censdate, $marrdate); + $married = WT_Date::Compare($censdate, $marrdate); if (!is_null($family)) { $husb = $family->getHusband($person); $wife = $family->getWife($person); @@ -1909,7 +1909,7 @@ function print_pedigree_person_nav2($pid, $style=1, $count=0, $personcount="1", } $tmp=$wife->getXref(); if ($wife->canDisplayName()) { - $married = GedcomDate::Compare($censdate, $marrdate); + $married = WT_Date::Compare($censdate, $marrdate); $nam = $wife->getAllNames(); $fulln = rtrim($nam[0]['givn'],'*')." ".$nam[0]['surname']; $fulln = str_replace("@N.N.", "(".i18n::translate('unknown').")", $fulln); @@ -1997,7 +1997,7 @@ function print_pedigree_person_nav2($pid, $style=1, $count=0, $personcount="1", $children = $family->getChildren(); $num = count($children); $marrdate = $family->getMarriageDate(); - $married = GedcomDate::Compare($censdate, $marrdate); + $married = WT_Date::Compare($censdate, $marrdate); $is_wife = $family->getWife(); //-- Get Spouse's Children's Name, DOB, DOD -------------------------- @@ -2045,7 +2045,7 @@ function print_pedigree_person_nav2($pid, $style=1, $count=0, $personcount="1", } $tmp=$spouse->getXref(); if ($spouse->canDisplayName()) { - $married = GedcomDate::Compare($censdate, $marrdate); + $married = WT_Date::Compare($censdate, $marrdate); $nam = $spouse->getAllNames(); $fulln = rtrim($nam[0]['givn'],'*')." ".$nam[0]['surname']; $fulln = str_replace("@N.N.", "(".i18n::translate('unknown').")", $fulln); @@ -2169,7 +2169,7 @@ function print_pedigree_person_nav2($pid, $style=1, $count=0, $personcount="1", $chhusbnam=null; foreach ($child->getSpouseFamilies() as $childfamily) { $marrdate=$childfamily->getMarriageDate(); - $married = GedcomDate::Compare($censdate, $marrdate); + $married = WT_Date::Compare($censdate, $marrdate); if ($childfamily->getHusband()) { $chhusbnam = $childfamily->getHusband()->getAllNames(); } diff --git a/modules/GEDFact_assistant/_MEDIA/media_1_ctrl.php b/modules/GEDFact_assistant/_MEDIA/media_1_ctrl.php index c74015fb69..7466201480 100644 --- a/modules/GEDFact_assistant/_MEDIA/media_1_ctrl.php +++ b/modules/GEDFact_assistant/_MEDIA/media_1_ctrl.php @@ -45,7 +45,7 @@ $censevent = new Event("1 CENS\n2 DATE 03 MAR".$year.""); $censdate = $censevent->getDate(); $censyear = $censdate->date1->y; $ctry = "UK"; -// $married = GedcomDate::Compare($censdate, $marrdate); +// $married = WT_Date::Compare($censdate, $marrdate); $married=-1; diff --git a/modules/GEDFact_assistant/_MEDIA/media_3_search_add.php b/modules/GEDFact_assistant/_MEDIA/media_3_search_add.php index e100d14037..1e36ec43c0 100644 --- a/modules/GEDFact_assistant/_MEDIA/media_3_search_add.php +++ b/modules/GEDFact_assistant/_MEDIA/media_3_search_add.php @@ -121,7 +121,7 @@ if (!defined('WT_WEBTREES')) { // Husband ------------------- $styleadd = ""; if (isset($people["husb"])) { - $married = GedcomDate::Compare($censdate, $marrdate); + $married = WT_Date::Compare($censdate, $marrdate); $nam = $people["husb"]->getAllNames(); $fulln = rtrim($nam[0]['givn'],'*')." ".$nam[0]['surname']; $givn = rtrim($nam[0]['givn'],'*'); @@ -201,7 +201,7 @@ if (!defined('WT_WEBTREES')) { } if (isset($people["wife"])) { - $married = GedcomDate::Compare($censdate, $marrdate); + $married = WT_Date::Compare($censdate, $marrdate); $nam = $people["wife"]->getAllNames(); $fulln = rtrim($nam[0]['givn'],'*')." ".$nam[0]['surname']; $givn = rtrim($nam[0]['givn'],'*'); @@ -297,7 +297,7 @@ if (!defined('WT_WEBTREES')) { $married=""; foreach ($child->getSpouseFamilies() as $childfamily) { $tmp=$childfamily->getMarriageDate(); - $married = GedcomDate::Compare($censdate, $tmp); + $married = WT_Date::Compare($censdate, $tmp); } $nam = $child->getAllNames(); $fulln = rtrim($nam[0]['givn'],'*')." ".$nam[0]['surname']; @@ -416,7 +416,7 @@ if (!defined('WT_WEBTREES')) { $styleadd = ""; $elderdate = ""; if (isset($people["husb"]) ) { - $married = GedcomDate::Compare($censdate, $marrdate); + $married = WT_Date::Compare($censdate, $marrdate); $nam = $people["husb"]->getAllNames(); $fulln = rtrim($nam[0]['givn'],'*')." ".$nam[0]['surname']; $givn = rtrim($nam[0]['givn'],'*'); @@ -507,7 +507,7 @@ if (!defined('WT_WEBTREES')) { // Wife ------------------- $styleadd = ""; if (isset($people["wife"]) ) { - $married = GedcomDate::Compare($censdate, $marrdate); + $married = WT_Date::Compare($censdate, $marrdate); $nam = $people["wife"]->getAllNames(); $fulln = rtrim($nam[0]['givn'],'*')." ".$nam[0]['surname']; $givn = rtrim($nam[0]['givn'],'*'); @@ -699,7 +699,7 @@ if (!defined('WT_WEBTREES')) { // Husband ------------------- if (isset($people["husb"])) { - $married = GedcomDate::Compare($censdate, $marrdate); + $married = WT_Date::Compare($censdate, $marrdate); $nam = $people["husb"]->getAllNames(); $fulln = rtrim($nam[0]['givn'],'*')." ".$nam[0]['surname']; $givn = rtrim($nam[0]['givn'],'*'); @@ -792,7 +792,7 @@ if (!defined('WT_WEBTREES')) { // Wife ------------------- //if (isset($people["wife"]) && $spousetag == 'WIFE') { if (isset($people["wife"])) { - $married = GedcomDate::Compare($censdate, $marrdate); + $married = WT_Date::Compare($censdate, $marrdate); $nam = $people["wife"]->getAllNames(); $fulln = rtrim($nam[0]['givn'],'*')." ".$nam[0]['surname']; $givn = rtrim($nam[0]['givn'],'*'); @@ -897,7 +897,7 @@ if (!defined('WT_WEBTREES')) { $married=""; foreach ($child->getSpouseFamilies() as $childfamily) { $tmp=$childfamily->getMarriageDate(); - $married = GedcomDate::Compare($censdate, $tmp); + $married = WT_Date::Compare($censdate, $tmp); } $nam = $child->getAllNames(); $fulln = rtrim($nam[0]['givn'],'*')." ".$nam[0]['surname']; @@ -1145,7 +1145,7 @@ function print_pedigree_person_nav2($pid, $style=1, $count=0, $personcount="1", } $tmp=$wife->getXref(); if ($wife->canDisplayName()) { - $married = GedcomDate::Compare($censdate, $marrdate); + $married = WT_Date::Compare($censdate, $marrdate); $nam = $wife->getAllNames(); $fulln = rtrim($nam[0]['givn'],'*')." ".$nam[0]['surname']; $givn = rtrim($nam[0]['givn'],'*'); @@ -1268,7 +1268,7 @@ function print_pedigree_person_nav2($pid, $style=1, $count=0, $personcount="1", } $tmp=$wife->getXref(); if ($wife->canDisplayName()) { - $married = GedcomDate::Compare($censdate, $marrdate); + $married = WT_Date::Compare($censdate, $marrdate); $nam = $wife->getAllNames(); $fulln = rtrim($nam[0]['givn'],'*')." ".$nam[0]['surname']; $givn = rtrim($nam[0]['givn'],'*'); @@ -1314,7 +1314,7 @@ function print_pedigree_person_nav2($pid, $style=1, $count=0, $personcount="1", } $tmp=$spouse->getXref(); if ($spouse->canDisplayName()) { - $married = GedcomDate::Compare($censdate, $marrdate); + $married = WT_Date::Compare($censdate, $marrdate); $nam = $spouse->getAllNames(); $fulln = rtrim($nam[0]['givn'],'*')." ".$nam[0]['surname']; $givn = rtrim($nam[0]['givn'],'*'); diff --git a/modules/googlemap/googlemap.php b/modules/googlemap/googlemap.php index 8e7148ade7..0f0b8613a4 100644 --- a/modules/googlemap/googlemap.php +++ b/modules/googlemap/googlemap.php @@ -338,7 +338,7 @@ function tool_tip_text($marker) { } } if (!empty($marker['date'])) { - $date=new GedcomDate($marker['date']); + $date=new WT_Date($marker['date']); $tool_tip.=" - ".$date->Display(false); } return $tool_tip; @@ -694,7 +694,7 @@ function build_indiv_map($indifacts, $famids) { echo preg_replace("/\"/", "\\\"", print_fact_place_map($markers[$j]["placerec"])); } if (!empty($markers[$j]["date"])) { - $date=new GedcomDate($markers[$j]["date"]); + $date=new WT_Date($markers[$j]["date"]); echo "<br />", addslashes($date->Display(true)); } if (($markers[$j]["lati"] == NULL) || ($markers[$j]["lng"] == NULL) || (($markers[$j]["lati"] == "0") && ($markers[$j]["lng"] == "0"))) { @@ -754,7 +754,7 @@ function build_indiv_map($indifacts, $famids) { echo preg_replace("/\"/", "\\\"", print_fact_place_map($markers[$j]["placerec"])); } if (!empty($markers[$j]["date"])) { - $date=new GedcomDate($markers[$j]["date"]); + $date=new WT_Date($markers[$j]["date"]); echo "<br />", addslashes($date->Display(true)); } if (!$GOOGLEMAP_COORD) { @@ -820,7 +820,7 @@ function build_indiv_map($indifacts, $famids) { echo preg_replace("/\"/", "\\\"", print_fact_place_map($markers[$k]["placerec"])); } if (!empty($markers[$k]["date"])) { - $date=new GedcomDate($markers[$k]["date"]); + $date=new WT_Date($markers[$k]["date"]); echo "<br />", addslashes($date->Display(true)); } if (!$GOOGLEMAP_COORD) { @@ -869,7 +869,7 @@ function build_indiv_map($indifacts, $famids) { echo print_fact_place_map($marker["placerec"]), "<br />"; } if (!empty($marker['date'])) { - $date=new GedcomDate($marker['date']); + $date=new WT_Date($marker['date']); echo $date->Display(true), "<br />"; } echo "</td></tr>"; diff --git a/modules/relatives/module.php b/modules/relatives/module.php index 3f489fb0b4..5fd1187b53 100644 --- a/modules/relatives/module.php +++ b/modules/relatives/module.php @@ -181,7 +181,7 @@ class relatives_WT_Module extends WT_Module implements WT_Module_Tab { if (!$date && $this->controller->show_changes && ($famrec = find_updated_record($famid))!==null) { $marrrec = get_sub_record(1, "1 MARR", $famrec); if ($marrrec!=$family->getMarriageRecord()) { - $date = new GedcomDate(get_gedcom_value("MARR:DATE", 1, $marrrec, '', false)); + $date = new WT_Date(get_gedcom_value("MARR:DATE", 1, $marrrec, '', false)); $place = get_gedcom_value("MARR:PLAC", 1, $marrrec, '', false); $styleadd = "blue"; } diff --git a/modules/yahrzeit/module.php b/modules/yahrzeit/module.php index f6958ab19f..662597178a 100644 --- a/modules/yahrzeit/module.php +++ b/modules/yahrzeit/module.php @@ -89,24 +89,24 @@ class yahrzeit_WT_Module extends WT_Module implements WT_Module_Block { // ...then adjust dates foreach ($yahrzeits as $key=>$yahrzeit) { if (strpos('1 DEAT', $yahrzeit['factrec'])!==false) { // Just DEAT, not _YART - $today=new JewishDate($yahrzeit['jd']); + $today=new WT_Date_Jewish($yahrzeit['jd']); $hd=$yahrzeit['date']->MinDate(); - $hd1=new JewishDate($hd); + $hd1=new WT_Date_Jewish($hd); $hd1->y+=1; $hd1->SetJDFromYMD(); // Special rules. See http://www.hebcal.com/help/anniv.html // Everything else is taken care of by our standard anniversary rules. if ($hd->d==30 && $hd->m==2 && $hd->y!=0 && $hd1->DaysInMonth()<30) { // 30 CSH // Last day in CSH - $yahrzeit[$key]['jd']=JewishDate::YMDtoJD($today->y, 3, 1)-1; + $yahrzeit[$key]['jd']=WT_Date_Jewish::YMDtoJD($today->y, 3, 1)-1; } if ($hd->d==30 && $hd->m==3 && $hd->y!=0 && $hd1->DaysInMonth()<30) { // 30 KSL // Last day in KSL - $yahrzeit[$key]['jd']=JewishDate::YMDtoJD($today->y, 4, 1)-1; + $yahrzeit[$key]['jd']=WT_Date_Jewish::YMDtoJD($today->y, 4, 1)-1; } if ($hd->d==30 && $hd->m==6 && $hd->y!=0 && $today->DaysInMonth()<30 && !$today->IsLeapYear()) { // 30 ADR // Last day in SHV - $yahrzeit[$key]['jd']=JewishDate::YMDtoJD($today->y, 6, 1)-1; + $yahrzeit[$key]['jd']=WT_Date_Jewish::YMDtoJD($today->y, 6, 1)-1; } } } @@ -160,8 +160,8 @@ class yahrzeit_WT_Module extends WT_Module implements WT_Module_Block { $content .= $exp[1]; $content .= "</td>"; - $today=new JewishDate($yahrzeit['jd']); - $td=new GedcomDate($today->Format('%@ %A %O %E')); + $today=new WT_Date_Jewish($yahrzeit['jd']); + $td=new WT_Date($today->Format('%@ %A %O %E')); // death/yahrzeit event date $content .= "<td class=\"list_value_wrap\">"; diff --git a/statisticsplot.php b/statisticsplot.php index 21df89e1d3..ab2bdb0672 100644 --- a/statisticsplot.php +++ b/statisticsplot.php @@ -717,7 +717,7 @@ function set_params($current, $indfam, $xg, $zg, $titstr, $xt, $yt, $gx, $gz, $m $monthdata= array(); for ($i=0; $i<12; ++$i) { - $monthdata[$i]=GregorianDate::NUM_TO_MONTH_NOMINATIVE($i+1, false); + $monthdata[$i]=WT_Date_Gregorian::NUM_TO_MONTH_NOMINATIVE($i+1, false); } |
