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\PersianCalendar; 19use Fisharebest\Webtrees\I18N; 20 21/** 22 * Definitions for the Jalali calendar 23 */ 24class JalaliDate extends CalendarDate 25{ 26 // Convert GEDCOM month names to month numbers 27 const MONTH_ABBREVIATIONS = [ 28 '' => 0, 29 'FARVA' => 1, 30 'ORDIB' => 2, 31 'KHORD' => 3, 32 'TIR' => 4, 33 'MORDA' => 5, 34 'SHAHR' => 6, 35 'MEHR' => 7, 36 'ABAN' => 8, 37 'AZAR' => 9, 38 'DEY' => 10, 39 'BAHMA' => 11, 40 'ESFAN' => 12, 41 ]; 42 43 /** 44 * Create a date from either: 45 * a Julian day number 46 * day/month/year strings from a GEDCOM date 47 * another CalendarDate object 48 * 49 * @param array|int|CalendarDate $date 50 */ 51 public function __construct($date) 52 { 53 $this->calendar = new PersianCalendar(); 54 parent::__construct($date); 55 } 56 57 /** 58 * Full month name in nominative case. 59 * 60 * @param int $month_number 61 * @param bool $leap_year Some calendars use leap months 62 * 63 * @return string 64 */ 65 protected function monthNameNominativeCase(int $month_number, bool $leap_year): string 66 { 67 static $translated_month_names; 68 69 if ($translated_month_names === null) { 70 $translated_month_names = [ 71 0 => '', 72 /* I18N: 1st month in the Persian/Jalali calendar */ 73 1 => I18N::translateContext('NOMINATIVE', 'Farvardin'), 74 /* I18N: 2nd month in the Persian/Jalali calendar */ 75 2 => I18N::translateContext('NOMINATIVE', 'Ordibehesht'), 76 /* I18N: 3rd month in the Persian/Jalali calendar */ 77 3 => I18N::translateContext('NOMINATIVE', 'Khordad'), 78 /* I18N: 4th month in the Persian/Jalali calendar */ 79 4 => I18N::translateContext('NOMINATIVE', 'Tir'), 80 /* I18N: 5th month in the Persian/Jalali calendar */ 81 5 => I18N::translateContext('NOMINATIVE', 'Mordad'), 82 /* I18N: 6th month in the Persian/Jalali calendar */ 83 6 => I18N::translateContext('NOMINATIVE', 'Shahrivar'), 84 /* I18N: 7th month in the Persian/Jalali calendar */ 85 7 => I18N::translateContext('NOMINATIVE', 'Mehr'), 86 /* I18N: 8th month in the Persian/Jalali calendar */ 87 8 => I18N::translateContext('NOMINATIVE', 'Aban'), 88 /* I18N: 9th month in the Persian/Jalali calendar */ 89 9 => I18N::translateContext('NOMINATIVE', 'Azar'), 90 /* I18N: 10th month in the Persian/Jalali calendar */ 91 10 => I18N::translateContext('NOMINATIVE', 'Dey'), 92 /* I18N: 11th month in the Persian/Jalali calendar */ 93 11 => I18N::translateContext('NOMINATIVE', 'Bahman'), 94 /* I18N: 12th month in the Persian/Jalali calendar */ 95 12 => I18N::translateContext('NOMINATIVE', 'Esfand'), 96 ]; 97 } 98 99 return $translated_month_names[$month_number]; 100 } 101 102 /** 103 * Full month name in genitive case. 104 * 105 * @param int $month_number 106 * @param bool $leap_year Some calendars use leap months 107 * 108 * @return string 109 */ 110 protected function monthNameGenitiveCase(int $month_number, bool $leap_year): string 111 { 112 static $translated_month_names; 113 114 if ($translated_month_names === null) { 115 $translated_month_names = [ 116 0 => '', 117 /* I18N: 1st month in the Persian/Jalali calendar */ 118 1 => I18N::translateContext('GENITIVE', 'Farvardin'), 119 /* I18N: 2nd month in the Persian/Jalali calendar */ 120 2 => I18N::translateContext('GENITIVE', 'Ordibehesht'), 121 /* I18N: 3rd month in the Persian/Jalali calendar */ 122 3 => I18N::translateContext('GENITIVE', 'Khordad'), 123 /* I18N: 4th month in the Persian/Jalali calendar */ 124 4 => I18N::translateContext('GENITIVE', 'Tir'), 125 /* I18N: 5th month in the Persian/Jalali calendar */ 126 5 => I18N::translateContext('GENITIVE', 'Mordad'), 127 /* I18N: 6th month in the Persian/Jalali calendar */ 128 6 => I18N::translateContext('GENITIVE', 'Shahrivar'), 129 /* I18N: 7th month in the Persian/Jalali calendar */ 130 7 => I18N::translateContext('GENITIVE', 'Mehr'), 131 /* I18N: 8th month in the Persian/Jalali calendar */ 132 8 => I18N::translateContext('GENITIVE', 'Aban'), 133 /* I18N: 9th month in the Persian/Jalali calendar */ 134 9 => I18N::translateContext('GENITIVE', 'Azar'), 135 /* I18N: 10th month in the Persian/Jalali calendar */ 136 10 => I18N::translateContext('GENITIVE', 'Dey'), 137 /* I18N: 11th month in the Persian/Jalali calendar */ 138 11 => I18N::translateContext('GENITIVE', 'Bahman'), 139 /* I18N: 12th month in the Persian/Jalali calendar */ 140 12 => I18N::translateContext('GENITIVE', 'Esfand'), 141 ]; 142 } 143 144 return $translated_month_names[$month_number]; 145 } 146 147 /** 148 * Full month name in locative case. 149 * 150 * @param int $month_number 151 * @param bool $leap_year Some calendars use leap months 152 * 153 * @return string 154 */ 155 protected function monthNameLocativeCase(int $month_number, bool $leap_year): string 156 { 157 static $translated_month_names; 158 159 if ($translated_month_names === null) { 160 $translated_month_names = [ 161 0 => '', 162 /* I18N: 1st month in the Persian/Jalali calendar */ 163 1 => I18N::translateContext('LOCATIVE', 'Farvardin'), 164 /* I18N: 2nd month in the Persian/Jalali calendar */ 165 2 => I18N::translateContext('LOCATIVE', 'Ordibehesht'), 166 /* I18N: 3rd month in the Persian/Jalali calendar */ 167 3 => I18N::translateContext('LOCATIVE', 'Khordad'), 168 /* I18N: 4th month in the Persian/Jalali calendar */ 169 4 => I18N::translateContext('LOCATIVE', 'Tir'), 170 /* I18N: 5th month in the Persian/Jalali calendar */ 171 5 => I18N::translateContext('LOCATIVE', 'Mordad'), 172 /* I18N: 6th month in the Persian/Jalali calendar */ 173 6 => I18N::translateContext('LOCATIVE', 'Shahrivar'), 174 /* I18N: 7th month in the Persian/Jalali calendar */ 175 7 => I18N::translateContext('LOCATIVE', 'Mehr'), 176 /* I18N: 8th month in the Persian/Jalali calendar */ 177 8 => I18N::translateContext('LOCATIVE', 'Aban'), 178 /* I18N: 9th month in the Persian/Jalali calendar */ 179 9 => I18N::translateContext('LOCATIVE', 'Azar'), 180 /* I18N: 10th month in the Persian/Jalali calendar */ 181 10 => I18N::translateContext('LOCATIVE', 'Dey'), 182 /* I18N: 11th month in the Persian/Jalali calendar */ 183 11 => I18N::translateContext('LOCATIVE', 'Bahman'), 184 /* I18N: 12th month in the Persian/Jalali calendar */ 185 12 => I18N::translateContext('LOCATIVE', 'Esfand'), 186 ]; 187 } 188 189 return $translated_month_names[$month_number]; 190 } 191 192 /** 193 * Full month name in instrumental case. 194 * 195 * @param int $month_number 196 * @param bool $leap_year Some calendars use leap months 197 * 198 * @return string 199 */ 200 protected function monthNameInstrumentalCase(int $month_number, bool $leap_year): string 201 { 202 static $translated_month_names; 203 204 if ($translated_month_names === null) { 205 $translated_month_names = [ 206 0 => '', 207 /* I18N: 1st month in the Persian/Jalali calendar */ 208 1 => I18N::translateContext('INSTRUMENTAL', 'Farvardin'), 209 /* I18N: 2nd month in the Persian/Jalali calendar */ 210 2 => I18N::translateContext('INSTRUMENTAL', 'Ordibehesht'), 211 /* I18N: 3rd month in the Persian/Jalali calendar */ 212 3 => I18N::translateContext('INSTRUMENTAL', 'Khordad'), 213 /* I18N: 4th month in the Persian/Jalali calendar */ 214 4 => I18N::translateContext('INSTRUMENTAL', 'Tir'), 215 /* I18N: 5th month in the Persian/Jalali calendar */ 216 5 => I18N::translateContext('INSTRUMENTAL', 'Mordad'), 217 /* I18N: 6th month in the Persian/Jalali calendar */ 218 6 => I18N::translateContext('INSTRUMENTAL', 'Shahrivar'), 219 /* I18N: 7th month in the Persian/Jalali calendar */ 220 7 => I18N::translateContext('INSTRUMENTAL', 'Mehr'), 221 /* I18N: 8th month in the Persian/Jalali calendar */ 222 8 => I18N::translateContext('INSTRUMENTAL', 'Aban'), 223 /* I18N: 9th month in the Persian/Jalali calendar */ 224 9 => I18N::translateContext('INSTRUMENTAL', 'Azar'), 225 /* I18N: 10th month in the Persian/Jalali calendar */ 226 10 => I18N::translateContext('INSTRUMENTAL', 'Dey'), 227 /* I18N: 11th month in the Persian/Jalali calendar */ 228 11 => I18N::translateContext('INSTRUMENTAL', 'Bahman'), 229 /* I18N: 12th month in the Persian/Jalali calendar */ 230 12 => I18N::translateContext('INSTRUMENTAL', 'Esfand'), 231 ]; 232 } 233 234 return $translated_month_names[$month_number]; 235 } 236 237 /** 238 * Abbreviated month name 239 * 240 * @param int $month_number 241 * @param bool $leap_year Some calendars use leap months 242 * 243 * @return string 244 */ 245 protected function monthNameAbbreviated(int $month_number, bool $leap_year): string 246 { 247 static $translated_month_names; 248 249 if ($translated_month_names === null) { 250 $translated_month_names = [ 251 0 => '', 252 1 => I18N::translateContext('Abbreviation for Persian month: Farvardin', 'Far'), 253 2 => I18N::translateContext('Abbreviation for Persian month: Ordibehesht', 'Ord'), 254 3 => I18N::translateContext('Abbreviation for Persian month: Khordad', 'Khor'), 255 4 => I18N::translateContext('Abbreviation for Persian month: Tir', 'Tir'), 256 5 => I18N::translateContext('Abbreviation for Persian month: Mordad', 'Mor'), 257 6 => I18N::translateContext('Abbreviation for Persian month: Shahrivar', 'Shah'), 258 7 => I18N::translateContext('Abbreviation for Persian month: Mehr', 'Mehr'), 259 8 => I18N::translateContext('Abbreviation for Persian month: Aban', 'Aban'), 260 9 => I18N::translateContext('Abbreviation for Persian month: Azar', 'Azar'), 261 10 => I18N::translateContext('Abbreviation for Persian month: Dey', 'Dey'), 262 11 => I18N::translateContext('Abbreviation for Persian month: Bahman', 'Bah'), 263 12 => I18N::translateContext('Abbreviation for Persian month: Esfand', 'Esf'), 264 ]; 265 } 266 267 return $translated_month_names[$month_number]; 268 } 269} 270