1<?php 2/** 3 * webtrees: online genealogy 4 * Copyright (C) 2018 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{ 29 /** @var int[] Convert GEDCOM month names to month numbers */ 30 public static $MONTH_ABBREV = [ 31 '' => 0, 32 'MUHAR' => 1, 33 'SAFAR' => 2, 34 'RABIA' => 3, 35 'RABIT' => 4, 36 'JUMAA' => 5, 37 'JUMAT' => 6, 38 'RAJAB' => 7, 39 'SHAAB' => 8, 40 'RAMAD' => 9, 41 'SHAWW' => 10, 42 'DHUAQ' => 11, 43 'DHUAH' => 12, 44 ]; 45 46 /** 47 * Create a date from either: 48 * a Julian day number 49 * day/month/year strings from a GEDCOM date 50 * another CalendarDate object 51 * 52 * @param array|int|CalendarDate $date 53 */ 54 public function __construct($date) 55 { 56 $this->calendar = new ArabicCalendar; 57 parent::__construct($date); 58 } 59 60 /** 61 * Full month name in nominative case. 62 * 63 * @param int $month_number 64 * @param bool $leap_year Some calendars use leap months 65 * 66 * @return string 67 */ 68 public static function monthNameNominativeCase($month_number, $leap_year) 69 { 70 static $translated_month_names; 71 72 if ($translated_month_names === null) { 73 $translated_month_names = [ 74 0 => '', 75 1 => /* I18N: http://en.wikipedia.org/wiki/Muharram */ 76 I18N::translateContext('NOMINATIVE', 'Muharram'), 77 2 => /* I18N: http://en.wikipedia.org/wiki/Safar */ 78 I18N::translateContext('NOMINATIVE', 'Safar'), 79 3 => /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-awwal */ 80 I18N::translateContext('NOMINATIVE', 'Rabi’ al-awwal'), 81 4 => /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-thani */ 82 I18N::translateContext('NOMINATIVE', 'Rabi’ al-thani'), 83 5 => /* I18N: http://en.wikipedia.org/wiki/Jumada_al-awwal */ 84 I18N::translateContext('NOMINATIVE', 'Jumada al-awwal'), 85 6 => /* I18N: http://en.wikipedia.org/wiki/Jumada_al-thani */ 86 I18N::translateContext('NOMINATIVE', 'Jumada al-thani'), 87 7 => /* I18N: http://en.wikipedia.org/wiki/Rajab */ 88 I18N::translateContext('NOMINATIVE', 'Rajab'), 89 8 => /* I18N: http://en.wikipedia.org/wiki/Sha%27aban */ 90 I18N::translateContext('NOMINATIVE', 'Sha’aban'), 91 9 => /* I18N: http://en.wikipedia.org/wiki/Ramadan_%28calendar_month%29 */ 92 I18N::translateContext('NOMINATIVE', 'Ramadan'), 93 10 => /* I18N: http://en.wikipedia.org/wiki/Shawwal */ 94 I18N::translateContext('NOMINATIVE', 'Shawwal'), 95 11 => /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Qi%27dah */ 96 I18N::translateContext('NOMINATIVE', 'Dhu al-Qi’dah'), 97 12 => /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Hijjah */ 98 I18N::translateContext('NOMINATIVE', 'Dhu al-Hijjah'), 99 ]; 100 } 101 102 return $translated_month_names[$month_number]; 103 } 104 105 /** 106 * Full month name in genitive case. 107 * 108 * @param int $month_number 109 * @param bool $leap_year Some calendars use leap months 110 * 111 * @return string 112 */ 113 protected function monthNameGenitiveCase($month_number, $leap_year) 114 { 115 static $translated_month_names; 116 117 if ($translated_month_names === null) { 118 $translated_month_names = [ 119 0 => '', 120 1 => /* I18N: http://en.wikipedia.org/wiki/Muharram */ 121 I18N::translateContext('GENITIVE', 'Muharram'), 122 2 => /* I18N: http://en.wikipedia.org/wiki/Safar */ 123 I18N::translateContext('GENITIVE', 'Safar'), 124 3 => /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-awwal */ 125 I18N::translateContext('GENITIVE', 'Rabi’ al-awwal'), 126 4 => /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-thani */ 127 I18N::translateContext('GENITIVE', 'Rabi’ al-thani'), 128 5 => /* I18N: http://en.wikipedia.org/wiki/Jumada_al-awwal */ 129 I18N::translateContext('GENITIVE', 'Jumada al-awwal'), 130 6 => /* I18N: http://en.wikipedia.org/wiki/Jumada_al-thani */ 131 I18N::translateContext('GENITIVE', 'Jumada al-thani'), 132 7 => /* I18N: http://en.wikipedia.org/wiki/Rajab */ 133 I18N::translateContext('GENITIVE', 'Rajab'), 134 8 => /* I18N: http://en.wikipedia.org/wiki/Sha%27aban */ 135 I18N::translateContext('GENITIVE', 'Sha’aban'), 136 9 => /* I18N: http://en.wikipedia.org/wiki/Ramadan_%28calendar_month%29 */ 137 I18N::translateContext('GENITIVE', 'Ramadan'), 138 10 => /* I18N: http://en.wikipedia.org/wiki/Shawwal */ 139 I18N::translateContext('GENITIVE', 'Shawwal'), 140 11 => /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Qi%27dah */ 141 I18N::translateContext('GENITIVE', 'Dhu al-Qi’dah'), 142 12 => /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Hijjah */ 143 I18N::translateContext('GENITIVE', 'Dhu al-Hijjah'), 144 ]; 145 } 146 147 return $translated_month_names[$month_number]; 148 } 149 150 /** 151 * Full month name in locative case. 152 * 153 * @param int $month_number 154 * @param bool $leap_year Some calendars use leap months 155 * 156 * @return string 157 */ 158 protected function monthNameLocativeCase($month_number, $leap_year) 159 { 160 static $translated_month_names; 161 162 if ($translated_month_names === null) { 163 $translated_month_names = [ 164 0 => '', 165 1 => /* I18N: http://en.wikipedia.org/wiki/Muharram */ 166 I18N::translateContext('LOCATIVE', 'Muharram'), 167 2 => /* I18N: http://en.wikipedia.org/wiki/Safar */ 168 I18N::translateContext('LOCATIVE', 'Safar'), 169 3 => /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-awwal */ 170 I18N::translateContext('LOCATIVE', 'Rabi’ al-awwal'), 171 4 => /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-thani */ 172 I18N::translateContext('LOCATIVE', 'Rabi’ al-thani'), 173 5 => /* I18N: http://en.wikipedia.org/wiki/Jumada_al-awwal */ 174 I18N::translateContext('LOCATIVE', 'Jumada al-awwal'), 175 6 => /* I18N: http://en.wikipedia.org/wiki/Jumada_al-thani */ 176 I18N::translateContext('LOCATIVE', 'Jumada al-thani'), 177 7 => /* I18N: http://en.wikipedia.org/wiki/Rajab */ 178 I18N::translateContext('LOCATIVE', 'Rajab'), 179 8 => /* I18N: http://en.wikipedia.org/wiki/Sha%27aban */ 180 I18N::translateContext('LOCATIVE', 'Sha’aban'), 181 9 => /* I18N: http://en.wikipedia.org/wiki/Ramadan_%28calendar_month%29 */ 182 I18N::translateContext('LOCATIVE', 'Ramadan'), 183 10 => /* I18N: http://en.wikipedia.org/wiki/Shawwal */ 184 I18N::translateContext('LOCATIVE', 'Shawwal'), 185 11 => /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Qi%27dah */ 186 I18N::translateContext('LOCATIVE', 'Dhu al-Qi’dah'), 187 12 => /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Hijjah */ 188 I18N::translateContext('LOCATIVE', 'Dhu al-Hijjah'), 189 ]; 190 } 191 192 return $translated_month_names[$month_number]; 193 } 194 195 /** 196 * Full month name in instrumental case. 197 * 198 * @param int $month_number 199 * @param bool $leap_year Some calendars use leap months 200 * 201 * @return string 202 */ 203 protected function monthNameInstrumentalCase($month_number, $leap_year) 204 { 205 static $translated_month_names; 206 207 if ($translated_month_names === null) { 208 $translated_month_names = [ 209 0 => '', 210 1 => /* I18N: http://en.wikipedia.org/wiki/Muharram */ 211 I18N::translateContext('INSTRUMENTAL', 'Muharram'), 212 2 => /* I18N: http://en.wikipedia.org/wiki/Safar */ 213 I18N::translateContext('INSTRUMENTAL', 'Safar'), 214 3 => /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-awwal */ 215 I18N::translateContext('INSTRUMENTAL', 'Rabi’ al-awwal'), 216 4 => /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-thani */ 217 I18N::translateContext('INSTRUMENTAL', 'Rabi’ al-thani'), 218 5 => /* I18N: http://en.wikipedia.org/wiki/Jumada_al-awwal */ 219 I18N::translateContext('INSTRUMENTAL', 'Jumada al-awwal'), 220 6 => /* I18N: http://en.wikipedia.org/wiki/Jumada_al-thani */ 221 I18N::translateContext('INSTRUMENTAL', 'Jumada al-thani'), 222 7 => /* I18N: http://en.wikipedia.org/wiki/Rajab */ 223 I18N::translateContext('INSTRUMENTAL', 'Rajab'), 224 8 => /* I18N: http://en.wikipedia.org/wiki/Sha%27aban */ 225 I18N::translateContext('INSTRUMENTAL', 'Sha’aban'), 226 9 => /* I18N: http://en.wikipedia.org/wiki/Ramadan_%28calendar_month%29 */ 227 I18N::translateContext('INSTRUMENTAL', 'Ramadan'), 228 10 => /* I18N: http://en.wikipedia.org/wiki/Shawwal */ 229 I18N::translateContext('INSTRUMENTAL', 'Shawwal'), 230 11 => /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Qi%27dah */ 231 I18N::translateContext('INSTRUMENTAL', 'Dhu al-Qi’dah'), 232 12 => /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Hijjah */ 233 I18N::translateContext('INSTRUMENTAL', 'Dhu al-Hijjah'), 234 ]; 235 } 236 237 return $translated_month_names[$month_number]; 238 } 239 240 /** 241 * Abbreviated month name 242 * 243 * @param int $month_number 244 * @param bool $leap_year Some calendars use leap months 245 * 246 * @return string 247 */ 248 protected function monthNameAbbreviated($month_number, $leap_year) 249 { 250 return self::monthNameNominativeCase($month_number, $leap_year); 251 } 252} 253