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