xref: /webtrees/app/Date/HijriDate.php (revision ad3143cc1f5191f21ec566a4ccc46aa1a5e4f909)
1a25f0a04SGreg Roach<?php
23976b470SGreg Roach
3a25f0a04SGreg Roach/**
4a25f0a04SGreg Roach * webtrees: online genealogy
589f7189bSGreg 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
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\ArabicCalendar;
230e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N;
24a25f0a04SGreg Roach
25a25f0a04SGreg Roach/**
264a83f5d7SGreg Roach * Definitions for Hijri dates.
27a25f0a04SGreg Roach *
28a25f0a04SGreg Roach * Note that these are "theoretical" dates.
29a25f0a04SGreg Roach * "True" dates are based on local lunar observations, and can be a +/- one day.
30a25f0a04SGreg Roach */
314a83f5d7SGreg Roachclass HijriDate extends AbstractCalendarDate
32c1010edaSGreg Roach{
334a83f5d7SGreg Roach    // GEDCOM calendar escape
3416d6367aSGreg Roach    public const ESCAPE = '@#DHIJRI@';
354a83f5d7SGreg Roach
3652348eb8SGreg Roach    // Convert GEDCOM month names to month numbers
3716d6367aSGreg Roach    protected const MONTH_ABBREVIATIONS = [
38b61e86aaSGreg Roach        ''      => 0,
39c1010edaSGreg Roach        'MUHAR' => 1,
40c1010edaSGreg Roach        'SAFAR' => 2,
41c1010edaSGreg Roach        'RABIA' => 3,
42c1010edaSGreg Roach        'RABIT' => 4,
43c1010edaSGreg Roach        'JUMAA' => 5,
44c1010edaSGreg Roach        'JUMAT' => 6,
45c1010edaSGreg Roach        'RAJAB' => 7,
46c1010edaSGreg Roach        'SHAAB' => 8,
47c1010edaSGreg Roach        'RAMAD' => 9,
48c1010edaSGreg Roach        'SHAWW' => 10,
49c1010edaSGreg Roach        'DHUAQ' => 11,
50c1010edaSGreg Roach        'DHUAH' => 12,
51c1010edaSGreg Roach    ];
52a25f0a04SGreg Roach
5376692c8bSGreg Roach    /**
5476692c8bSGreg Roach     * Create a date from either:
5576692c8bSGreg Roach     * a Julian day number
5676692c8bSGreg Roach     * day/month/year strings from a GEDCOM date
5776692c8bSGreg Roach     * another CalendarDate object
5876692c8bSGreg Roach     *
59f4c767fdSGreg Roach     * @param array<string>|int|AbstractCalendarDate $date
6076692c8bSGreg Roach     */
61c1010edaSGreg Roach    public function __construct($date)
62c1010edaSGreg Roach    {
6359f2f229SGreg Roach        $this->calendar = new ArabicCalendar();
64a25f0a04SGreg Roach        parent::__construct($date);
65a25f0a04SGreg Roach    }
66a25f0a04SGreg Roach
6776692c8bSGreg Roach    /**
6876692c8bSGreg Roach     * Full month name in nominative case.
6976692c8bSGreg Roach     *
707bb2eb25SGreg Roach     * @param int  $month
7176692c8bSGreg Roach     * @param bool $leap_year Some calendars use leap months
7276692c8bSGreg Roach     *
7376692c8bSGreg Roach     * @return string
7476692c8bSGreg Roach     */
757bb2eb25SGreg Roach    protected function monthNameNominativeCase(int $month, bool $leap_year): string
76c1010edaSGreg Roach    {
77a25f0a04SGreg Roach        static $translated_month_names;
78a25f0a04SGreg Roach
79a25f0a04SGreg Roach        if ($translated_month_names === null) {
8013abd6f3SGreg Roach            $translated_month_names = [
81a25f0a04SGreg Roach                0  => '',
82*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Muharram */
83bbb76c12SGreg Roach                1  => I18N::translateContext('NOMINATIVE', 'Muharram'),
84*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Safar */
85bbb76c12SGreg Roach                2  => I18N::translateContext('NOMINATIVE', 'Safar'),
86*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Rabi%27_al-awwal */
87bbb76c12SGreg Roach                3  => I18N::translateContext('NOMINATIVE', 'Rabi’ al-awwal'),
88*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Rabi%27_al-thani */
89bbb76c12SGreg Roach                4  => I18N::translateContext('NOMINATIVE', 'Rabi’ al-thani'),
90*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Jumada_al-awwal */
91bbb76c12SGreg Roach                5  => I18N::translateContext('NOMINATIVE', 'Jumada al-awwal'),
92*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Jumada_al-thani */
93bbb76c12SGreg Roach                6  => I18N::translateContext('NOMINATIVE', 'Jumada al-thani'),
94*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Rajab */
95bbb76c12SGreg Roach                7  => I18N::translateContext('NOMINATIVE', 'Rajab'),
96*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Sha%27aban */
97bbb76c12SGreg Roach                8  => I18N::translateContext('NOMINATIVE', 'Sha’aban'),
98*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Ramadan_%28calendar_month%29 */
99bbb76c12SGreg Roach                9  => I18N::translateContext('NOMINATIVE', 'Ramadan'),
100*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Shawwal */
101bbb76c12SGreg Roach                10 => I18N::translateContext('NOMINATIVE', 'Shawwal'),
102*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Dhu_al-Qi%27dah */
103bbb76c12SGreg Roach                11 => I18N::translateContext('NOMINATIVE', 'Dhu al-Qi’dah'),
104*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Dhu_al-Hijjah */
105bbb76c12SGreg Roach                12 => I18N::translateContext('NOMINATIVE', 'Dhu al-Hijjah'),
10613abd6f3SGreg Roach            ];
107a25f0a04SGreg Roach        }
108a25f0a04SGreg Roach
1097bb2eb25SGreg Roach        return $translated_month_names[$month];
110a25f0a04SGreg Roach    }
111a25f0a04SGreg Roach
11276692c8bSGreg Roach    /**
11376692c8bSGreg Roach     * Full month name in genitive case.
11476692c8bSGreg Roach     *
1157bb2eb25SGreg Roach     * @param int  $month
11676692c8bSGreg Roach     * @param bool $leap_year Some calendars use leap months
11776692c8bSGreg Roach     *
11876692c8bSGreg Roach     * @return string
11976692c8bSGreg Roach     */
1207bb2eb25SGreg Roach    protected function monthNameGenitiveCase(int $month, bool $leap_year): string
121c1010edaSGreg Roach    {
122a25f0a04SGreg Roach        static $translated_month_names;
123a25f0a04SGreg Roach
124a25f0a04SGreg Roach        if ($translated_month_names === null) {
12513abd6f3SGreg Roach            $translated_month_names = [
126a25f0a04SGreg Roach                0  => '',
127*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Muharram */
128bbb76c12SGreg Roach                1  => I18N::translateContext('GENITIVE', 'Muharram'),
129*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Safar */
130bbb76c12SGreg Roach                2  => I18N::translateContext('GENITIVE', 'Safar'),
131*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Rabi%27_al-awwal */
132bbb76c12SGreg Roach                3  => I18N::translateContext('GENITIVE', 'Rabi’ al-awwal'),
133*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Rabi%27_al-thani */
134bbb76c12SGreg Roach                4  => I18N::translateContext('GENITIVE', 'Rabi’ al-thani'),
135*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Jumada_al-awwal */
136bbb76c12SGreg Roach                5  => I18N::translateContext('GENITIVE', 'Jumada al-awwal'),
137*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Jumada_al-thani */
138bbb76c12SGreg Roach                6  => I18N::translateContext('GENITIVE', 'Jumada al-thani'),
139*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Rajab */
140bbb76c12SGreg Roach                7  => I18N::translateContext('GENITIVE', 'Rajab'),
141*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Sha%27aban */
142bbb76c12SGreg Roach                8  => I18N::translateContext('GENITIVE', 'Sha’aban'),
143*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Ramadan_%28calendar_month%29 */
144bbb76c12SGreg Roach                9  => I18N::translateContext('GENITIVE', 'Ramadan'),
145*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Shawwal */
146bbb76c12SGreg Roach                10 => I18N::translateContext('GENITIVE', 'Shawwal'),
147*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Dhu_al-Qi%27dah */
148bbb76c12SGreg Roach                11 => I18N::translateContext('GENITIVE', 'Dhu al-Qi’dah'),
149*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Dhu_al-Hijjah */
150bbb76c12SGreg Roach                12 => I18N::translateContext('GENITIVE', 'Dhu al-Hijjah'),
15113abd6f3SGreg Roach            ];
152a25f0a04SGreg Roach        }
153a25f0a04SGreg Roach
1547bb2eb25SGreg Roach        return $translated_month_names[$month];
155a25f0a04SGreg Roach    }
156a25f0a04SGreg Roach
15776692c8bSGreg Roach    /**
15876692c8bSGreg Roach     * Full month name in locative case.
15976692c8bSGreg Roach     *
1607bb2eb25SGreg Roach     * @param int  $month
16176692c8bSGreg Roach     * @param bool $leap_year Some calendars use leap months
16276692c8bSGreg Roach     *
16376692c8bSGreg Roach     * @return string
16476692c8bSGreg Roach     */
1657bb2eb25SGreg Roach    protected function monthNameLocativeCase(int $month, bool $leap_year): string
166c1010edaSGreg Roach    {
167a25f0a04SGreg Roach        static $translated_month_names;
168a25f0a04SGreg Roach
169a25f0a04SGreg Roach        if ($translated_month_names === null) {
17013abd6f3SGreg Roach            $translated_month_names = [
171a25f0a04SGreg Roach                0  => '',
172*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Muharram */
173bbb76c12SGreg Roach                1  => I18N::translateContext('LOCATIVE', 'Muharram'),
174*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Safar */
175bbb76c12SGreg Roach                2  => I18N::translateContext('LOCATIVE', 'Safar'),
176*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Rabi%27_al-awwal */
177bbb76c12SGreg Roach                3  => I18N::translateContext('LOCATIVE', 'Rabi’ al-awwal'),
178*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Rabi%27_al-thani */
179bbb76c12SGreg Roach                4  => I18N::translateContext('LOCATIVE', 'Rabi’ al-thani'),
180*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Jumada_al-awwal */
181bbb76c12SGreg Roach                5  => I18N::translateContext('LOCATIVE', 'Jumada al-awwal'),
182*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Jumada_al-thani */
183bbb76c12SGreg Roach                6  => I18N::translateContext('LOCATIVE', 'Jumada al-thani'),
184*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Rajab */
185bbb76c12SGreg Roach                7  => I18N::translateContext('LOCATIVE', 'Rajab'),
186*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Sha%27aban */
187bbb76c12SGreg Roach                8  => I18N::translateContext('LOCATIVE', 'Sha’aban'),
188*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Ramadan_%28calendar_month%29 */
189bbb76c12SGreg Roach                9  => I18N::translateContext('LOCATIVE', 'Ramadan'),
190*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Shawwal */
191bbb76c12SGreg Roach                10 => I18N::translateContext('LOCATIVE', 'Shawwal'),
192*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Dhu_al-Qi%27dah */
193bbb76c12SGreg Roach                11 => I18N::translateContext('LOCATIVE', 'Dhu al-Qi’dah'),
194*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Dhu_al-Hijjah */
195bbb76c12SGreg Roach                12 => I18N::translateContext('LOCATIVE', 'Dhu al-Hijjah'),
19613abd6f3SGreg Roach            ];
197a25f0a04SGreg Roach        }
198a25f0a04SGreg Roach
1997bb2eb25SGreg Roach        return $translated_month_names[$month];
200a25f0a04SGreg Roach    }
201a25f0a04SGreg Roach
20276692c8bSGreg Roach    /**
20376692c8bSGreg Roach     * Full month name in instrumental case.
20476692c8bSGreg Roach     *
2057bb2eb25SGreg Roach     * @param int  $month
20676692c8bSGreg Roach     * @param bool $leap_year Some calendars use leap months
20776692c8bSGreg Roach     *
20876692c8bSGreg Roach     * @return string
20976692c8bSGreg Roach     */
2107bb2eb25SGreg Roach    protected function monthNameInstrumentalCase(int $month, bool $leap_year): string
211c1010edaSGreg Roach    {
212a25f0a04SGreg Roach        static $translated_month_names;
213a25f0a04SGreg Roach
214a25f0a04SGreg Roach        if ($translated_month_names === null) {
21513abd6f3SGreg Roach            $translated_month_names = [
216a25f0a04SGreg Roach                0  => '',
217*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Muharram */
218bbb76c12SGreg Roach                1  => I18N::translateContext('INSTRUMENTAL', 'Muharram'),
219*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Safar */
220bbb76c12SGreg Roach                2  => I18N::translateContext('INSTRUMENTAL', 'Safar'),
221*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Rabi%27_al-awwal */
222bbb76c12SGreg Roach                3  => I18N::translateContext('INSTRUMENTAL', 'Rabi’ al-awwal'),
223*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Rabi%27_al-thani */
224bbb76c12SGreg Roach                4  => I18N::translateContext('INSTRUMENTAL', 'Rabi’ al-thani'),
225*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Jumada_al-awwal */
226bbb76c12SGreg Roach                5  => I18N::translateContext('INSTRUMENTAL', 'Jumada al-awwal'),
227*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Jumada_al-thani */
228bbb76c12SGreg Roach                6  => I18N::translateContext('INSTRUMENTAL', 'Jumada al-thani'),
229*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Rajab */
230bbb76c12SGreg Roach                7  => I18N::translateContext('INSTRUMENTAL', 'Rajab'),
231*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Sha%27aban */
232bbb76c12SGreg Roach                8  => I18N::translateContext('INSTRUMENTAL', 'Sha’aban'),
233*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Ramadan_%28calendar_month%29 */
234bbb76c12SGreg Roach                9  => I18N::translateContext('INSTRUMENTAL', 'Ramadan'),
235*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Shawwal */
236bbb76c12SGreg Roach                10 => I18N::translateContext('INSTRUMENTAL', 'Shawwal'),
237*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Dhu_al-Qi%27dah */
238bbb76c12SGreg Roach                11 => I18N::translateContext('INSTRUMENTAL', 'Dhu al-Qi’dah'),
239*ad3143ccSGreg Roach                /* I18N: https://en.wikipedia.org/wiki/Dhu_al-Hijjah */
240bbb76c12SGreg Roach                12 => I18N::translateContext('INSTRUMENTAL', 'Dhu al-Hijjah'),
24113abd6f3SGreg Roach            ];
242a25f0a04SGreg Roach        }
243a25f0a04SGreg Roach
2447bb2eb25SGreg Roach        return $translated_month_names[$month];
245a25f0a04SGreg Roach    }
246a25f0a04SGreg Roach
24776692c8bSGreg Roach    /**
24876692c8bSGreg Roach     * Abbreviated month name
24976692c8bSGreg Roach     *
2507bb2eb25SGreg Roach     * @param int  $month
25176692c8bSGreg Roach     * @param bool $leap_year Some calendars use leap months
25276692c8bSGreg Roach     *
25376692c8bSGreg Roach     * @return string
25476692c8bSGreg Roach     */
2557bb2eb25SGreg Roach    protected function monthNameAbbreviated(int $month, bool $leap_year): string
256c1010edaSGreg Roach    {
2577bb2eb25SGreg Roach        return $this->monthNameNominativeCase($month, $leap_year);
258a25f0a04SGreg Roach    }
259a25f0a04SGreg Roach}
260