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