1a25f0a04SGreg Roach<?php 2a25f0a04SGreg Roach/** 3a25f0a04SGreg Roach * webtrees: online genealogy 41062a142SGreg Roach * Copyright (C) 2018 webtrees development team 5a25f0a04SGreg Roach * This program is free software: you can redistribute it and/or modify 6a25f0a04SGreg Roach * it under the terms of the GNU General Public License as published by 7a25f0a04SGreg Roach * the Free Software Foundation, either version 3 of the License, or 8a25f0a04SGreg Roach * (at your option) any later version. 9a25f0a04SGreg Roach * This program is distributed in the hope that it will be useful, 10a25f0a04SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 11a25f0a04SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12a25f0a04SGreg Roach * GNU General Public License for more details. 13a25f0a04SGreg Roach * You should have received a copy of the GNU General Public License 14a25f0a04SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 15a25f0a04SGreg Roach */ 1676692c8bSGreg Roachnamespace Fisharebest\Webtrees\Date; 17a25f0a04SGreg Roach 18a25f0a04SGreg Roachuse Fisharebest\ExtCalendar\PersianCalendar; 190e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N; 20a25f0a04SGreg Roach 21a25f0a04SGreg Roach/** 2276692c8bSGreg Roach * Definitions for the Jalali calendar 23a25f0a04SGreg Roach */ 24c1010edaSGreg Roachclass JalaliDate extends CalendarDate 25c1010edaSGreg Roach{ 26e2052359SGreg Roach /** @var int[] Convert GEDCOM month names to month numbers */ 27b61e86aaSGreg Roach public static $MONTH_ABBREV = [ 28b61e86aaSGreg Roach '' => 0, 29c1010edaSGreg Roach 'FARVA' => 1, 30c1010edaSGreg Roach 'ORDIB' => 2, 31c1010edaSGreg Roach 'KHORD' => 3, 32c1010edaSGreg Roach 'TIR' => 4, 33c1010edaSGreg Roach 'MORDA' => 5, 34c1010edaSGreg Roach 'SHAHR' => 6, 35c1010edaSGreg Roach 'MEHR' => 7, 36c1010edaSGreg Roach 'ABAN' => 8, 37c1010edaSGreg Roach 'AZAR' => 9, 38c1010edaSGreg Roach 'DEY' => 10, 39c1010edaSGreg Roach 'BAHMA' => 11, 40c1010edaSGreg Roach 'ESFAN' => 12, 41c1010edaSGreg Roach ]; 42a25f0a04SGreg Roach 4376692c8bSGreg Roach /** 4476692c8bSGreg Roach * Create a date from either: 4576692c8bSGreg Roach * a Julian day number 4676692c8bSGreg Roach * day/month/year strings from a GEDCOM date 4776692c8bSGreg Roach * another CalendarDate object 4876692c8bSGreg Roach * 4976692c8bSGreg Roach * @param array|int|CalendarDate $date 5076692c8bSGreg Roach */ 51c1010edaSGreg Roach public function __construct($date) 52c1010edaSGreg Roach { 53*59f2f229SGreg Roach $this->calendar = new PersianCalendar(); 54a25f0a04SGreg Roach parent::__construct($date); 55a25f0a04SGreg Roach } 56a25f0a04SGreg Roach 5776692c8bSGreg Roach /** 5876692c8bSGreg Roach * Full month name in nominative case. 5976692c8bSGreg Roach * 6076692c8bSGreg Roach * @param int $month_number 6176692c8bSGreg Roach * @param bool $leap_year Some calendars use leap months 6276692c8bSGreg Roach * 6376692c8bSGreg Roach * @return string 6476692c8bSGreg Roach */ 65c1010edaSGreg Roach public static function monthNameNominativeCase($month_number, $leap_year) 66c1010edaSGreg Roach { 67a25f0a04SGreg Roach static $translated_month_names; 68a25f0a04SGreg Roach 69a25f0a04SGreg Roach if ($translated_month_names === null) { 7013abd6f3SGreg Roach $translated_month_names = [ 71a25f0a04SGreg Roach 0 => '', 72bbb76c12SGreg Roach /* I18N: 1st month in the Persian/Jalali calendar */ 73bbb76c12SGreg Roach 1 => I18N::translateContext('NOMINATIVE', 'Farvardin'), 74bbb76c12SGreg Roach /* I18N: 2nd month in the Persian/Jalali calendar */ 75bbb76c12SGreg Roach 2 => I18N::translateContext('NOMINATIVE', 'Ordibehesht'), 76bbb76c12SGreg Roach /* I18N: 3rd month in the Persian/Jalali calendar */ 77bbb76c12SGreg Roach 3 => I18N::translateContext('NOMINATIVE', 'Khordad'), 78bbb76c12SGreg Roach /* I18N: 4th month in the Persian/Jalali calendar */ 79bbb76c12SGreg Roach 4 => I18N::translateContext('NOMINATIVE', 'Tir'), 80bbb76c12SGreg Roach /* I18N: 5th month in the Persian/Jalali calendar */ 81bbb76c12SGreg Roach 5 => I18N::translateContext('NOMINATIVE', 'Mordad'), 82bbb76c12SGreg Roach /* I18N: 6th month in the Persian/Jalali calendar */ 83bbb76c12SGreg Roach 6 => I18N::translateContext('NOMINATIVE', 'Shahrivar'), 84bbb76c12SGreg Roach /* I18N: 7th month in the Persian/Jalali calendar */ 85bbb76c12SGreg Roach 7 => I18N::translateContext('NOMINATIVE', 'Mehr'), 86bbb76c12SGreg Roach /* I18N: 8th month in the Persian/Jalali calendar */ 87bbb76c12SGreg Roach 8 => I18N::translateContext('NOMINATIVE', 'Aban'), 88bbb76c12SGreg Roach /* I18N: 9th month in the Persian/Jalali calendar */ 89bbb76c12SGreg Roach 9 => I18N::translateContext('NOMINATIVE', 'Azar'), 90bbb76c12SGreg Roach /* I18N: 10th month in the Persian/Jalali calendar */ 91bbb76c12SGreg Roach 10 => I18N::translateContext('NOMINATIVE', 'Dey'), 92bbb76c12SGreg Roach /* I18N: 11th month in the Persian/Jalali calendar */ 93bbb76c12SGreg Roach 11 => I18N::translateContext('NOMINATIVE', 'Bahman'), 94bbb76c12SGreg Roach /* I18N: 12th month in the Persian/Jalali calendar */ 95bbb76c12SGreg Roach 12 => I18N::translateContext('NOMINATIVE', 'Esfand'), 9613abd6f3SGreg Roach ]; 97a25f0a04SGreg Roach } 98a25f0a04SGreg Roach 99a25f0a04SGreg Roach return $translated_month_names[$month_number]; 100a25f0a04SGreg Roach } 101a25f0a04SGreg Roach 10276692c8bSGreg Roach /** 10376692c8bSGreg Roach * Full month name in genitive case. 10476692c8bSGreg Roach * 10576692c8bSGreg Roach * @param int $month_number 10676692c8bSGreg Roach * @param bool $leap_year Some calendars use leap months 10776692c8bSGreg Roach * 10876692c8bSGreg Roach * @return string 10976692c8bSGreg Roach */ 110c1010edaSGreg Roach protected function monthNameGenitiveCase($month_number, $leap_year) 111c1010edaSGreg Roach { 112a25f0a04SGreg Roach static $translated_month_names; 113a25f0a04SGreg Roach 114a25f0a04SGreg Roach if ($translated_month_names === null) { 11513abd6f3SGreg Roach $translated_month_names = [ 116a25f0a04SGreg Roach 0 => '', 117bbb76c12SGreg Roach /* I18N: 1st month in the Persian/Jalali calendar */ 118bbb76c12SGreg Roach 1 => I18N::translateContext('GENITIVE', 'Farvardin'), 119bbb76c12SGreg Roach /* I18N: 2nd month in the Persian/Jalali calendar */ 120bbb76c12SGreg Roach 2 => I18N::translateContext('GENITIVE', 'Ordibehesht'), 121bbb76c12SGreg Roach /* I18N: 3rd month in the Persian/Jalali calendar */ 122bbb76c12SGreg Roach 3 => I18N::translateContext('GENITIVE', 'Khordad'), 123bbb76c12SGreg Roach /* I18N: 4th month in the Persian/Jalali calendar */ 124bbb76c12SGreg Roach 4 => I18N::translateContext('GENITIVE', 'Tir'), 125bbb76c12SGreg Roach /* I18N: 5th month in the Persian/Jalali calendar */ 126bbb76c12SGreg Roach 5 => I18N::translateContext('GENITIVE', 'Mordad'), 127bbb76c12SGreg Roach /* I18N: 6th month in the Persian/Jalali calendar */ 128bbb76c12SGreg Roach 6 => I18N::translateContext('GENITIVE', 'Shahrivar'), 129bbb76c12SGreg Roach /* I18N: 7th month in the Persian/Jalali calendar */ 130bbb76c12SGreg Roach 7 => I18N::translateContext('GENITIVE', 'Mehr'), 131bbb76c12SGreg Roach /* I18N: 8th month in the Persian/Jalali calendar */ 132bbb76c12SGreg Roach 8 => I18N::translateContext('GENITIVE', 'Aban'), 133bbb76c12SGreg Roach /* I18N: 9th month in the Persian/Jalali calendar */ 134bbb76c12SGreg Roach 9 => I18N::translateContext('GENITIVE', 'Azar'), 135bbb76c12SGreg Roach /* I18N: 10th month in the Persian/Jalali calendar */ 136bbb76c12SGreg Roach 10 => I18N::translateContext('GENITIVE', 'Dey'), 137bbb76c12SGreg Roach /* I18N: 11th month in the Persian/Jalali calendar */ 138bbb76c12SGreg Roach 11 => I18N::translateContext('GENITIVE', 'Bahman'), 139bbb76c12SGreg Roach /* I18N: 12th month in the Persian/Jalali calendar */ 140bbb76c12SGreg Roach 12 => I18N::translateContext('GENITIVE', 'Esfand'), 14113abd6f3SGreg Roach ]; 142a25f0a04SGreg Roach } 143a25f0a04SGreg Roach 144a25f0a04SGreg Roach return $translated_month_names[$month_number]; 145a25f0a04SGreg Roach } 146a25f0a04SGreg Roach 14776692c8bSGreg Roach /** 14876692c8bSGreg Roach * Full month name in locative case. 14976692c8bSGreg Roach * 15076692c8bSGreg Roach * @param int $month_number 15176692c8bSGreg Roach * @param bool $leap_year Some calendars use leap months 15276692c8bSGreg Roach * 15376692c8bSGreg Roach * @return string 15476692c8bSGreg Roach */ 155c1010edaSGreg Roach protected function monthNameLocativeCase($month_number, $leap_year) 156c1010edaSGreg Roach { 157a25f0a04SGreg Roach static $translated_month_names; 158a25f0a04SGreg Roach 159a25f0a04SGreg Roach if ($translated_month_names === null) { 16013abd6f3SGreg Roach $translated_month_names = [ 161a25f0a04SGreg Roach 0 => '', 162bbb76c12SGreg Roach /* I18N: 1st month in the Persian/Jalali calendar */ 163bbb76c12SGreg Roach 1 => I18N::translateContext('LOCATIVE', 'Farvardin'), 164bbb76c12SGreg Roach /* I18N: 2nd month in the Persian/Jalali calendar */ 165bbb76c12SGreg Roach 2 => I18N::translateContext('LOCATIVE', 'Ordibehesht'), 166bbb76c12SGreg Roach /* I18N: 3rd month in the Persian/Jalali calendar */ 167bbb76c12SGreg Roach 3 => I18N::translateContext('LOCATIVE', 'Khordad'), 168bbb76c12SGreg Roach /* I18N: 4th month in the Persian/Jalali calendar */ 169bbb76c12SGreg Roach 4 => I18N::translateContext('LOCATIVE', 'Tir'), 170bbb76c12SGreg Roach /* I18N: 5th month in the Persian/Jalali calendar */ 171bbb76c12SGreg Roach 5 => I18N::translateContext('LOCATIVE', 'Mordad'), 172bbb76c12SGreg Roach /* I18N: 6th month in the Persian/Jalali calendar */ 173bbb76c12SGreg Roach 6 => I18N::translateContext('LOCATIVE', 'Shahrivar'), 174bbb76c12SGreg Roach /* I18N: 7th month in the Persian/Jalali calendar */ 175bbb76c12SGreg Roach 7 => I18N::translateContext('LOCATIVE', 'Mehr'), 176bbb76c12SGreg Roach /* I18N: 8th month in the Persian/Jalali calendar */ 177bbb76c12SGreg Roach 8 => I18N::translateContext('LOCATIVE', 'Aban'), 178bbb76c12SGreg Roach /* I18N: 9th month in the Persian/Jalali calendar */ 179bbb76c12SGreg Roach 9 => I18N::translateContext('LOCATIVE', 'Azar'), 180bbb76c12SGreg Roach /* I18N: 10th month in the Persian/Jalali calendar */ 181bbb76c12SGreg Roach 10 => I18N::translateContext('LOCATIVE', 'Dey'), 182bbb76c12SGreg Roach /* I18N: 11th month in the Persian/Jalali calendar */ 183bbb76c12SGreg Roach 11 => I18N::translateContext('LOCATIVE', 'Bahman'), 184bbb76c12SGreg Roach /* I18N: 12th month in the Persian/Jalali calendar */ 185bbb76c12SGreg Roach 12 => I18N::translateContext('LOCATIVE', 'Esfand'), 18613abd6f3SGreg Roach ]; 187a25f0a04SGreg Roach } 188a25f0a04SGreg Roach 189a25f0a04SGreg Roach return $translated_month_names[$month_number]; 190a25f0a04SGreg Roach } 191a25f0a04SGreg Roach 19276692c8bSGreg Roach /** 19376692c8bSGreg Roach * Full month name in instrumental case. 19476692c8bSGreg Roach * 19576692c8bSGreg Roach * @param int $month_number 19676692c8bSGreg Roach * @param bool $leap_year Some calendars use leap months 19776692c8bSGreg Roach * 19876692c8bSGreg Roach * @return string 19976692c8bSGreg Roach */ 200c1010edaSGreg Roach protected function monthNameInstrumentalCase($month_number, $leap_year) 201c1010edaSGreg Roach { 202a25f0a04SGreg Roach static $translated_month_names; 203a25f0a04SGreg Roach 204a25f0a04SGreg Roach if ($translated_month_names === null) { 20513abd6f3SGreg Roach $translated_month_names = [ 206a25f0a04SGreg Roach 0 => '', 207bbb76c12SGreg Roach /* I18N: 1st month in the Persian/Jalali calendar */ 208bbb76c12SGreg Roach 1 => I18N::translateContext('INSTRUMENTAL', 'Farvardin'), 209bbb76c12SGreg Roach /* I18N: 2nd month in the Persian/Jalali calendar */ 210bbb76c12SGreg Roach 2 => I18N::translateContext('INSTRUMENTAL', 'Ordibehesht'), 211bbb76c12SGreg Roach /* I18N: 3rd month in the Persian/Jalali calendar */ 212bbb76c12SGreg Roach 3 => I18N::translateContext('INSTRUMENTAL', 'Khordad'), 213bbb76c12SGreg Roach /* I18N: 4th month in the Persian/Jalali calendar */ 214bbb76c12SGreg Roach 4 => I18N::translateContext('INSTRUMENTAL', 'Tir'), 215bbb76c12SGreg Roach /* I18N: 5th month in the Persian/Jalali calendar */ 216bbb76c12SGreg Roach 5 => I18N::translateContext('INSTRUMENTAL', 'Mordad'), 217bbb76c12SGreg Roach /* I18N: 6th month in the Persian/Jalali calendar */ 218bbb76c12SGreg Roach 6 => I18N::translateContext('INSTRUMENTAL', 'Shahrivar'), 219bbb76c12SGreg Roach /* I18N: 7th month in the Persian/Jalali calendar */ 220bbb76c12SGreg Roach 7 => I18N::translateContext('INSTRUMENTAL', 'Mehr'), 221bbb76c12SGreg Roach /* I18N: 8th month in the Persian/Jalali calendar */ 222bbb76c12SGreg Roach 8 => I18N::translateContext('INSTRUMENTAL', 'Aban'), 223bbb76c12SGreg Roach /* I18N: 9th month in the Persian/Jalali calendar */ 224bbb76c12SGreg Roach 9 => I18N::translateContext('INSTRUMENTAL', 'Azar'), 225bbb76c12SGreg Roach /* I18N: 10th month in the Persian/Jalali calendar */ 226bbb76c12SGreg Roach 10 => I18N::translateContext('INSTRUMENTAL', 'Dey'), 227bbb76c12SGreg Roach /* I18N: 11th month in the Persian/Jalali calendar */ 228bbb76c12SGreg Roach 11 => I18N::translateContext('INSTRUMENTAL', 'Bahman'), 229bbb76c12SGreg Roach /* I18N: 12th month in the Persian/Jalali calendar */ 230bbb76c12SGreg Roach 12 => I18N::translateContext('INSTRUMENTAL', 'Esfand'), 23113abd6f3SGreg Roach ]; 232a25f0a04SGreg Roach } 233a25f0a04SGreg Roach 234a25f0a04SGreg Roach return $translated_month_names[$month_number]; 235a25f0a04SGreg Roach } 236a25f0a04SGreg Roach 23776692c8bSGreg Roach /** 23876692c8bSGreg Roach * Abbreviated month name 23976692c8bSGreg Roach * 24076692c8bSGreg Roach * @param int $month_number 24176692c8bSGreg Roach * @param bool $leap_year Some calendars use leap months 24276692c8bSGreg Roach * 24376692c8bSGreg Roach * @return string 24476692c8bSGreg Roach */ 245c1010edaSGreg Roach protected function monthNameAbbreviated($month_number, $leap_year) 246c1010edaSGreg Roach { 247a25f0a04SGreg Roach static $translated_month_names; 248a25f0a04SGreg Roach 249a25f0a04SGreg Roach if ($translated_month_names === null) { 25013abd6f3SGreg Roach $translated_month_names = [ 251a25f0a04SGreg Roach 0 => '', 252764a01d9SGreg Roach 1 => I18N::translateContext('Abbreviation for Persian month: Farvardin', 'Far'), 253764a01d9SGreg Roach 2 => I18N::translateContext('Abbreviation for Persian month: Ordibehesht', 'Ord'), 254764a01d9SGreg Roach 3 => I18N::translateContext('Abbreviation for Persian month: Khordad', 'Khor'), 255764a01d9SGreg Roach 4 => I18N::translateContext('Abbreviation for Persian month: Tir', 'Tir'), 256764a01d9SGreg Roach 5 => I18N::translateContext('Abbreviation for Persian month: Mordad', 'Mor'), 257764a01d9SGreg Roach 6 => I18N::translateContext('Abbreviation for Persian month: Shahrivar', 'Shah'), 258764a01d9SGreg Roach 7 => I18N::translateContext('Abbreviation for Persian month: Mehr', 'Mehr'), 259764a01d9SGreg Roach 8 => I18N::translateContext('Abbreviation for Persian month: Aban', 'Aban'), 260764a01d9SGreg Roach 9 => I18N::translateContext('Abbreviation for Persian month: Azar', 'Azar'), 261764a01d9SGreg Roach 10 => I18N::translateContext('Abbreviation for Persian month: Dey', 'Dey'), 262764a01d9SGreg Roach 11 => I18N::translateContext('Abbreviation for Persian month: Bahman', 'Bah'), 263764a01d9SGreg Roach 12 => I18N::translateContext('Abbreviation for Persian month: Esfand', 'Esf'), 26413abd6f3SGreg Roach ]; 265a25f0a04SGreg Roach } 266a25f0a04SGreg Roach 267a25f0a04SGreg Roach return $translated_month_names[$month_number]; 268a25f0a04SGreg Roach } 269a25f0a04SGreg Roach} 270