xref: /webtrees/app/Date/HijriDate.php (revision 1062a1429914c995339f502856821457aa975a5a)
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\ArabicCalendar;
190e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N;
20a25f0a04SGreg Roach
21a25f0a04SGreg Roach/**
2276692c8bSGreg Roach * Definitions for the Hijri calendar.
23a25f0a04SGreg Roach *
24a25f0a04SGreg Roach * Note that these are "theoretical" dates.
25a25f0a04SGreg Roach * "True" dates are based on local lunar observations, and can be a +/- one day.
26a25f0a04SGreg Roach */
27a25f0a04SGreg Roachclass HijriDate extends CalendarDate {
28e2052359SGreg Roach	/** @var int[] Convert GEDCOM month names to month numbers  */
2913abd6f3SGreg Roach	public static $MONTH_ABBREV = ['' => 0, 'MUHAR' => 1, 'SAFAR' => 2, 'RABIA' => 3, 'RABIT' => 4, 'JUMAA' => 5, 'JUMAT' => 6, 'RAJAB' => 7, 'SHAAB' => 8, 'RAMAD' => 9, 'SHAWW' => 10, 'DHUAQ' => 11, 'DHUAH' => 12];
30a25f0a04SGreg Roach
3176692c8bSGreg Roach	/**
3276692c8bSGreg Roach	 * Create a date from either:
3376692c8bSGreg Roach	 * a Julian day number
3476692c8bSGreg Roach	 * day/month/year strings from a GEDCOM date
3576692c8bSGreg Roach	 * another CalendarDate object
3676692c8bSGreg Roach	 *
3776692c8bSGreg Roach	 * @param array|int|CalendarDate $date
3876692c8bSGreg Roach	 */
39a25f0a04SGreg Roach	public function __construct($date) {
40a25f0a04SGreg Roach		$this->calendar = new ArabicCalendar;
41a25f0a04SGreg Roach		parent::__construct($date);
42a25f0a04SGreg Roach	}
43a25f0a04SGreg Roach
4476692c8bSGreg Roach	/**
4576692c8bSGreg Roach	 * Full month name in nominative case.
4676692c8bSGreg Roach	 *
4776692c8bSGreg Roach	 * @param int  $month_number
4876692c8bSGreg Roach	 * @param bool $leap_year    Some calendars use leap months
4976692c8bSGreg Roach	 *
5076692c8bSGreg Roach	 * @return string
5176692c8bSGreg Roach	 */
52a25f0a04SGreg Roach	public static function monthNameNominativeCase($month_number, $leap_year) {
53a25f0a04SGreg Roach		static $translated_month_names;
54a25f0a04SGreg Roach
55a25f0a04SGreg Roach		if ($translated_month_names === null) {
5613abd6f3SGreg Roach			$translated_month_names = [
57a25f0a04SGreg Roach				0  => '',
58764a01d9SGreg Roach				1  => /* I18N: http://en.wikipedia.org/wiki/Muharram */ I18N::translateContext('NOMINATIVE', 'Muharram'),
59764a01d9SGreg Roach				2  => /* I18N: http://en.wikipedia.org/wiki/Safar */ I18N::translateContext('NOMINATIVE', 'Safar'),
60764a01d9SGreg Roach				3  => /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-awwal */ I18N::translateContext('NOMINATIVE', 'Rabi’ al-awwal'),
61764a01d9SGreg Roach				4  => /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-thani */ I18N::translateContext('NOMINATIVE', 'Rabi’ al-thani'),
62764a01d9SGreg Roach				5  => /* I18N: http://en.wikipedia.org/wiki/Jumada_al-awwal */ I18N::translateContext('NOMINATIVE', 'Jumada al-awwal'),
63764a01d9SGreg Roach				6  => /* I18N: http://en.wikipedia.org/wiki/Jumada_al-thani */ I18N::translateContext('NOMINATIVE', 'Jumada al-thani'),
64764a01d9SGreg Roach				7  => /* I18N: http://en.wikipedia.org/wiki/Rajab */ I18N::translateContext('NOMINATIVE', 'Rajab'),
65764a01d9SGreg Roach				8  => /* I18N: http://en.wikipedia.org/wiki/Sha%27aban */ I18N::translateContext('NOMINATIVE', 'Sha’aban'),
66764a01d9SGreg Roach				9  => /* I18N: http://en.wikipedia.org/wiki/Ramadan_%28calendar_month%29 */ I18N::translateContext('NOMINATIVE', 'Ramadan'),
67764a01d9SGreg Roach				10 => /* I18N: http://en.wikipedia.org/wiki/Shawwal */ I18N::translateContext('NOMINATIVE', 'Shawwal'),
68764a01d9SGreg Roach				11 => /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Qi%27dah */ I18N::translateContext('NOMINATIVE', 'Dhu al-Qi’dah'),
69764a01d9SGreg Roach				12 => /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Hijjah */ I18N::translateContext('NOMINATIVE', 'Dhu al-Hijjah'),
7013abd6f3SGreg Roach			];
71a25f0a04SGreg Roach		}
72a25f0a04SGreg Roach
73a25f0a04SGreg Roach		return $translated_month_names[$month_number];
74a25f0a04SGreg Roach	}
75a25f0a04SGreg Roach
7676692c8bSGreg Roach	/**
7776692c8bSGreg Roach	 * Full month name in genitive case.
7876692c8bSGreg Roach	 *
7976692c8bSGreg Roach	 * @param int  $month_number
8076692c8bSGreg Roach	 * @param bool $leap_year    Some calendars use leap months
8176692c8bSGreg Roach	 *
8276692c8bSGreg Roach	 * @return string
8376692c8bSGreg Roach	 */
8417920f94SGreg Roach	protected function monthNameGenitiveCase($month_number, $leap_year) {
85a25f0a04SGreg Roach		static $translated_month_names;
86a25f0a04SGreg Roach
87a25f0a04SGreg Roach		if ($translated_month_names === null) {
8813abd6f3SGreg Roach			$translated_month_names = [
89a25f0a04SGreg Roach				0  => '',
90764a01d9SGreg Roach				1  => /* I18N: http://en.wikipedia.org/wiki/Muharram */ I18N::translateContext('GENITIVE', 'Muharram'),
91764a01d9SGreg Roach				2  => /* I18N: http://en.wikipedia.org/wiki/Safar */ I18N::translateContext('GENITIVE', 'Safar'),
92764a01d9SGreg Roach				3  => /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-awwal */ I18N::translateContext('GENITIVE', 'Rabi’ al-awwal'),
93764a01d9SGreg Roach				4  => /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-thani */ I18N::translateContext('GENITIVE', 'Rabi’ al-thani'),
94764a01d9SGreg Roach				5  => /* I18N: http://en.wikipedia.org/wiki/Jumada_al-awwal */ I18N::translateContext('GENITIVE', 'Jumada al-awwal'),
95764a01d9SGreg Roach				6  => /* I18N: http://en.wikipedia.org/wiki/Jumada_al-thani */ I18N::translateContext('GENITIVE', 'Jumada al-thani'),
96764a01d9SGreg Roach				7  => /* I18N: http://en.wikipedia.org/wiki/Rajab */ I18N::translateContext('GENITIVE', 'Rajab'),
97764a01d9SGreg Roach				8  => /* I18N: http://en.wikipedia.org/wiki/Sha%27aban */ I18N::translateContext('GENITIVE', 'Sha’aban'),
98764a01d9SGreg Roach				9  => /* I18N: http://en.wikipedia.org/wiki/Ramadan_%28calendar_month%29 */ I18N::translateContext('GENITIVE', 'Ramadan'),
99764a01d9SGreg Roach				10 => /* I18N: http://en.wikipedia.org/wiki/Shawwal */ I18N::translateContext('GENITIVE', 'Shawwal'),
100764a01d9SGreg Roach				11 => /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Qi%27dah */ I18N::translateContext('GENITIVE', 'Dhu al-Qi’dah'),
101764a01d9SGreg Roach				12 => /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Hijjah */ I18N::translateContext('GENITIVE', 'Dhu al-Hijjah'),
10213abd6f3SGreg Roach			];
103a25f0a04SGreg Roach		}
104a25f0a04SGreg Roach
105a25f0a04SGreg Roach		return $translated_month_names[$month_number];
106a25f0a04SGreg Roach	}
107a25f0a04SGreg Roach
10876692c8bSGreg Roach	/**
10976692c8bSGreg Roach	 * Full month name in locative case.
11076692c8bSGreg Roach	 *
11176692c8bSGreg Roach	 * @param int  $month_number
11276692c8bSGreg Roach	 * @param bool $leap_year    Some calendars use leap months
11376692c8bSGreg Roach	 *
11476692c8bSGreg Roach	 * @return string
11576692c8bSGreg Roach	 */
11617920f94SGreg Roach	protected function monthNameLocativeCase($month_number, $leap_year) {
117a25f0a04SGreg Roach		static $translated_month_names;
118a25f0a04SGreg Roach
119a25f0a04SGreg Roach		if ($translated_month_names === null) {
12013abd6f3SGreg Roach			$translated_month_names = [
121a25f0a04SGreg Roach				0  => '',
122764a01d9SGreg Roach				1  => /* I18N: http://en.wikipedia.org/wiki/Muharram */ I18N::translateContext('LOCATIVE', 'Muharram'),
123764a01d9SGreg Roach				2  => /* I18N: http://en.wikipedia.org/wiki/Safar */ I18N::translateContext('LOCATIVE', 'Safar'),
124764a01d9SGreg Roach				3  => /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-awwal */ I18N::translateContext('LOCATIVE', 'Rabi’ al-awwal'),
125764a01d9SGreg Roach				4  => /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-thani */ I18N::translateContext('LOCATIVE', 'Rabi’ al-thani'),
126764a01d9SGreg Roach				5  => /* I18N: http://en.wikipedia.org/wiki/Jumada_al-awwal */ I18N::translateContext('LOCATIVE', 'Jumada al-awwal'),
127764a01d9SGreg Roach				6  => /* I18N: http://en.wikipedia.org/wiki/Jumada_al-thani */ I18N::translateContext('LOCATIVE', 'Jumada al-thani'),
128764a01d9SGreg Roach				7  => /* I18N: http://en.wikipedia.org/wiki/Rajab */ I18N::translateContext('LOCATIVE', 'Rajab'),
129764a01d9SGreg Roach				8  => /* I18N: http://en.wikipedia.org/wiki/Sha%27aban */ I18N::translateContext('LOCATIVE', 'Sha’aban'),
130764a01d9SGreg Roach				9  => /* I18N: http://en.wikipedia.org/wiki/Ramadan_%28calendar_month%29 */ I18N::translateContext('LOCATIVE', 'Ramadan'),
131764a01d9SGreg Roach				10 => /* I18N: http://en.wikipedia.org/wiki/Shawwal */ I18N::translateContext('LOCATIVE', 'Shawwal'),
132764a01d9SGreg Roach				11 => /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Qi%27dah */ I18N::translateContext('LOCATIVE', 'Dhu al-Qi’dah'),
133764a01d9SGreg Roach				12 => /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Hijjah */ I18N::translateContext('LOCATIVE', 'Dhu al-Hijjah'),
13413abd6f3SGreg Roach			];
135a25f0a04SGreg Roach		}
136a25f0a04SGreg Roach
137a25f0a04SGreg Roach		return $translated_month_names[$month_number];
138a25f0a04SGreg Roach	}
139a25f0a04SGreg Roach
14076692c8bSGreg Roach	/**
14176692c8bSGreg Roach	 * Full month name in instrumental case.
14276692c8bSGreg Roach	 *
14376692c8bSGreg Roach	 * @param int  $month_number
14476692c8bSGreg Roach	 * @param bool $leap_year    Some calendars use leap months
14576692c8bSGreg Roach	 *
14676692c8bSGreg Roach	 * @return string
14776692c8bSGreg Roach	 */
14817920f94SGreg Roach	protected function monthNameInstrumentalCase($month_number, $leap_year) {
149a25f0a04SGreg Roach		static $translated_month_names;
150a25f0a04SGreg Roach
151a25f0a04SGreg Roach		if ($translated_month_names === null) {
15213abd6f3SGreg Roach			$translated_month_names = [
153a25f0a04SGreg Roach				0  => '',
154764a01d9SGreg Roach				1  => /* I18N: http://en.wikipedia.org/wiki/Muharram */ I18N::translateContext('INSTRUMENTAL', 'Muharram'),
155764a01d9SGreg Roach				2  => /* I18N: http://en.wikipedia.org/wiki/Safar */ I18N::translateContext('INSTRUMENTAL', 'Safar'),
156764a01d9SGreg Roach				3  => /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-awwal */ I18N::translateContext('INSTRUMENTAL', 'Rabi’ al-awwal'),
157764a01d9SGreg Roach				4  => /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-thani */ I18N::translateContext('INSTRUMENTAL', 'Rabi’ al-thani'),
158764a01d9SGreg Roach				5  => /* I18N: http://en.wikipedia.org/wiki/Jumada_al-awwal */ I18N::translateContext('INSTRUMENTAL', 'Jumada al-awwal'),
159764a01d9SGreg Roach				6  => /* I18N: http://en.wikipedia.org/wiki/Jumada_al-thani */ I18N::translateContext('INSTRUMENTAL', 'Jumada al-thani'),
160764a01d9SGreg Roach				7  => /* I18N: http://en.wikipedia.org/wiki/Rajab */ I18N::translateContext('INSTRUMENTAL', 'Rajab'),
161764a01d9SGreg Roach				8  => /* I18N: http://en.wikipedia.org/wiki/Sha%27aban */ I18N::translateContext('INSTRUMENTAL', 'Sha’aban'),
162764a01d9SGreg Roach				9  => /* I18N: http://en.wikipedia.org/wiki/Ramadan_%28calendar_month%29 */ I18N::translateContext('INSTRUMENTAL', 'Ramadan'),
163764a01d9SGreg Roach				10 => /* I18N: http://en.wikipedia.org/wiki/Shawwal */ I18N::translateContext('INSTRUMENTAL', 'Shawwal'),
164764a01d9SGreg Roach				11 => /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Qi%27dah */ I18N::translateContext('INSTRUMENTAL', 'Dhu al-Qi’dah'),
165764a01d9SGreg Roach				12 => /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Hijjah */ I18N::translateContext('INSTRUMENTAL', 'Dhu al-Hijjah'),
16613abd6f3SGreg Roach			];
167a25f0a04SGreg Roach		}
168a25f0a04SGreg Roach
169a25f0a04SGreg Roach		return $translated_month_names[$month_number];
170a25f0a04SGreg Roach	}
171a25f0a04SGreg Roach
17276692c8bSGreg Roach	/**
17376692c8bSGreg Roach	 * Abbreviated month name
17476692c8bSGreg Roach	 *
17576692c8bSGreg Roach	 * @param int  $month_number
17676692c8bSGreg Roach	 * @param bool $leap_year    Some calendars use leap months
17776692c8bSGreg Roach	 *
17876692c8bSGreg Roach	 * @return string
17976692c8bSGreg Roach	 */
18017920f94SGreg Roach	protected function monthNameAbbreviated($month_number, $leap_year) {
181a25f0a04SGreg Roach		return self::monthNameNominativeCase($month_number, $leap_year);
182a25f0a04SGreg Roach	}
183a25f0a04SGreg Roach}
184