1a25f0a04SGreg Roach<?php 2a25f0a04SGreg Roach/** 3a25f0a04SGreg Roach * webtrees: online genealogy 4*1062a142SGreg 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\JewishCalendar; 190e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N; 20a25f0a04SGreg Roach 21a25f0a04SGreg Roach/** 2276692c8bSGreg Roach * Definitions for the Jewish calendar 23a25f0a04SGreg Roach */ 24a25f0a04SGreg Roachclass JewishDate extends CalendarDate { 25e2052359SGreg Roach /** @var int[] Convert GEDCOM month names to month numbers */ 2613abd6f3SGreg Roach public static $MONTH_ABBREV = ['' => 0, 'TSH' => 1, 'CSH' => 2, 'KSL' => 3, 'TVT' => 4, 'SHV' => 5, 'ADR' => 6, 'ADS' => 7, 'NSN' => 8, 'IYR' => 9, 'SVN' => 10, 'TMZ' => 11, 'AAV' => 12, 'ELL' => 13]; 27a25f0a04SGreg Roach 2876692c8bSGreg Roach /** 2976692c8bSGreg Roach * Create a date from either: 3076692c8bSGreg Roach * a Julian day number 3176692c8bSGreg Roach * day/month/year strings from a GEDCOM date 3276692c8bSGreg Roach * another CalendarDate object 3376692c8bSGreg Roach * 3476692c8bSGreg Roach * @param array|int|CalendarDate $date 3576692c8bSGreg Roach */ 36a25f0a04SGreg Roach public function __construct($date) { 37a25f0a04SGreg Roach $this->calendar = new JewishCalendar; 38a25f0a04SGreg Roach parent::__construct($date); 39a25f0a04SGreg Roach } 40a25f0a04SGreg Roach 4176692c8bSGreg Roach /** 4276692c8bSGreg Roach * Generate the %j format for a date. 4376692c8bSGreg Roach * 4476692c8bSGreg Roach * @return string 4576692c8bSGreg Roach */ 4617920f94SGreg Roach protected function formatDay() { 4717920f94SGreg Roach if (WT_LOCALE === 'he' || WT_LOCALE === 'yi') { 4817920f94SGreg Roach return $this->calendar->numberToHebrewNumerals($this->d, true); 49a25f0a04SGreg Roach } else { 50a25f0a04SGreg Roach return $this->d; 51a25f0a04SGreg Roach } 52a25f0a04SGreg Roach } 53a25f0a04SGreg Roach 5476692c8bSGreg Roach /** 5576692c8bSGreg Roach * Generate the %y format for a date. 5676692c8bSGreg Roach * 5776692c8bSGreg Roach * NOTE Short year is NOT a 2-digit year. It is for calendars such as hebrew 5876692c8bSGreg Roach * which have a 3-digit form of 4-digit years. 5976692c8bSGreg Roach * 6076692c8bSGreg Roach * @return string 6176692c8bSGreg Roach */ 6217920f94SGreg Roach protected function formatShortYear() { 6317920f94SGreg Roach if (WT_LOCALE === 'he' || WT_LOCALE === 'yi') { 6417920f94SGreg Roach return $this->calendar->numberToHebrewNumerals($this->y, false); 65a25f0a04SGreg Roach } else { 66a25f0a04SGreg Roach return $this->y; 67a25f0a04SGreg Roach } 68a25f0a04SGreg Roach } 69a25f0a04SGreg Roach 7076692c8bSGreg Roach /** 7176692c8bSGreg Roach * Generate the %Y format for a date. 7276692c8bSGreg Roach * 7376692c8bSGreg Roach * @return string 7476692c8bSGreg Roach */ 7517920f94SGreg Roach protected function formatLongYear() { 7617920f94SGreg Roach if (WT_LOCALE === 'he' || WT_LOCALE === 'yi') { 7717920f94SGreg Roach return $this->calendar->numberToHebrewNumerals($this->y, true); 78a25f0a04SGreg Roach } else { 79a25f0a04SGreg Roach return $this->y; 80a25f0a04SGreg Roach } 81a25f0a04SGreg Roach } 82a25f0a04SGreg Roach 8376692c8bSGreg Roach /** 8476692c8bSGreg Roach * Full month name in nominative case. 8576692c8bSGreg Roach * 8676692c8bSGreg Roach * @param int $month_number 8776692c8bSGreg Roach * @param bool $leap_year Some calendars use leap months 8876692c8bSGreg Roach * 8976692c8bSGreg Roach * @return string 9076692c8bSGreg Roach */ 91a25f0a04SGreg Roach public static function monthNameNominativeCase($month_number, $leap_year) { 92a25f0a04SGreg Roach static $translated_month_names; 93a25f0a04SGreg Roach 94a25f0a04SGreg Roach if ($translated_month_names === null) { 9513abd6f3SGreg Roach $translated_month_names = [ 96a25f0a04SGreg Roach 0 => '', 97764a01d9SGreg Roach 1 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('NOMINATIVE', 'Tishrei'), 98764a01d9SGreg Roach 2 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('NOMINATIVE', 'Heshvan'), 99764a01d9SGreg Roach 3 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('NOMINATIVE', 'Kislev'), 100764a01d9SGreg Roach 4 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('NOMINATIVE', 'Tevet'), 101764a01d9SGreg Roach 5 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('NOMINATIVE', 'Shevat'), 102764a01d9SGreg Roach 6 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('NOMINATIVE', 'Adar I'), 103764a01d9SGreg Roach 7 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('NOMINATIVE', 'Adar'), 104764a01d9SGreg Roach -7 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('NOMINATIVE', 'Adar II'), 105764a01d9SGreg Roach 8 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('NOMINATIVE', 'Nissan'), 106764a01d9SGreg Roach 9 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('NOMINATIVE', 'Iyar'), 107764a01d9SGreg Roach 10 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('NOMINATIVE', 'Sivan'), 108764a01d9SGreg Roach 11 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('NOMINATIVE', 'Tamuz'), 109764a01d9SGreg Roach 12 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('NOMINATIVE', 'Av'), 110764a01d9SGreg Roach 13 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('NOMINATIVE', 'Elul'), 11113abd6f3SGreg Roach ]; 112a25f0a04SGreg Roach } 113a25f0a04SGreg Roach 114a25f0a04SGreg Roach if ($month_number === 7 && $leap_year) { 115a25f0a04SGreg Roach return $translated_month_names[-7]; 116a25f0a04SGreg Roach } else { 117a25f0a04SGreg Roach return $translated_month_names[$month_number]; 118a25f0a04SGreg Roach } 119a25f0a04SGreg Roach } 120a25f0a04SGreg Roach 12176692c8bSGreg Roach /** 12276692c8bSGreg Roach * Full month name in genitive case. 12376692c8bSGreg Roach * 12476692c8bSGreg Roach * @param int $month_number 12576692c8bSGreg Roach * @param bool $leap_year Some calendars use leap months 12676692c8bSGreg Roach * 12776692c8bSGreg Roach * @return string 12876692c8bSGreg Roach */ 12917920f94SGreg Roach protected function monthNameGenitiveCase($month_number, $leap_year) { 130a25f0a04SGreg Roach static $translated_month_names; 131a25f0a04SGreg Roach 132a25f0a04SGreg Roach if ($translated_month_names === null) { 13313abd6f3SGreg Roach $translated_month_names = [ 134a25f0a04SGreg Roach 0 => '', 135764a01d9SGreg Roach 1 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('GENITIVE', 'Tishrei'), 136764a01d9SGreg Roach 2 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('GENITIVE', 'Heshvan'), 137764a01d9SGreg Roach 3 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('GENITIVE', 'Kislev'), 138764a01d9SGreg Roach 4 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('GENITIVE', 'Tevet'), 139764a01d9SGreg Roach 5 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('GENITIVE', 'Shevat'), 140764a01d9SGreg Roach 6 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('GENITIVE', 'Adar I'), 141764a01d9SGreg Roach 7 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('GENITIVE', 'Adar'), 142764a01d9SGreg Roach -7 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('GENITIVE', 'Adar II'), 143764a01d9SGreg Roach 8 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('GENITIVE', 'Nissan'), 144764a01d9SGreg Roach 9 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('GENITIVE', 'Iyar'), 145764a01d9SGreg Roach 10 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('GENITIVE', 'Sivan'), 146764a01d9SGreg Roach 11 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('GENITIVE', 'Tamuz'), 147764a01d9SGreg Roach 12 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('GENITIVE', 'Av'), 148764a01d9SGreg Roach 13 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('GENITIVE', 'Elul'), 14913abd6f3SGreg Roach ]; 150a25f0a04SGreg Roach } 151a25f0a04SGreg Roach 152a25f0a04SGreg Roach if ($month_number === 7 && $leap_year) { 153a25f0a04SGreg Roach return $translated_month_names[-7]; 154a25f0a04SGreg Roach } else { 155a25f0a04SGreg Roach return $translated_month_names[$month_number]; 156a25f0a04SGreg Roach } 157a25f0a04SGreg Roach } 158a25f0a04SGreg Roach 15976692c8bSGreg Roach /** 16076692c8bSGreg Roach * Full month name in locative case. 16176692c8bSGreg Roach * 16276692c8bSGreg Roach * @param int $month_number 16376692c8bSGreg Roach * @param bool $leap_year Some calendars use leap months 16476692c8bSGreg Roach * 16576692c8bSGreg Roach * @return string 16676692c8bSGreg Roach */ 16717920f94SGreg Roach protected function monthNameLocativeCase($month_number, $leap_year) { 168a25f0a04SGreg Roach static $translated_month_names; 169a25f0a04SGreg Roach 170a25f0a04SGreg Roach if ($translated_month_names === null) { 17113abd6f3SGreg Roach $translated_month_names = [ 172a25f0a04SGreg Roach 0 => '', 173764a01d9SGreg Roach 1 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('LOCATIVE', 'Tishrei'), 174764a01d9SGreg Roach 2 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('LOCATIVE', 'Heshvan'), 175764a01d9SGreg Roach 3 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('LOCATIVE', 'Kislev'), 176764a01d9SGreg Roach 4 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('LOCATIVE', 'Tevet'), 177764a01d9SGreg Roach 5 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('LOCATIVE', 'Shevat'), 178764a01d9SGreg Roach 6 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('LOCATIVE', 'Adar I'), 179764a01d9SGreg Roach 7 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('LOCATIVE', 'Adar'), 180764a01d9SGreg Roach -7 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('LOCATIVE', 'Adar II'), 181764a01d9SGreg Roach 8 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('LOCATIVE', 'Nissan'), 182764a01d9SGreg Roach 9 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('LOCATIVE', 'Iyar'), 183764a01d9SGreg Roach 10 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('LOCATIVE', 'Sivan'), 184764a01d9SGreg Roach 11 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('LOCATIVE', 'Tamuz'), 185764a01d9SGreg Roach 12 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('LOCATIVE', 'Av'), 186764a01d9SGreg Roach 13 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('LOCATIVE', 'Elul'), 18713abd6f3SGreg Roach ]; 188a25f0a04SGreg Roach } 189a25f0a04SGreg Roach 190a25f0a04SGreg Roach if ($month_number === 7 && $leap_year) { 191a25f0a04SGreg Roach return $translated_month_names[-7]; 192a25f0a04SGreg Roach } else { 193a25f0a04SGreg Roach return $translated_month_names[$month_number]; 194a25f0a04SGreg Roach } 195a25f0a04SGreg Roach } 196a25f0a04SGreg Roach 19776692c8bSGreg Roach /** 19876692c8bSGreg Roach * Full month name in instrumental case. 19976692c8bSGreg Roach * 20076692c8bSGreg Roach * @param int $month_number 20176692c8bSGreg Roach * @param bool $leap_year Some calendars use leap months 20276692c8bSGreg Roach * 20376692c8bSGreg Roach * @return string 20476692c8bSGreg Roach */ 20517920f94SGreg Roach protected function monthNameInstrumentalCase($month_number, $leap_year) { 206a25f0a04SGreg Roach static $translated_month_names; 207a25f0a04SGreg Roach 208a25f0a04SGreg Roach if ($translated_month_names === null) { 20913abd6f3SGreg Roach $translated_month_names = [ 210a25f0a04SGreg Roach 0 => '', 211764a01d9SGreg Roach 1 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('INSTRUMENTAL', 'Tishrei'), 212764a01d9SGreg Roach 2 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('INSTRUMENTAL', 'Heshvan'), 213764a01d9SGreg Roach 3 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('INSTRUMENTAL', 'Kislev'), 214764a01d9SGreg Roach 4 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('INSTRUMENTAL', 'Tevet'), 215764a01d9SGreg Roach 5 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('INSTRUMENTAL', 'Shevat'), 216764a01d9SGreg Roach 6 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('INSTRUMENTAL', 'Adar I'), 217764a01d9SGreg Roach 7 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('INSTRUMENTAL', 'Adar'), 218764a01d9SGreg Roach -7 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('INSTRUMENTAL', 'Adar II'), 219764a01d9SGreg Roach 8 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('INSTRUMENTAL', 'Nissan'), 220764a01d9SGreg Roach 9 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('INSTRUMENTAL', 'Iyar'), 221764a01d9SGreg Roach 10 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('INSTRUMENTAL', 'Sivan'), 222764a01d9SGreg Roach 11 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('INSTRUMENTAL', 'Tamuz'), 223764a01d9SGreg Roach 12 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('INSTRUMENTAL', 'Av'), 224764a01d9SGreg Roach 13 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('INSTRUMENTAL', 'Elul'), 22513abd6f3SGreg Roach ]; 226a25f0a04SGreg Roach } 227a25f0a04SGreg Roach 228a25f0a04SGreg Roach if ($month_number === 7 && $leap_year) { 229a25f0a04SGreg Roach return $translated_month_names[-7]; 230a25f0a04SGreg Roach } else { 231a25f0a04SGreg Roach return $translated_month_names[$month_number]; 232a25f0a04SGreg Roach } 233a25f0a04SGreg Roach } 234a25f0a04SGreg Roach 23576692c8bSGreg Roach /** 23676692c8bSGreg Roach * Abbreviated month name 23776692c8bSGreg Roach * 23876692c8bSGreg Roach * @param int $month_number 23976692c8bSGreg Roach * @param bool $leap_year Some calendars use leap months 24076692c8bSGreg Roach * 24176692c8bSGreg Roach * @return string 24276692c8bSGreg Roach */ 24317920f94SGreg Roach protected function monthNameAbbreviated($month_number, $leap_year) { 244a25f0a04SGreg Roach return self::monthNameNominativeCase($month_number, $leap_year); 245a25f0a04SGreg Roach } 246a25f0a04SGreg Roach 24776692c8bSGreg Roach /** 24876692c8bSGreg Roach * Which months follows this one? Calendars with leap-months should provide their own implementation. 24976692c8bSGreg Roach * 250e2052359SGreg Roach * @return int[] 25176692c8bSGreg Roach */ 252a25f0a04SGreg Roach protected function nextMonth() { 253a25f0a04SGreg Roach if ($this->m == 6 && !$this->isLeapYear()) { 25413abd6f3SGreg Roach return [$this->y, 8]; 255a25f0a04SGreg Roach } else { 25613abd6f3SGreg Roach return [$this->y + ($this->m == 13 ? 1 : 0), ($this->m % 13) + 1]; 257a25f0a04SGreg Roach } 258a25f0a04SGreg Roach } 259a25f0a04SGreg Roach} 260