1a25f0a04SGreg Roach<?php 23976b470SGreg Roach 3a25f0a04SGreg Roach/** 4a25f0a04SGreg Roach * webtrees: online genealogy 5*89f7189bSGreg Roach * Copyright (C) 2021 webtrees development team 6a25f0a04SGreg Roach * This program is free software: you can redistribute it and/or modify 7a25f0a04SGreg Roach * it under the terms of the GNU General Public License as published by 8a25f0a04SGreg Roach * the Free Software Foundation, either version 3 of the License, or 9a25f0a04SGreg Roach * (at your option) any later version. 10a25f0a04SGreg Roach * This program is distributed in the hope that it will be useful, 11a25f0a04SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12a25f0a04SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13a25f0a04SGreg Roach * GNU General Public License for more details. 14a25f0a04SGreg Roach * You should have received a copy of the GNU General Public License 15*89f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 16a25f0a04SGreg Roach */ 17fcfa147eSGreg Roach 18e7f56f2aSGreg Roachdeclare(strict_types=1); 19e7f56f2aSGreg Roach 2076692c8bSGreg Roachnamespace Fisharebest\Webtrees\Date; 21a25f0a04SGreg Roach 22a25f0a04SGreg Roachuse Fisharebest\ExtCalendar\PersianCalendar; 230e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N; 24a25f0a04SGreg Roach 25a25f0a04SGreg Roach/** 264a83f5d7SGreg Roach * Definitions for Jalali dates. 27a25f0a04SGreg Roach */ 284a83f5d7SGreg Roachclass JalaliDate extends AbstractCalendarDate 29c1010edaSGreg Roach{ 304a83f5d7SGreg Roach // GEDCOM calendar escape 3116d6367aSGreg Roach public const ESCAPE = '@#DJALALI@'; 324a83f5d7SGreg Roach 3352348eb8SGreg Roach // Convert GEDCOM month names to month numbers 3416d6367aSGreg Roach protected const MONTH_ABBREVIATIONS = [ 35b61e86aaSGreg Roach '' => 0, 36c1010edaSGreg Roach 'FARVA' => 1, 37c1010edaSGreg Roach 'ORDIB' => 2, 38c1010edaSGreg Roach 'KHORD' => 3, 39c1010edaSGreg Roach 'TIR' => 4, 40c1010edaSGreg Roach 'MORDA' => 5, 41c1010edaSGreg Roach 'SHAHR' => 6, 42c1010edaSGreg Roach 'MEHR' => 7, 43c1010edaSGreg Roach 'ABAN' => 8, 44c1010edaSGreg Roach 'AZAR' => 9, 45c1010edaSGreg Roach 'DEY' => 10, 46c1010edaSGreg Roach 'BAHMA' => 11, 47c1010edaSGreg Roach 'ESFAN' => 12, 48c1010edaSGreg Roach ]; 49a25f0a04SGreg Roach 5076692c8bSGreg Roach /** 5176692c8bSGreg Roach * Create a date from either: 5276692c8bSGreg Roach * a Julian day number 5376692c8bSGreg Roach * day/month/year strings from a GEDCOM date 5476692c8bSGreg Roach * another CalendarDate object 5576692c8bSGreg Roach * 56f4c767fdSGreg Roach * @param array<string>|int|AbstractCalendarDate $date 5776692c8bSGreg Roach */ 58c1010edaSGreg Roach public function __construct($date) 59c1010edaSGreg Roach { 6059f2f229SGreg Roach $this->calendar = new PersianCalendar(); 61a25f0a04SGreg Roach parent::__construct($date); 62a25f0a04SGreg Roach } 63a25f0a04SGreg Roach 6476692c8bSGreg Roach /** 6576692c8bSGreg Roach * Full month name in nominative case. 6676692c8bSGreg Roach * 677bb2eb25SGreg Roach * @param int $month 6876692c8bSGreg Roach * @param bool $leap_year Some calendars use leap months 6976692c8bSGreg Roach * 7076692c8bSGreg Roach * @return string 7176692c8bSGreg Roach */ 727bb2eb25SGreg Roach protected function monthNameNominativeCase(int $month, bool $leap_year): string 73c1010edaSGreg Roach { 74a25f0a04SGreg Roach static $translated_month_names; 75a25f0a04SGreg Roach 76a25f0a04SGreg Roach if ($translated_month_names === null) { 7713abd6f3SGreg Roach $translated_month_names = [ 78a25f0a04SGreg Roach 0 => '', 79bbb76c12SGreg Roach /* I18N: 1st month in the Persian/Jalali calendar */ 80bbb76c12SGreg Roach 1 => I18N::translateContext('NOMINATIVE', 'Farvardin'), 81bbb76c12SGreg Roach /* I18N: 2nd month in the Persian/Jalali calendar */ 82bbb76c12SGreg Roach 2 => I18N::translateContext('NOMINATIVE', 'Ordibehesht'), 83bbb76c12SGreg Roach /* I18N: 3rd month in the Persian/Jalali calendar */ 84bbb76c12SGreg Roach 3 => I18N::translateContext('NOMINATIVE', 'Khordad'), 85bbb76c12SGreg Roach /* I18N: 4th month in the Persian/Jalali calendar */ 86bbb76c12SGreg Roach 4 => I18N::translateContext('NOMINATIVE', 'Tir'), 87bbb76c12SGreg Roach /* I18N: 5th month in the Persian/Jalali calendar */ 88bbb76c12SGreg Roach 5 => I18N::translateContext('NOMINATIVE', 'Mordad'), 89bbb76c12SGreg Roach /* I18N: 6th month in the Persian/Jalali calendar */ 90bbb76c12SGreg Roach 6 => I18N::translateContext('NOMINATIVE', 'Shahrivar'), 91bbb76c12SGreg Roach /* I18N: 7th month in the Persian/Jalali calendar */ 92bbb76c12SGreg Roach 7 => I18N::translateContext('NOMINATIVE', 'Mehr'), 93bbb76c12SGreg Roach /* I18N: 8th month in the Persian/Jalali calendar */ 94bbb76c12SGreg Roach 8 => I18N::translateContext('NOMINATIVE', 'Aban'), 95bbb76c12SGreg Roach /* I18N: 9th month in the Persian/Jalali calendar */ 96bbb76c12SGreg Roach 9 => I18N::translateContext('NOMINATIVE', 'Azar'), 97bbb76c12SGreg Roach /* I18N: 10th month in the Persian/Jalali calendar */ 98bbb76c12SGreg Roach 10 => I18N::translateContext('NOMINATIVE', 'Dey'), 99bbb76c12SGreg Roach /* I18N: 11th month in the Persian/Jalali calendar */ 100bbb76c12SGreg Roach 11 => I18N::translateContext('NOMINATIVE', 'Bahman'), 101bbb76c12SGreg Roach /* I18N: 12th month in the Persian/Jalali calendar */ 102bbb76c12SGreg Roach 12 => I18N::translateContext('NOMINATIVE', 'Esfand'), 10313abd6f3SGreg Roach ]; 104a25f0a04SGreg Roach } 105a25f0a04SGreg Roach 1067bb2eb25SGreg Roach return $translated_month_names[$month]; 107a25f0a04SGreg Roach } 108a25f0a04SGreg Roach 10976692c8bSGreg Roach /** 11076692c8bSGreg Roach * Full month name in genitive case. 11176692c8bSGreg Roach * 1127bb2eb25SGreg Roach * @param int $month 11376692c8bSGreg Roach * @param bool $leap_year Some calendars use leap months 11476692c8bSGreg Roach * 11576692c8bSGreg Roach * @return string 11676692c8bSGreg Roach */ 1177bb2eb25SGreg Roach protected function monthNameGenitiveCase(int $month, bool $leap_year): string 118c1010edaSGreg Roach { 119a25f0a04SGreg Roach static $translated_month_names; 120a25f0a04SGreg Roach 121a25f0a04SGreg Roach if ($translated_month_names === null) { 12213abd6f3SGreg Roach $translated_month_names = [ 123a25f0a04SGreg Roach 0 => '', 124bbb76c12SGreg Roach /* I18N: 1st month in the Persian/Jalali calendar */ 125bbb76c12SGreg Roach 1 => I18N::translateContext('GENITIVE', 'Farvardin'), 126bbb76c12SGreg Roach /* I18N: 2nd month in the Persian/Jalali calendar */ 127bbb76c12SGreg Roach 2 => I18N::translateContext('GENITIVE', 'Ordibehesht'), 128bbb76c12SGreg Roach /* I18N: 3rd month in the Persian/Jalali calendar */ 129bbb76c12SGreg Roach 3 => I18N::translateContext('GENITIVE', 'Khordad'), 130bbb76c12SGreg Roach /* I18N: 4th month in the Persian/Jalali calendar */ 131bbb76c12SGreg Roach 4 => I18N::translateContext('GENITIVE', 'Tir'), 132bbb76c12SGreg Roach /* I18N: 5th month in the Persian/Jalali calendar */ 133bbb76c12SGreg Roach 5 => I18N::translateContext('GENITIVE', 'Mordad'), 134bbb76c12SGreg Roach /* I18N: 6th month in the Persian/Jalali calendar */ 135bbb76c12SGreg Roach 6 => I18N::translateContext('GENITIVE', 'Shahrivar'), 136bbb76c12SGreg Roach /* I18N: 7th month in the Persian/Jalali calendar */ 137bbb76c12SGreg Roach 7 => I18N::translateContext('GENITIVE', 'Mehr'), 138bbb76c12SGreg Roach /* I18N: 8th month in the Persian/Jalali calendar */ 139bbb76c12SGreg Roach 8 => I18N::translateContext('GENITIVE', 'Aban'), 140bbb76c12SGreg Roach /* I18N: 9th month in the Persian/Jalali calendar */ 141bbb76c12SGreg Roach 9 => I18N::translateContext('GENITIVE', 'Azar'), 142bbb76c12SGreg Roach /* I18N: 10th month in the Persian/Jalali calendar */ 143bbb76c12SGreg Roach 10 => I18N::translateContext('GENITIVE', 'Dey'), 144bbb76c12SGreg Roach /* I18N: 11th month in the Persian/Jalali calendar */ 145bbb76c12SGreg Roach 11 => I18N::translateContext('GENITIVE', 'Bahman'), 146bbb76c12SGreg Roach /* I18N: 12th month in the Persian/Jalali calendar */ 147bbb76c12SGreg Roach 12 => I18N::translateContext('GENITIVE', 'Esfand'), 14813abd6f3SGreg Roach ]; 149a25f0a04SGreg Roach } 150a25f0a04SGreg Roach 1517bb2eb25SGreg Roach return $translated_month_names[$month]; 152a25f0a04SGreg Roach } 153a25f0a04SGreg Roach 15476692c8bSGreg Roach /** 15576692c8bSGreg Roach * Full month name in locative case. 15676692c8bSGreg Roach * 1577bb2eb25SGreg Roach * @param int $month 15876692c8bSGreg Roach * @param bool $leap_year Some calendars use leap months 15976692c8bSGreg Roach * 16076692c8bSGreg Roach * @return string 16176692c8bSGreg Roach */ 1627bb2eb25SGreg Roach protected function monthNameLocativeCase(int $month, bool $leap_year): string 163c1010edaSGreg Roach { 164a25f0a04SGreg Roach static $translated_month_names; 165a25f0a04SGreg Roach 166a25f0a04SGreg Roach if ($translated_month_names === null) { 16713abd6f3SGreg Roach $translated_month_names = [ 168a25f0a04SGreg Roach 0 => '', 169bbb76c12SGreg Roach /* I18N: 1st month in the Persian/Jalali calendar */ 170bbb76c12SGreg Roach 1 => I18N::translateContext('LOCATIVE', 'Farvardin'), 171bbb76c12SGreg Roach /* I18N: 2nd month in the Persian/Jalali calendar */ 172bbb76c12SGreg Roach 2 => I18N::translateContext('LOCATIVE', 'Ordibehesht'), 173bbb76c12SGreg Roach /* I18N: 3rd month in the Persian/Jalali calendar */ 174bbb76c12SGreg Roach 3 => I18N::translateContext('LOCATIVE', 'Khordad'), 175bbb76c12SGreg Roach /* I18N: 4th month in the Persian/Jalali calendar */ 176bbb76c12SGreg Roach 4 => I18N::translateContext('LOCATIVE', 'Tir'), 177bbb76c12SGreg Roach /* I18N: 5th month in the Persian/Jalali calendar */ 178bbb76c12SGreg Roach 5 => I18N::translateContext('LOCATIVE', 'Mordad'), 179bbb76c12SGreg Roach /* I18N: 6th month in the Persian/Jalali calendar */ 180bbb76c12SGreg Roach 6 => I18N::translateContext('LOCATIVE', 'Shahrivar'), 181bbb76c12SGreg Roach /* I18N: 7th month in the Persian/Jalali calendar */ 182bbb76c12SGreg Roach 7 => I18N::translateContext('LOCATIVE', 'Mehr'), 183bbb76c12SGreg Roach /* I18N: 8th month in the Persian/Jalali calendar */ 184bbb76c12SGreg Roach 8 => I18N::translateContext('LOCATIVE', 'Aban'), 185bbb76c12SGreg Roach /* I18N: 9th month in the Persian/Jalali calendar */ 186bbb76c12SGreg Roach 9 => I18N::translateContext('LOCATIVE', 'Azar'), 187bbb76c12SGreg Roach /* I18N: 10th month in the Persian/Jalali calendar */ 188bbb76c12SGreg Roach 10 => I18N::translateContext('LOCATIVE', 'Dey'), 189bbb76c12SGreg Roach /* I18N: 11th month in the Persian/Jalali calendar */ 190bbb76c12SGreg Roach 11 => I18N::translateContext('LOCATIVE', 'Bahman'), 191bbb76c12SGreg Roach /* I18N: 12th month in the Persian/Jalali calendar */ 192bbb76c12SGreg Roach 12 => I18N::translateContext('LOCATIVE', 'Esfand'), 19313abd6f3SGreg Roach ]; 194a25f0a04SGreg Roach } 195a25f0a04SGreg Roach 1967bb2eb25SGreg Roach return $translated_month_names[$month]; 197a25f0a04SGreg Roach } 198a25f0a04SGreg Roach 19976692c8bSGreg Roach /** 20076692c8bSGreg Roach * Full month name in instrumental case. 20176692c8bSGreg Roach * 2027bb2eb25SGreg Roach * @param int $month 20376692c8bSGreg Roach * @param bool $leap_year Some calendars use leap months 20476692c8bSGreg Roach * 20576692c8bSGreg Roach * @return string 20676692c8bSGreg Roach */ 2077bb2eb25SGreg Roach protected function monthNameInstrumentalCase(int $month, bool $leap_year): string 208c1010edaSGreg Roach { 209a25f0a04SGreg Roach static $translated_month_names; 210a25f0a04SGreg Roach 211a25f0a04SGreg Roach if ($translated_month_names === null) { 21213abd6f3SGreg Roach $translated_month_names = [ 213a25f0a04SGreg Roach 0 => '', 214bbb76c12SGreg Roach /* I18N: 1st month in the Persian/Jalali calendar */ 215bbb76c12SGreg Roach 1 => I18N::translateContext('INSTRUMENTAL', 'Farvardin'), 216bbb76c12SGreg Roach /* I18N: 2nd month in the Persian/Jalali calendar */ 217bbb76c12SGreg Roach 2 => I18N::translateContext('INSTRUMENTAL', 'Ordibehesht'), 218bbb76c12SGreg Roach /* I18N: 3rd month in the Persian/Jalali calendar */ 219bbb76c12SGreg Roach 3 => I18N::translateContext('INSTRUMENTAL', 'Khordad'), 220bbb76c12SGreg Roach /* I18N: 4th month in the Persian/Jalali calendar */ 221bbb76c12SGreg Roach 4 => I18N::translateContext('INSTRUMENTAL', 'Tir'), 222bbb76c12SGreg Roach /* I18N: 5th month in the Persian/Jalali calendar */ 223bbb76c12SGreg Roach 5 => I18N::translateContext('INSTRUMENTAL', 'Mordad'), 224bbb76c12SGreg Roach /* I18N: 6th month in the Persian/Jalali calendar */ 225bbb76c12SGreg Roach 6 => I18N::translateContext('INSTRUMENTAL', 'Shahrivar'), 226bbb76c12SGreg Roach /* I18N: 7th month in the Persian/Jalali calendar */ 227bbb76c12SGreg Roach 7 => I18N::translateContext('INSTRUMENTAL', 'Mehr'), 228bbb76c12SGreg Roach /* I18N: 8th month in the Persian/Jalali calendar */ 229bbb76c12SGreg Roach 8 => I18N::translateContext('INSTRUMENTAL', 'Aban'), 230bbb76c12SGreg Roach /* I18N: 9th month in the Persian/Jalali calendar */ 231bbb76c12SGreg Roach 9 => I18N::translateContext('INSTRUMENTAL', 'Azar'), 232bbb76c12SGreg Roach /* I18N: 10th month in the Persian/Jalali calendar */ 233bbb76c12SGreg Roach 10 => I18N::translateContext('INSTRUMENTAL', 'Dey'), 234bbb76c12SGreg Roach /* I18N: 11th month in the Persian/Jalali calendar */ 235bbb76c12SGreg Roach 11 => I18N::translateContext('INSTRUMENTAL', 'Bahman'), 236bbb76c12SGreg Roach /* I18N: 12th month in the Persian/Jalali calendar */ 237bbb76c12SGreg Roach 12 => I18N::translateContext('INSTRUMENTAL', 'Esfand'), 23813abd6f3SGreg Roach ]; 239a25f0a04SGreg Roach } 240a25f0a04SGreg Roach 2417bb2eb25SGreg Roach return $translated_month_names[$month]; 242a25f0a04SGreg Roach } 243a25f0a04SGreg Roach 24476692c8bSGreg Roach /** 24576692c8bSGreg Roach * Abbreviated month name 24676692c8bSGreg Roach * 2477bb2eb25SGreg Roach * @param int $month 24876692c8bSGreg Roach * @param bool $leap_year Some calendars use leap months 24976692c8bSGreg Roach * 25076692c8bSGreg Roach * @return string 25176692c8bSGreg Roach */ 2527bb2eb25SGreg Roach protected function monthNameAbbreviated(int $month, bool $leap_year): string 253c1010edaSGreg Roach { 254a25f0a04SGreg Roach static $translated_month_names; 255a25f0a04SGreg Roach 256a25f0a04SGreg Roach if ($translated_month_names === null) { 25713abd6f3SGreg Roach $translated_month_names = [ 258a25f0a04SGreg Roach 0 => '', 259764a01d9SGreg Roach 1 => I18N::translateContext('Abbreviation for Persian month: Farvardin', 'Far'), 260764a01d9SGreg Roach 2 => I18N::translateContext('Abbreviation for Persian month: Ordibehesht', 'Ord'), 261764a01d9SGreg Roach 3 => I18N::translateContext('Abbreviation for Persian month: Khordad', 'Khor'), 262764a01d9SGreg Roach 4 => I18N::translateContext('Abbreviation for Persian month: Tir', 'Tir'), 263764a01d9SGreg Roach 5 => I18N::translateContext('Abbreviation for Persian month: Mordad', 'Mor'), 264764a01d9SGreg Roach 6 => I18N::translateContext('Abbreviation for Persian month: Shahrivar', 'Shah'), 265764a01d9SGreg Roach 7 => I18N::translateContext('Abbreviation for Persian month: Mehr', 'Mehr'), 266764a01d9SGreg Roach 8 => I18N::translateContext('Abbreviation for Persian month: Aban', 'Aban'), 267764a01d9SGreg Roach 9 => I18N::translateContext('Abbreviation for Persian month: Azar', 'Azar'), 268764a01d9SGreg Roach 10 => I18N::translateContext('Abbreviation for Persian month: Dey', 'Dey'), 269764a01d9SGreg Roach 11 => I18N::translateContext('Abbreviation for Persian month: Bahman', 'Bah'), 270764a01d9SGreg Roach 12 => I18N::translateContext('Abbreviation for Persian month: Esfand', 'Esf'), 27113abd6f3SGreg Roach ]; 272a25f0a04SGreg Roach } 273a25f0a04SGreg Roach 2747bb2eb25SGreg Roach return $translated_month_names[$month]; 275a25f0a04SGreg Roach } 276a25f0a04SGreg Roach} 277