summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfisharebest <fisharebest@gmail.com>2013-07-22 21:35:13 +0000
committerfisharebest <fisharebest@gmail.com>2013-07-22 21:35:13 +0000
commit57c5ddda3a446f75afcda4c8f16620100aed4769 (patch)
tree2cea597949e563a84b5e702a13eda7b016130f4a
parentde2d6648c48b35630a4c3cd700a3903a1e0d91c5 (diff)
downloadwebtrees-57c5ddda3a446f75afcda4c8f16620100aed4769.tar.gz
webtrees-57c5ddda3a446f75afcda4c8f16620100aed4769.tar.bz2
webtrees-57c5ddda3a446f75afcda4c8f16620100aed4769.zip
#1203239 - Handling of Old Style Gregorian Dates
-rw-r--r--calendar.php17
-rw-r--r--library/WT/Date.php6
-rw-r--r--library/WT/Date/Calendar.php38
-rw-r--r--library/WT/Date/French.php2
-rw-r--r--library/WT/Date/Julian.php18
-rw-r--r--library/WT/Date/Roman.php4
6 files changed, 47 insertions, 38 deletions
diff --git a/calendar.php b/calendar.php
index 7c86b7ca69..a7d0c0e117 100644
--- a/calendar.php
+++ b/calendar.php
@@ -34,9 +34,9 @@ $controller->setPageTitle(WT_I18N::translate('Anniversary calendar'));
$controller->pageHeader();
$cal =safe_GET('cal', '@#D[A-Z ]+@');
-$day =safe_GET('day', '[0-9]+');
+$day =safe_GET('day', '\d\d?');
$month =safe_GET('month', '[A-Z]{3,5}');
-$year =safe_GET('year', '[0-9]+(-[0-9]+|[?]+)?');
+$year =safe_GET('year', '\d{1,4}(?: B\.C\.)?|\d\d\d\d\/\d\d|\d+(-\d+|[?]+)?');
$action =safe_GET('action', array('year', 'today', 'calendar'), 'today');
$filterev=safe_GET('filterev', array('all', 'bdm', WT_REGEX_TAG), 'bdm');
$filterof=safe_GET('filterof', array('all', 'living', 'recent'), 'all');
@@ -54,13 +54,19 @@ if ($cal.$day.$month.$year=='') {
// Create a WT_Date_Calendar from the parameters
+// We cannot display new-style/old-style years, so convert to new style
+if (preg_match('/^(\d\d)\d\d\/(\d\d)$/', $year, $match)) {
+ $year=$match[1].$match[2];
+}
+
// advance-year "year range"
if (preg_match('/^(\d+)-(\d+)$/', $year, $match)) {
- if (strlen($match[1]) > strlen($match[2]))
+ if (strlen($match[1]) > strlen($match[2])) {
$match[2]=substr($match[1], 0, strlen($match[1])-strlen($match[2])).$match[2];
+ }
$ged_date=new WT_Date("FROM {$cal} {$match[1]} TO {$cal} {$match[2]}");
$action='year';
-} else
+} else {
// advanced-year "decade/century wildcard"
if (preg_match('/^(\d+)(\?+)$/', $year, $match)) {
$y1=$match[1].str_replace('?', '0', $match[2]);
@@ -69,10 +75,11 @@ if (preg_match('/^(\d+)-(\d+)$/', $year, $match)) {
$action='year';
} else {
if ($year<0)
- $year=(-$year)."B.C."; // need BC to parse date
+ $year=(-$year)." B.C."; // need BC to parse date
$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;
// Invalid month? Pick a sensible one.
diff --git a/library/WT/Date.php b/library/WT/Date.php
index 307e785540..68865d75a5 100644
--- a/library/WT/Date.php
+++ b/library/WT/Date.php
@@ -82,13 +82,13 @@ class WT_Date {
$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|FARVA|ORDIB|KHORD|TIR|MORDA|SHAHR|MEHR|ABAN|AZAR|DEY|BAHMA|ESFAN) ?((?:\d+(?: B ?C)?|\d\d\d\d \/ \d{1,4})?)$/', $date, $match)) {
+ 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|FARVA|ORDIB|KHORD|TIR|MORDA|SHAHR|MEHR|ABAN|AZAR|DEY|BAHMA|ESFAN) ?((?:\d{1,4}(?: B\.C\.)?|\d\d\d\d\/\d\d)?)$/', $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)) {
+ if (preg_match('/^(\d{1,4}(?: B\.C\.)?|\d\d\d\d\/\d\d)$/', $date, $match)) {
$d='';
$m='';
$y=$match[1];
@@ -121,7 +121,7 @@ class WT_Date {
} else {
if (preg_match('/^(FARVA|ORDIB|KHORD|TIR|MORDA|SHAHR|MEHR|ABAN|AZAR|DEY|BAHMA|ESFAN)$/', $m)) {
$cal='@#DJALALI@'; // This is a WT extension
- } elseif (preg_match('/^\d+( B ?C)|\d\d\d\d \/ \d{1,4}$/', $y)) {
+ } elseif (preg_match('/^\d{1,4}( B\.C\.)|\d\d\d\d\/\d\d$/', $y)) {
$cal='@#DJULIAN@';
}
diff --git a/library/WT/Date/Calendar.php b/library/WT/Date/Calendar.php
index cfd4ccb44a..5849283e5a 100644
--- a/library/WT/Date/Calendar.php
+++ b/library/WT/Date/Calendar.php
@@ -409,7 +409,7 @@ class WT_Date_Calendar {
// Functions to extract bits of the date in various formats. Individual calendars
// will want to redefine some of these.
- private function FormatDayZeros() {
+ protected function FormatDayZeros() {
if ($this->d>9) {
return WT_I18N::digits($this->d);
} else {
@@ -417,23 +417,23 @@ class WT_Date_Calendar {
}
}
- private function FormatDay() {
+ protected function FormatDay() {
return WT_I18N::digits($this->d);
}
- private function FormatLongWeekday() {
+ protected function FormatLongWeekday() {
return $this->LONG_DAYS_OF_WEEK($this->minJD % static::DAYS_IN_WEEK);
}
- private function FormatShortWeekday() {
+ protected function FormatShortWeekday() {
return $this->SHORT_DAYS_OF_WEEK($this->minJD % static::DAYS_IN_WEEK);
}
- private function FormatISOWeekday() {
+ protected function FormatISOWeekday() {
return WT_I18N::digits($this->minJD % 7 + 1);
}
- private function FormatOrdinalSuffix() {
+ protected function FormatOrdinalSuffix() {
$func="ordinal_suffix_".WT_LOCALE;
if (function_exists($func))
return $func($this->d);
@@ -441,19 +441,19 @@ class WT_Date_Calendar {
return '';
}
- private function FormatNumericWeekday() {
+ protected function FormatNumericWeekday() {
return WT_I18N::digits(($this->minJD + 1) % static::DAYS_IN_WEEK);
}
- private function FormatDayOfYear() {
+ protected function FormatDayOfYear() {
return WT_I18N::digits($this->minJD - $this->YMDtoJD($this->y, 1, 1));
}
- private function FormatMonth() {
+ protected function FormatMonth() {
return WT_I18N::digits($this->m);
}
- private function FormatMonthZeros() {
+ protected function FormatMonthZeros() {
if ($this->m>9) {
return WT_I18N::digits($this->m);
} else {
@@ -461,7 +461,7 @@ class WT_Date_Calendar {
}
}
- private function FormatLongMonth($case='NOMINATIVE') {
+ protected 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());
@@ -470,17 +470,17 @@ class WT_Date_Calendar {
}
}
- private function FormatShortMonth() {
+ protected 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.
- private function FormatShortYear() {
+ protected function FormatShortYear() {
return WT_I18N::digits($this->y);
}
- private function FormatGedcomDay() {
+ protected function FormatGedcomDay() {
if ($this->d==0) {
return '';
} else {
@@ -488,11 +488,11 @@ class WT_Date_Calendar {
}
}
- private function FormatGedcomMonth() {
+ protected function FormatGedcomMonth() {
return array_search($this->m, static::$MONTH_ABBREV);
}
- private function FormatGedcomYear() {
+ protected function FormatGedcomYear() {
if ($this->y==0) {
return '';
} else {
@@ -500,12 +500,12 @@ class WT_Date_Calendar {
}
}
- private function FormatLongYear() {
+ protected function FormatLongYear() {
return WT_I18N::digits($this->y);
}
// Calendars with leap-months should redefine this.
- private function NextMonth() {
+ protected function NextMonth() {
return array(
$this->m==static::MONTHS_IN_YEAR ? $this->NextYear($this->y) : $this->y,
($this->m % static::MONTHS_IN_YEAR)+1
@@ -526,7 +526,7 @@ class WT_Date_Calendar {
}
// Convert a roman numeral to decimal
- private static function RomanToNum($roman) {
+ protected 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)
diff --git a/library/WT/Date/French.php b/library/WT/Date/French.php
index 481791b32f..7c48c6a7e4 100644
--- a/library/WT/Date/French.php
+++ b/library/WT/Date/French.php
@@ -156,7 +156,7 @@ class WT_Date_French extends WT_Date_Calendar {
}
// Years were written using roman numerals
- function FormatLongYear() {
+ protected function FormatLongYear() {
return $this->NumToRoman($this->y);
}
}
diff --git a/library/WT/Date/Julian.php b/library/WT/Date/Julian.php
index d73ef47f35..824de25d46 100644
--- a/library/WT/Date/Julian.php
+++ b/library/WT/Date/Julian.php
@@ -73,24 +73,26 @@ class WT_Date_Julian extends WT_Date_Calendar {
$day=$e-(int)((153*$m+2)/5)+1;
$month=$m+3-12*(int)($m/10);
$year=$d-4800+(int)($m/10);
- if ($year<1) // 0=1BC, -1=2BC, etc.
- --$year;
+ 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
+ public 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))
+ if (preg_match('/^(\d+) B\.C\.$/', $year, $match))
return -$match[1];
else
return (int)$year;
}
- function FormatLongYear() {
+ protected function FormatLongYear() {
if ($this->y<0) {
return /* I18N: BCE=Before the Common Era, for Julian years < 0. See http://en.wikipedia.org/wiki/Common_Era */ WT_I18N::translate('%s&nbsp;BCE', WT_I18N::digits(-$this->y));
} else {
@@ -101,9 +103,9 @@ class WT_Date_Julian extends WT_Date_Calendar {
}
}
- function FormatGedcomYear() {
+ protected function FormatGedcomYear() {
if ($this->y<0) {
- return sprintf('%04dB.C.', -$this->y);
+ return sprintf('%04d B.C.', -$this->y);
} else {
if ($this->new_old_style) {
return sprintf('%04d/%02d', $this->y-1, $this->y % 100);
diff --git a/library/WT/Date/Roman.php b/library/WT/Date/Roman.php
index 586bd92afb..b1a760781b 100644
--- a/library/WT/Date/Roman.php
+++ b/library/WT/Date/Roman.php
@@ -37,11 +37,11 @@ if (!defined('WT_WEBTREES')) {
class WT_Date_Roman extends WT_Date_Calendar {
const CALENDAR_ESCAPE = '@#DROMAN@';
- function FormatGedcomYear() {
+ protected function FormatGedcomYear() {
return sprintf('%04dAUC',$this->y);
}
- function FormatLongYear() {
+ protected function FormatLongYear() {
return $this->y.'AUC';
}
}