1a25f0a04SGreg Roach<?php 23976b470SGreg Roach 3a25f0a04SGreg Roach/** 4a25f0a04SGreg Roach * webtrees: online genealogy 5*d11be702SGreg Roach * Copyright (C) 2023 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 1589f7189bSGreg 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 34d8809d62SGreg Roach protected const MONTH_TO_NUMBER = [ 35c1010edaSGreg Roach 'FARVA' => 1, 36c1010edaSGreg Roach 'ORDIB' => 2, 37c1010edaSGreg Roach 'KHORD' => 3, 38c1010edaSGreg Roach 'TIR' => 4, 39c1010edaSGreg Roach 'MORDA' => 5, 40c1010edaSGreg Roach 'SHAHR' => 6, 41c1010edaSGreg Roach 'MEHR' => 7, 42c1010edaSGreg Roach 'ABAN' => 8, 43c1010edaSGreg Roach 'AZAR' => 9, 44c1010edaSGreg Roach 'DEY' => 10, 45c1010edaSGreg Roach 'BAHMA' => 11, 46c1010edaSGreg Roach 'ESFAN' => 12, 47c1010edaSGreg Roach ]; 48a25f0a04SGreg Roach 49d8809d62SGreg Roach protected const NUMBER_TO_MONTH = [ 50d8809d62SGreg Roach 1 => 'FARVA', 51d8809d62SGreg Roach 2 => 'ORDIB', 52d8809d62SGreg Roach 3 => 'KHORD', 53d8809d62SGreg Roach 4 => 'TIR', 54d8809d62SGreg Roach 5 => 'MORDA', 55d8809d62SGreg Roach 6 => 'SHAHR', 56d8809d62SGreg Roach 7 => 'MEHR', 57d8809d62SGreg Roach 8 => 'ABAN', 58d8809d62SGreg Roach 9 => 'AZAR', 59d8809d62SGreg Roach 10 => 'DEY', 60d8809d62SGreg Roach 11 => 'BAHMA', 61d8809d62SGreg Roach 12 => 'ESFAN', 62d8809d62SGreg Roach ]; 63d8809d62SGreg Roach 6476692c8bSGreg Roach /** 6576692c8bSGreg Roach * Create a date from either: 6676692c8bSGreg Roach * a Julian day number 6776692c8bSGreg Roach * day/month/year strings from a GEDCOM date 6876692c8bSGreg Roach * another CalendarDate object 6976692c8bSGreg Roach * 70f4c767fdSGreg Roach * @param array<string>|int|AbstractCalendarDate $date 7176692c8bSGreg Roach */ 72c1010edaSGreg Roach public function __construct($date) 73c1010edaSGreg Roach { 7459f2f229SGreg Roach $this->calendar = new PersianCalendar(); 75a25f0a04SGreg Roach parent::__construct($date); 76a25f0a04SGreg Roach } 77a25f0a04SGreg Roach 7876692c8bSGreg Roach /** 7976692c8bSGreg Roach * Full month name in nominative case. 8076692c8bSGreg Roach * 817bb2eb25SGreg Roach * @param int $month 8276692c8bSGreg Roach * @param bool $leap_year Some calendars use leap months 8376692c8bSGreg Roach * 8476692c8bSGreg Roach * @return string 8576692c8bSGreg Roach */ 867bb2eb25SGreg Roach protected function monthNameNominativeCase(int $month, bool $leap_year): string 87c1010edaSGreg Roach { 88a25f0a04SGreg Roach static $translated_month_names; 89a25f0a04SGreg Roach 90a25f0a04SGreg Roach if ($translated_month_names === null) { 9113abd6f3SGreg Roach $translated_month_names = [ 92a25f0a04SGreg Roach 0 => '', 93bbb76c12SGreg Roach /* I18N: 1st month in the Persian/Jalali calendar */ 94bbb76c12SGreg Roach 1 => I18N::translateContext('NOMINATIVE', 'Farvardin'), 95bbb76c12SGreg Roach /* I18N: 2nd month in the Persian/Jalali calendar */ 96bbb76c12SGreg Roach 2 => I18N::translateContext('NOMINATIVE', 'Ordibehesht'), 97bbb76c12SGreg Roach /* I18N: 3rd month in the Persian/Jalali calendar */ 98bbb76c12SGreg Roach 3 => I18N::translateContext('NOMINATIVE', 'Khordad'), 99bbb76c12SGreg Roach /* I18N: 4th month in the Persian/Jalali calendar */ 100bbb76c12SGreg Roach 4 => I18N::translateContext('NOMINATIVE', 'Tir'), 101bbb76c12SGreg Roach /* I18N: 5th month in the Persian/Jalali calendar */ 102bbb76c12SGreg Roach 5 => I18N::translateContext('NOMINATIVE', 'Mordad'), 103bbb76c12SGreg Roach /* I18N: 6th month in the Persian/Jalali calendar */ 104bbb76c12SGreg Roach 6 => I18N::translateContext('NOMINATIVE', 'Shahrivar'), 105bbb76c12SGreg Roach /* I18N: 7th month in the Persian/Jalali calendar */ 106bbb76c12SGreg Roach 7 => I18N::translateContext('NOMINATIVE', 'Mehr'), 107bbb76c12SGreg Roach /* I18N: 8th month in the Persian/Jalali calendar */ 108bbb76c12SGreg Roach 8 => I18N::translateContext('NOMINATIVE', 'Aban'), 109bbb76c12SGreg Roach /* I18N: 9th month in the Persian/Jalali calendar */ 110bbb76c12SGreg Roach 9 => I18N::translateContext('NOMINATIVE', 'Azar'), 111bbb76c12SGreg Roach /* I18N: 10th month in the Persian/Jalali calendar */ 112bbb76c12SGreg Roach 10 => I18N::translateContext('NOMINATIVE', 'Dey'), 113bbb76c12SGreg Roach /* I18N: 11th month in the Persian/Jalali calendar */ 114bbb76c12SGreg Roach 11 => I18N::translateContext('NOMINATIVE', 'Bahman'), 115bbb76c12SGreg Roach /* I18N: 12th month in the Persian/Jalali calendar */ 116bbb76c12SGreg Roach 12 => I18N::translateContext('NOMINATIVE', 'Esfand'), 11713abd6f3SGreg Roach ]; 118a25f0a04SGreg Roach } 119a25f0a04SGreg Roach 1207bb2eb25SGreg Roach return $translated_month_names[$month]; 121a25f0a04SGreg Roach } 122a25f0a04SGreg Roach 12376692c8bSGreg Roach /** 12476692c8bSGreg Roach * Full month name in genitive case. 12576692c8bSGreg Roach * 1267bb2eb25SGreg Roach * @param int $month 12776692c8bSGreg Roach * @param bool $leap_year Some calendars use leap months 12876692c8bSGreg Roach * 12976692c8bSGreg Roach * @return string 13076692c8bSGreg Roach */ 1317bb2eb25SGreg Roach protected function monthNameGenitiveCase(int $month, bool $leap_year): string 132c1010edaSGreg Roach { 133a25f0a04SGreg Roach static $translated_month_names; 134a25f0a04SGreg Roach 135a25f0a04SGreg Roach if ($translated_month_names === null) { 13613abd6f3SGreg Roach $translated_month_names = [ 137a25f0a04SGreg Roach 0 => '', 138bbb76c12SGreg Roach /* I18N: 1st month in the Persian/Jalali calendar */ 139bbb76c12SGreg Roach 1 => I18N::translateContext('GENITIVE', 'Farvardin'), 140bbb76c12SGreg Roach /* I18N: 2nd month in the Persian/Jalali calendar */ 141bbb76c12SGreg Roach 2 => I18N::translateContext('GENITIVE', 'Ordibehesht'), 142bbb76c12SGreg Roach /* I18N: 3rd month in the Persian/Jalali calendar */ 143bbb76c12SGreg Roach 3 => I18N::translateContext('GENITIVE', 'Khordad'), 144bbb76c12SGreg Roach /* I18N: 4th month in the Persian/Jalali calendar */ 145bbb76c12SGreg Roach 4 => I18N::translateContext('GENITIVE', 'Tir'), 146bbb76c12SGreg Roach /* I18N: 5th month in the Persian/Jalali calendar */ 147bbb76c12SGreg Roach 5 => I18N::translateContext('GENITIVE', 'Mordad'), 148bbb76c12SGreg Roach /* I18N: 6th month in the Persian/Jalali calendar */ 149bbb76c12SGreg Roach 6 => I18N::translateContext('GENITIVE', 'Shahrivar'), 150bbb76c12SGreg Roach /* I18N: 7th month in the Persian/Jalali calendar */ 151bbb76c12SGreg Roach 7 => I18N::translateContext('GENITIVE', 'Mehr'), 152bbb76c12SGreg Roach /* I18N: 8th month in the Persian/Jalali calendar */ 153bbb76c12SGreg Roach 8 => I18N::translateContext('GENITIVE', 'Aban'), 154bbb76c12SGreg Roach /* I18N: 9th month in the Persian/Jalali calendar */ 155bbb76c12SGreg Roach 9 => I18N::translateContext('GENITIVE', 'Azar'), 156bbb76c12SGreg Roach /* I18N: 10th month in the Persian/Jalali calendar */ 157bbb76c12SGreg Roach 10 => I18N::translateContext('GENITIVE', 'Dey'), 158bbb76c12SGreg Roach /* I18N: 11th month in the Persian/Jalali calendar */ 159bbb76c12SGreg Roach 11 => I18N::translateContext('GENITIVE', 'Bahman'), 160bbb76c12SGreg Roach /* I18N: 12th month in the Persian/Jalali calendar */ 161bbb76c12SGreg Roach 12 => I18N::translateContext('GENITIVE', 'Esfand'), 16213abd6f3SGreg Roach ]; 163a25f0a04SGreg Roach } 164a25f0a04SGreg Roach 1657bb2eb25SGreg Roach return $translated_month_names[$month]; 166a25f0a04SGreg Roach } 167a25f0a04SGreg Roach 16876692c8bSGreg Roach /** 16976692c8bSGreg Roach * Full month name in locative case. 17076692c8bSGreg Roach * 1717bb2eb25SGreg Roach * @param int $month 17276692c8bSGreg Roach * @param bool $leap_year Some calendars use leap months 17376692c8bSGreg Roach * 17476692c8bSGreg Roach * @return string 17576692c8bSGreg Roach */ 1767bb2eb25SGreg Roach protected function monthNameLocativeCase(int $month, bool $leap_year): string 177c1010edaSGreg Roach { 178a25f0a04SGreg Roach static $translated_month_names; 179a25f0a04SGreg Roach 180a25f0a04SGreg Roach if ($translated_month_names === null) { 18113abd6f3SGreg Roach $translated_month_names = [ 182a25f0a04SGreg Roach 0 => '', 183bbb76c12SGreg Roach /* I18N: 1st month in the Persian/Jalali calendar */ 184bbb76c12SGreg Roach 1 => I18N::translateContext('LOCATIVE', 'Farvardin'), 185bbb76c12SGreg Roach /* I18N: 2nd month in the Persian/Jalali calendar */ 186bbb76c12SGreg Roach 2 => I18N::translateContext('LOCATIVE', 'Ordibehesht'), 187bbb76c12SGreg Roach /* I18N: 3rd month in the Persian/Jalali calendar */ 188bbb76c12SGreg Roach 3 => I18N::translateContext('LOCATIVE', 'Khordad'), 189bbb76c12SGreg Roach /* I18N: 4th month in the Persian/Jalali calendar */ 190bbb76c12SGreg Roach 4 => I18N::translateContext('LOCATIVE', 'Tir'), 191bbb76c12SGreg Roach /* I18N: 5th month in the Persian/Jalali calendar */ 192bbb76c12SGreg Roach 5 => I18N::translateContext('LOCATIVE', 'Mordad'), 193bbb76c12SGreg Roach /* I18N: 6th month in the Persian/Jalali calendar */ 194bbb76c12SGreg Roach 6 => I18N::translateContext('LOCATIVE', 'Shahrivar'), 195bbb76c12SGreg Roach /* I18N: 7th month in the Persian/Jalali calendar */ 196bbb76c12SGreg Roach 7 => I18N::translateContext('LOCATIVE', 'Mehr'), 197bbb76c12SGreg Roach /* I18N: 8th month in the Persian/Jalali calendar */ 198bbb76c12SGreg Roach 8 => I18N::translateContext('LOCATIVE', 'Aban'), 199bbb76c12SGreg Roach /* I18N: 9th month in the Persian/Jalali calendar */ 200bbb76c12SGreg Roach 9 => I18N::translateContext('LOCATIVE', 'Azar'), 201bbb76c12SGreg Roach /* I18N: 10th month in the Persian/Jalali calendar */ 202bbb76c12SGreg Roach 10 => I18N::translateContext('LOCATIVE', 'Dey'), 203bbb76c12SGreg Roach /* I18N: 11th month in the Persian/Jalali calendar */ 204bbb76c12SGreg Roach 11 => I18N::translateContext('LOCATIVE', 'Bahman'), 205bbb76c12SGreg Roach /* I18N: 12th month in the Persian/Jalali calendar */ 206bbb76c12SGreg Roach 12 => I18N::translateContext('LOCATIVE', 'Esfand'), 20713abd6f3SGreg Roach ]; 208a25f0a04SGreg Roach } 209a25f0a04SGreg Roach 2107bb2eb25SGreg Roach return $translated_month_names[$month]; 211a25f0a04SGreg Roach } 212a25f0a04SGreg Roach 21376692c8bSGreg Roach /** 21476692c8bSGreg Roach * Full month name in instrumental case. 21576692c8bSGreg Roach * 2167bb2eb25SGreg Roach * @param int $month 21776692c8bSGreg Roach * @param bool $leap_year Some calendars use leap months 21876692c8bSGreg Roach * 21976692c8bSGreg Roach * @return string 22076692c8bSGreg Roach */ 2217bb2eb25SGreg Roach protected function monthNameInstrumentalCase(int $month, bool $leap_year): string 222c1010edaSGreg Roach { 223a25f0a04SGreg Roach static $translated_month_names; 224a25f0a04SGreg Roach 225a25f0a04SGreg Roach if ($translated_month_names === null) { 22613abd6f3SGreg Roach $translated_month_names = [ 227a25f0a04SGreg Roach 0 => '', 228bbb76c12SGreg Roach /* I18N: 1st month in the Persian/Jalali calendar */ 229bbb76c12SGreg Roach 1 => I18N::translateContext('INSTRUMENTAL', 'Farvardin'), 230bbb76c12SGreg Roach /* I18N: 2nd month in the Persian/Jalali calendar */ 231bbb76c12SGreg Roach 2 => I18N::translateContext('INSTRUMENTAL', 'Ordibehesht'), 232bbb76c12SGreg Roach /* I18N: 3rd month in the Persian/Jalali calendar */ 233bbb76c12SGreg Roach 3 => I18N::translateContext('INSTRUMENTAL', 'Khordad'), 234bbb76c12SGreg Roach /* I18N: 4th month in the Persian/Jalali calendar */ 235bbb76c12SGreg Roach 4 => I18N::translateContext('INSTRUMENTAL', 'Tir'), 236bbb76c12SGreg Roach /* I18N: 5th month in the Persian/Jalali calendar */ 237bbb76c12SGreg Roach 5 => I18N::translateContext('INSTRUMENTAL', 'Mordad'), 238bbb76c12SGreg Roach /* I18N: 6th month in the Persian/Jalali calendar */ 239bbb76c12SGreg Roach 6 => I18N::translateContext('INSTRUMENTAL', 'Shahrivar'), 240bbb76c12SGreg Roach /* I18N: 7th month in the Persian/Jalali calendar */ 241bbb76c12SGreg Roach 7 => I18N::translateContext('INSTRUMENTAL', 'Mehr'), 242bbb76c12SGreg Roach /* I18N: 8th month in the Persian/Jalali calendar */ 243bbb76c12SGreg Roach 8 => I18N::translateContext('INSTRUMENTAL', 'Aban'), 244bbb76c12SGreg Roach /* I18N: 9th month in the Persian/Jalali calendar */ 245bbb76c12SGreg Roach 9 => I18N::translateContext('INSTRUMENTAL', 'Azar'), 246bbb76c12SGreg Roach /* I18N: 10th month in the Persian/Jalali calendar */ 247bbb76c12SGreg Roach 10 => I18N::translateContext('INSTRUMENTAL', 'Dey'), 248bbb76c12SGreg Roach /* I18N: 11th month in the Persian/Jalali calendar */ 249bbb76c12SGreg Roach 11 => I18N::translateContext('INSTRUMENTAL', 'Bahman'), 250bbb76c12SGreg Roach /* I18N: 12th month in the Persian/Jalali calendar */ 251bbb76c12SGreg Roach 12 => I18N::translateContext('INSTRUMENTAL', 'Esfand'), 25213abd6f3SGreg Roach ]; 253a25f0a04SGreg Roach } 254a25f0a04SGreg Roach 2557bb2eb25SGreg Roach return $translated_month_names[$month]; 256a25f0a04SGreg Roach } 257a25f0a04SGreg Roach 25876692c8bSGreg Roach /** 25976692c8bSGreg Roach * Abbreviated month name 26076692c8bSGreg Roach * 2617bb2eb25SGreg Roach * @param int $month 26276692c8bSGreg Roach * @param bool $leap_year Some calendars use leap months 26376692c8bSGreg Roach * 26476692c8bSGreg Roach * @return string 26576692c8bSGreg Roach */ 2667bb2eb25SGreg Roach protected function monthNameAbbreviated(int $month, bool $leap_year): string 267c1010edaSGreg Roach { 268a25f0a04SGreg Roach static $translated_month_names; 269a25f0a04SGreg Roach 270a25f0a04SGreg Roach if ($translated_month_names === null) { 27113abd6f3SGreg Roach $translated_month_names = [ 272a25f0a04SGreg Roach 0 => '', 273764a01d9SGreg Roach 1 => I18N::translateContext('Abbreviation for Persian month: Farvardin', 'Far'), 274764a01d9SGreg Roach 2 => I18N::translateContext('Abbreviation for Persian month: Ordibehesht', 'Ord'), 275764a01d9SGreg Roach 3 => I18N::translateContext('Abbreviation for Persian month: Khordad', 'Khor'), 276764a01d9SGreg Roach 4 => I18N::translateContext('Abbreviation for Persian month: Tir', 'Tir'), 277764a01d9SGreg Roach 5 => I18N::translateContext('Abbreviation for Persian month: Mordad', 'Mor'), 278764a01d9SGreg Roach 6 => I18N::translateContext('Abbreviation for Persian month: Shahrivar', 'Shah'), 279764a01d9SGreg Roach 7 => I18N::translateContext('Abbreviation for Persian month: Mehr', 'Mehr'), 280764a01d9SGreg Roach 8 => I18N::translateContext('Abbreviation for Persian month: Aban', 'Aban'), 281764a01d9SGreg Roach 9 => I18N::translateContext('Abbreviation for Persian month: Azar', 'Azar'), 282764a01d9SGreg Roach 10 => I18N::translateContext('Abbreviation for Persian month: Dey', 'Dey'), 283764a01d9SGreg Roach 11 => I18N::translateContext('Abbreviation for Persian month: Bahman', 'Bah'), 284764a01d9SGreg Roach 12 => I18N::translateContext('Abbreviation for Persian month: Esfand', 'Esf'), 28513abd6f3SGreg Roach ]; 286a25f0a04SGreg Roach } 287a25f0a04SGreg Roach 2887bb2eb25SGreg Roach return $translated_month_names[$month]; 289a25f0a04SGreg Roach } 290a25f0a04SGreg Roach} 291