1<?php 2/** 3 * webtrees: online genealogy 4 * Copyright (C) 2016 webtrees development team 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 */ 16namespace Fisharebest\Webtrees\Date; 17 18use Fisharebest\ExtCalendar\ArabicCalendar; 19use Fisharebest\Webtrees\I18N; 20 21/** 22 * Definitions for the Hijri calendar. 23 * 24 * Note that these are "theoretical" dates. 25 * "True" dates are based on local lunar observations, and can be a +/- one day. 26 */ 27class HijriDate extends CalendarDate { 28 /** @var int[] Convert GEDCOM month names to month numbers */ 29 public static $MONTH_ABBREV = ['' => 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]; 30 31 /** 32 * Create a date from either: 33 * a Julian day number 34 * day/month/year strings from a GEDCOM date 35 * another CalendarDate object 36 * 37 * @param array|int|CalendarDate $date 38 */ 39 public function __construct($date) { 40 $this->calendar = new ArabicCalendar; 41 parent::__construct($date); 42 } 43 44 /** 45 * Full month name in nominative case. 46 * 47 * @param int $month_number 48 * @param bool $leap_year Some calendars use leap months 49 * 50 * @return string 51 */ 52 public static function monthNameNominativeCase($month_number, $leap_year) { 53 static $translated_month_names; 54 55 if ($translated_month_names === null) { 56 $translated_month_names = [ 57 0 => '', 58 1 => /* I18N: http://en.wikipedia.org/wiki/Muharram */ I18N::translateContext('NOMINATIVE', 'Muharram'), 59 2 => /* I18N: http://en.wikipedia.org/wiki/Safar */ I18N::translateContext('NOMINATIVE', 'Safar'), 60 3 => /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-awwal */ I18N::translateContext('NOMINATIVE', 'Rabi’ al-awwal'), 61 4 => /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-thani */ I18N::translateContext('NOMINATIVE', 'Rabi’ al-thani'), 62 5 => /* I18N: http://en.wikipedia.org/wiki/Jumada_al-awwal */ I18N::translateContext('NOMINATIVE', 'Jumada al-awwal'), 63 6 => /* I18N: http://en.wikipedia.org/wiki/Jumada_al-thani */ I18N::translateContext('NOMINATIVE', 'Jumada al-thani'), 64 7 => /* I18N: http://en.wikipedia.org/wiki/Rajab */ I18N::translateContext('NOMINATIVE', 'Rajab'), 65 8 => /* I18N: http://en.wikipedia.org/wiki/Sha%27aban */ I18N::translateContext('NOMINATIVE', 'Sha’aban'), 66 9 => /* I18N: http://en.wikipedia.org/wiki/Ramadan_%28calendar_month%29 */ I18N::translateContext('NOMINATIVE', 'Ramadan'), 67 10 => /* I18N: http://en.wikipedia.org/wiki/Shawwal */ I18N::translateContext('NOMINATIVE', 'Shawwal'), 68 11 => /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Qi%27dah */ I18N::translateContext('NOMINATIVE', 'Dhu al-Qi’dah'), 69 12 => /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Hijjah */ I18N::translateContext('NOMINATIVE', 'Dhu al-Hijjah'), 70 ]; 71 } 72 73 return $translated_month_names[$month_number]; 74 } 75 76 /** 77 * Full month name in genitive case. 78 * 79 * @param int $month_number 80 * @param bool $leap_year Some calendars use leap months 81 * 82 * @return string 83 */ 84 protected function monthNameGenitiveCase($month_number, $leap_year) { 85 static $translated_month_names; 86 87 if ($translated_month_names === null) { 88 $translated_month_names = [ 89 0 => '', 90 1 => /* I18N: http://en.wikipedia.org/wiki/Muharram */ I18N::translateContext('GENITIVE', 'Muharram'), 91 2 => /* I18N: http://en.wikipedia.org/wiki/Safar */ I18N::translateContext('GENITIVE', 'Safar'), 92 3 => /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-awwal */ I18N::translateContext('GENITIVE', 'Rabi’ al-awwal'), 93 4 => /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-thani */ I18N::translateContext('GENITIVE', 'Rabi’ al-thani'), 94 5 => /* I18N: http://en.wikipedia.org/wiki/Jumada_al-awwal */ I18N::translateContext('GENITIVE', 'Jumada al-awwal'), 95 6 => /* I18N: http://en.wikipedia.org/wiki/Jumada_al-thani */ I18N::translateContext('GENITIVE', 'Jumada al-thani'), 96 7 => /* I18N: http://en.wikipedia.org/wiki/Rajab */ I18N::translateContext('GENITIVE', 'Rajab'), 97 8 => /* I18N: http://en.wikipedia.org/wiki/Sha%27aban */ I18N::translateContext('GENITIVE', 'Sha’aban'), 98 9 => /* I18N: http://en.wikipedia.org/wiki/Ramadan_%28calendar_month%29 */ I18N::translateContext('GENITIVE', 'Ramadan'), 99 10 => /* I18N: http://en.wikipedia.org/wiki/Shawwal */ I18N::translateContext('GENITIVE', 'Shawwal'), 100 11 => /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Qi%27dah */ I18N::translateContext('GENITIVE', 'Dhu al-Qi’dah'), 101 12 => /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Hijjah */ I18N::translateContext('GENITIVE', 'Dhu al-Hijjah'), 102 ]; 103 } 104 105 return $translated_month_names[$month_number]; 106 } 107 108 /** 109 * Full month name in locative case. 110 * 111 * @param int $month_number 112 * @param bool $leap_year Some calendars use leap months 113 * 114 * @return string 115 */ 116 protected function monthNameLocativeCase($month_number, $leap_year) { 117 static $translated_month_names; 118 119 if ($translated_month_names === null) { 120 $translated_month_names = [ 121 0 => '', 122 1 => /* I18N: http://en.wikipedia.org/wiki/Muharram */ I18N::translateContext('LOCATIVE', 'Muharram'), 123 2 => /* I18N: http://en.wikipedia.org/wiki/Safar */ I18N::translateContext('LOCATIVE', 'Safar'), 124 3 => /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-awwal */ I18N::translateContext('LOCATIVE', 'Rabi’ al-awwal'), 125 4 => /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-thani */ I18N::translateContext('LOCATIVE', 'Rabi’ al-thani'), 126 5 => /* I18N: http://en.wikipedia.org/wiki/Jumada_al-awwal */ I18N::translateContext('LOCATIVE', 'Jumada al-awwal'), 127 6 => /* I18N: http://en.wikipedia.org/wiki/Jumada_al-thani */ I18N::translateContext('LOCATIVE', 'Jumada al-thani'), 128 7 => /* I18N: http://en.wikipedia.org/wiki/Rajab */ I18N::translateContext('LOCATIVE', 'Rajab'), 129 8 => /* I18N: http://en.wikipedia.org/wiki/Sha%27aban */ I18N::translateContext('LOCATIVE', 'Sha’aban'), 130 9 => /* I18N: http://en.wikipedia.org/wiki/Ramadan_%28calendar_month%29 */ I18N::translateContext('LOCATIVE', 'Ramadan'), 131 10 => /* I18N: http://en.wikipedia.org/wiki/Shawwal */ I18N::translateContext('LOCATIVE', 'Shawwal'), 132 11 => /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Qi%27dah */ I18N::translateContext('LOCATIVE', 'Dhu al-Qi’dah'), 133 12 => /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Hijjah */ I18N::translateContext('LOCATIVE', 'Dhu al-Hijjah'), 134 ]; 135 } 136 137 return $translated_month_names[$month_number]; 138 } 139 140 /** 141 * Full month name in instrumental case. 142 * 143 * @param int $month_number 144 * @param bool $leap_year Some calendars use leap months 145 * 146 * @return string 147 */ 148 protected function monthNameInstrumentalCase($month_number, $leap_year) { 149 static $translated_month_names; 150 151 if ($translated_month_names === null) { 152 $translated_month_names = [ 153 0 => '', 154 1 => /* I18N: http://en.wikipedia.org/wiki/Muharram */ I18N::translateContext('INSTRUMENTAL', 'Muharram'), 155 2 => /* I18N: http://en.wikipedia.org/wiki/Safar */ I18N::translateContext('INSTRUMENTAL', 'Safar'), 156 3 => /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-awwal */ I18N::translateContext('INSTRUMENTAL', 'Rabi’ al-awwal'), 157 4 => /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-thani */ I18N::translateContext('INSTRUMENTAL', 'Rabi’ al-thani'), 158 5 => /* I18N: http://en.wikipedia.org/wiki/Jumada_al-awwal */ I18N::translateContext('INSTRUMENTAL', 'Jumada al-awwal'), 159 6 => /* I18N: http://en.wikipedia.org/wiki/Jumada_al-thani */ I18N::translateContext('INSTRUMENTAL', 'Jumada al-thani'), 160 7 => /* I18N: http://en.wikipedia.org/wiki/Rajab */ I18N::translateContext('INSTRUMENTAL', 'Rajab'), 161 8 => /* I18N: http://en.wikipedia.org/wiki/Sha%27aban */ I18N::translateContext('INSTRUMENTAL', 'Sha’aban'), 162 9 => /* I18N: http://en.wikipedia.org/wiki/Ramadan_%28calendar_month%29 */ I18N::translateContext('INSTRUMENTAL', 'Ramadan'), 163 10 => /* I18N: http://en.wikipedia.org/wiki/Shawwal */ I18N::translateContext('INSTRUMENTAL', 'Shawwal'), 164 11 => /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Qi%27dah */ I18N::translateContext('INSTRUMENTAL', 'Dhu al-Qi’dah'), 165 12 => /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Hijjah */ I18N::translateContext('INSTRUMENTAL', 'Dhu al-Hijjah'), 166 ]; 167 } 168 169 return $translated_month_names[$month_number]; 170 } 171 172 /** 173 * Abbreviated month name 174 * 175 * @param int $month_number 176 * @param bool $leap_year Some calendars use leap months 177 * 178 * @return string 179 */ 180 protected function monthNameAbbreviated($month_number, $leap_year) { 181 return self::monthNameNominativeCase($month_number, $leap_year); 182 } 183} 184