xref: /webtrees/app/Date/HijriDate.php (revision 4a83f5d742e43c37a641392fe50a3db201bffb30)
1a25f0a04SGreg Roach<?php
2a25f0a04SGreg Roach/**
3a25f0a04SGreg Roach * webtrees: online genealogy
41062a142SGreg 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 */
16e7f56f2aSGreg Roachdeclare(strict_types=1);
17e7f56f2aSGreg Roach
1876692c8bSGreg Roachnamespace Fisharebest\Webtrees\Date;
19a25f0a04SGreg Roach
20a25f0a04SGreg Roachuse Fisharebest\ExtCalendar\ArabicCalendar;
210e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N;
22a25f0a04SGreg Roach
23a25f0a04SGreg Roach/**
24*4a83f5d7SGreg Roach * Definitions for Hijri dates.
25a25f0a04SGreg Roach *
26a25f0a04SGreg Roach * Note that these are "theoretical" dates.
27a25f0a04SGreg Roach * "True" dates are based on local lunar observations, and can be a +/- one day.
28a25f0a04SGreg Roach */
29*4a83f5d7SGreg Roachclass HijriDate extends AbstractCalendarDate
30c1010edaSGreg Roach{
31*4a83f5d7SGreg Roach    // GEDCOM calendar escape
32*4a83f5d7SGreg Roach    const ESCAPE = '@#DHIJRI@';
33*4a83f5d7SGreg Roach
3452348eb8SGreg Roach    // Convert GEDCOM month names to month numbers
3552348eb8SGreg Roach    const MONTH_ABBREVIATIONS = [
36b61e86aaSGreg Roach        ''      => 0,
37c1010edaSGreg Roach        'MUHAR' => 1,
38c1010edaSGreg Roach        'SAFAR' => 2,
39c1010edaSGreg Roach        'RABIA' => 3,
40c1010edaSGreg Roach        'RABIT' => 4,
41c1010edaSGreg Roach        'JUMAA' => 5,
42c1010edaSGreg Roach        'JUMAT' => 6,
43c1010edaSGreg Roach        'RAJAB' => 7,
44c1010edaSGreg Roach        'SHAAB' => 8,
45c1010edaSGreg Roach        'RAMAD' => 9,
46c1010edaSGreg Roach        'SHAWW' => 10,
47c1010edaSGreg Roach        'DHUAQ' => 11,
48c1010edaSGreg Roach        'DHUAH' => 12,
49c1010edaSGreg Roach    ];
50a25f0a04SGreg Roach
5176692c8bSGreg Roach    /**
5276692c8bSGreg Roach     * Create a date from either:
5376692c8bSGreg Roach     * a Julian day number
5476692c8bSGreg Roach     * day/month/year strings from a GEDCOM date
5576692c8bSGreg Roach     * another CalendarDate object
5676692c8bSGreg Roach     *
57*4a83f5d7SGreg Roach     * @param array|int|AbstractCalendarDate $date
5876692c8bSGreg Roach     */
59c1010edaSGreg Roach    public function __construct($date)
60c1010edaSGreg Roach    {
6159f2f229SGreg Roach        $this->calendar = new ArabicCalendar();
62a25f0a04SGreg Roach        parent::__construct($date);
63a25f0a04SGreg Roach    }
64a25f0a04SGreg Roach
6576692c8bSGreg Roach    /**
6676692c8bSGreg Roach     * Full month name in nominative case.
6776692c8bSGreg Roach     *
6876692c8bSGreg Roach     * @param int  $month_number
6976692c8bSGreg Roach     * @param bool $leap_year Some calendars use leap months
7076692c8bSGreg Roach     *
7176692c8bSGreg Roach     * @return string
7276692c8bSGreg Roach     */
73220febf9SGreg Roach    protected function monthNameNominativeCase(int $month_number, bool $leap_year): string
74c1010edaSGreg Roach    {
75a25f0a04SGreg Roach        static $translated_month_names;
76a25f0a04SGreg Roach
77a25f0a04SGreg Roach        if ($translated_month_names === null) {
7813abd6f3SGreg Roach            $translated_month_names = [
79a25f0a04SGreg Roach                0  => '',
80bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Muharram */
81bbb76c12SGreg Roach                1  => I18N::translateContext('NOMINATIVE', 'Muharram'),
82bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Safar */
83bbb76c12SGreg Roach                2  => I18N::translateContext('NOMINATIVE', 'Safar'),
84bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-awwal */
85bbb76c12SGreg Roach                3  => I18N::translateContext('NOMINATIVE', 'Rabi’ al-awwal'),
86bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-thani */
87bbb76c12SGreg Roach                4  => I18N::translateContext('NOMINATIVE', 'Rabi’ al-thani'),
88bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Jumada_al-awwal */
89bbb76c12SGreg Roach                5  => I18N::translateContext('NOMINATIVE', 'Jumada al-awwal'),
90bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Jumada_al-thani */
91bbb76c12SGreg Roach                6  => I18N::translateContext('NOMINATIVE', 'Jumada al-thani'),
92bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Rajab */
93bbb76c12SGreg Roach                7  => I18N::translateContext('NOMINATIVE', 'Rajab'),
94bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Sha%27aban */
95bbb76c12SGreg Roach                8  => I18N::translateContext('NOMINATIVE', 'Sha’aban'),
96bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Ramadan_%28calendar_month%29 */
97bbb76c12SGreg Roach                9  => I18N::translateContext('NOMINATIVE', 'Ramadan'),
98bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Shawwal */
99bbb76c12SGreg Roach                10 => I18N::translateContext('NOMINATIVE', 'Shawwal'),
100bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Qi%27dah */
101bbb76c12SGreg Roach                11 => I18N::translateContext('NOMINATIVE', 'Dhu al-Qi’dah'),
102bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Hijjah */
103bbb76c12SGreg Roach                12 => I18N::translateContext('NOMINATIVE', 'Dhu al-Hijjah'),
10413abd6f3SGreg Roach            ];
105a25f0a04SGreg Roach        }
106a25f0a04SGreg Roach
107a25f0a04SGreg Roach        return $translated_month_names[$month_number];
108a25f0a04SGreg Roach    }
109a25f0a04SGreg Roach
11076692c8bSGreg Roach    /**
11176692c8bSGreg Roach     * Full month name in genitive case.
11276692c8bSGreg Roach     *
11376692c8bSGreg Roach     * @param int  $month_number
11476692c8bSGreg Roach     * @param bool $leap_year Some calendars use leap months
11576692c8bSGreg Roach     *
11676692c8bSGreg Roach     * @return string
11776692c8bSGreg Roach     */
118fe11e66dSGreg Roach    protected function monthNameGenitiveCase(int $month_number, bool $leap_year): string
119c1010edaSGreg Roach    {
120a25f0a04SGreg Roach        static $translated_month_names;
121a25f0a04SGreg Roach
122a25f0a04SGreg Roach        if ($translated_month_names === null) {
12313abd6f3SGreg Roach            $translated_month_names = [
124a25f0a04SGreg Roach                0  => '',
125bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Muharram */
126bbb76c12SGreg Roach                1  => I18N::translateContext('GENITIVE', 'Muharram'),
127bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Safar */
128bbb76c12SGreg Roach                2  => I18N::translateContext('GENITIVE', 'Safar'),
129bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-awwal */
130bbb76c12SGreg Roach                3  => I18N::translateContext('GENITIVE', 'Rabi’ al-awwal'),
131bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-thani */
132bbb76c12SGreg Roach                4  => I18N::translateContext('GENITIVE', 'Rabi’ al-thani'),
133bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Jumada_al-awwal */
134bbb76c12SGreg Roach                5  => I18N::translateContext('GENITIVE', 'Jumada al-awwal'),
135bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Jumada_al-thani */
136bbb76c12SGreg Roach                6  => I18N::translateContext('GENITIVE', 'Jumada al-thani'),
137bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Rajab */
138bbb76c12SGreg Roach                7  => I18N::translateContext('GENITIVE', 'Rajab'),
139bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Sha%27aban */
140bbb76c12SGreg Roach                8  => I18N::translateContext('GENITIVE', 'Sha’aban'),
141bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Ramadan_%28calendar_month%29 */
142bbb76c12SGreg Roach                9  => I18N::translateContext('GENITIVE', 'Ramadan'),
143bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Shawwal */
144bbb76c12SGreg Roach                10 => I18N::translateContext('GENITIVE', 'Shawwal'),
145bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Qi%27dah */
146bbb76c12SGreg Roach                11 => I18N::translateContext('GENITIVE', 'Dhu al-Qi’dah'),
147bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Hijjah */
148bbb76c12SGreg Roach                12 => I18N::translateContext('GENITIVE', 'Dhu al-Hijjah'),
14913abd6f3SGreg Roach            ];
150a25f0a04SGreg Roach        }
151a25f0a04SGreg Roach
152a25f0a04SGreg Roach        return $translated_month_names[$month_number];
153a25f0a04SGreg Roach    }
154a25f0a04SGreg Roach
15576692c8bSGreg Roach    /**
15676692c8bSGreg Roach     * Full month name in locative case.
15776692c8bSGreg Roach     *
15876692c8bSGreg Roach     * @param int  $month_number
15976692c8bSGreg Roach     * @param bool $leap_year Some calendars use leap months
16076692c8bSGreg Roach     *
16176692c8bSGreg Roach     * @return string
16276692c8bSGreg Roach     */
163fe11e66dSGreg Roach    protected function monthNameLocativeCase(int $month_number, bool $leap_year): string
164c1010edaSGreg Roach    {
165a25f0a04SGreg Roach        static $translated_month_names;
166a25f0a04SGreg Roach
167a25f0a04SGreg Roach        if ($translated_month_names === null) {
16813abd6f3SGreg Roach            $translated_month_names = [
169a25f0a04SGreg Roach                0  => '',
170bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Muharram */
171bbb76c12SGreg Roach                1  => I18N::translateContext('LOCATIVE', 'Muharram'),
172bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Safar */
173bbb76c12SGreg Roach                2  => I18N::translateContext('LOCATIVE', 'Safar'),
174bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-awwal */
175bbb76c12SGreg Roach                3  => I18N::translateContext('LOCATIVE', 'Rabi’ al-awwal'),
176bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-thani */
177bbb76c12SGreg Roach                4  => I18N::translateContext('LOCATIVE', 'Rabi’ al-thani'),
178bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Jumada_al-awwal */
179bbb76c12SGreg Roach                5  => I18N::translateContext('LOCATIVE', 'Jumada al-awwal'),
180bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Jumada_al-thani */
181bbb76c12SGreg Roach                6  => I18N::translateContext('LOCATIVE', 'Jumada al-thani'),
182bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Rajab */
183bbb76c12SGreg Roach                7  => I18N::translateContext('LOCATIVE', 'Rajab'),
184bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Sha%27aban */
185bbb76c12SGreg Roach                8  => I18N::translateContext('LOCATIVE', 'Sha’aban'),
186bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Ramadan_%28calendar_month%29 */
187bbb76c12SGreg Roach                9  => I18N::translateContext('LOCATIVE', 'Ramadan'),
188bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Shawwal */
189bbb76c12SGreg Roach                10 => I18N::translateContext('LOCATIVE', 'Shawwal'),
190bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Qi%27dah */
191bbb76c12SGreg Roach                11 => I18N::translateContext('LOCATIVE', 'Dhu al-Qi’dah'),
192bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Hijjah */
193bbb76c12SGreg Roach                12 => I18N::translateContext('LOCATIVE', 'Dhu al-Hijjah'),
19413abd6f3SGreg Roach            ];
195a25f0a04SGreg Roach        }
196a25f0a04SGreg Roach
197a25f0a04SGreg Roach        return $translated_month_names[$month_number];
198a25f0a04SGreg Roach    }
199a25f0a04SGreg Roach
20076692c8bSGreg Roach    /**
20176692c8bSGreg Roach     * Full month name in instrumental case.
20276692c8bSGreg Roach     *
20376692c8bSGreg Roach     * @param int  $month_number
20476692c8bSGreg Roach     * @param bool $leap_year Some calendars use leap months
20576692c8bSGreg Roach     *
20676692c8bSGreg Roach     * @return string
20776692c8bSGreg Roach     */
208fe11e66dSGreg Roach    protected function monthNameInstrumentalCase(int $month_number, bool $leap_year): string
209c1010edaSGreg Roach    {
210a25f0a04SGreg Roach        static $translated_month_names;
211a25f0a04SGreg Roach
212a25f0a04SGreg Roach        if ($translated_month_names === null) {
21313abd6f3SGreg Roach            $translated_month_names = [
214a25f0a04SGreg Roach                0  => '',
215bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Muharram */
216bbb76c12SGreg Roach                1  => I18N::translateContext('INSTRUMENTAL', 'Muharram'),
217bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Safar */
218bbb76c12SGreg Roach                2  => I18N::translateContext('INSTRUMENTAL', 'Safar'),
219bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-awwal */
220bbb76c12SGreg Roach                3  => I18N::translateContext('INSTRUMENTAL', 'Rabi’ al-awwal'),
221bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-thani */
222bbb76c12SGreg Roach                4  => I18N::translateContext('INSTRUMENTAL', 'Rabi’ al-thani'),
223bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Jumada_al-awwal */
224bbb76c12SGreg Roach                5  => I18N::translateContext('INSTRUMENTAL', 'Jumada al-awwal'),
225bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Jumada_al-thani */
226bbb76c12SGreg Roach                6  => I18N::translateContext('INSTRUMENTAL', 'Jumada al-thani'),
227bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Rajab */
228bbb76c12SGreg Roach                7  => I18N::translateContext('INSTRUMENTAL', 'Rajab'),
229bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Sha%27aban */
230bbb76c12SGreg Roach                8  => I18N::translateContext('INSTRUMENTAL', 'Sha’aban'),
231bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Ramadan_%28calendar_month%29 */
232bbb76c12SGreg Roach                9  => I18N::translateContext('INSTRUMENTAL', 'Ramadan'),
233bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Shawwal */
234bbb76c12SGreg Roach                10 => I18N::translateContext('INSTRUMENTAL', 'Shawwal'),
235bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Qi%27dah */
236bbb76c12SGreg Roach                11 => I18N::translateContext('INSTRUMENTAL', 'Dhu al-Qi’dah'),
237bbb76c12SGreg Roach                /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Hijjah */
238bbb76c12SGreg Roach                12 => I18N::translateContext('INSTRUMENTAL', 'Dhu al-Hijjah'),
23913abd6f3SGreg Roach            ];
240a25f0a04SGreg Roach        }
241a25f0a04SGreg Roach
242a25f0a04SGreg Roach        return $translated_month_names[$month_number];
243a25f0a04SGreg Roach    }
244a25f0a04SGreg Roach
24576692c8bSGreg Roach    /**
24676692c8bSGreg Roach     * Abbreviated month name
24776692c8bSGreg Roach     *
24876692c8bSGreg Roach     * @param int  $month_number
24976692c8bSGreg Roach     * @param bool $leap_year Some calendars use leap months
25076692c8bSGreg Roach     *
25176692c8bSGreg Roach     * @return string
25276692c8bSGreg Roach     */
253fe11e66dSGreg Roach    protected function monthNameAbbreviated(int $month_number, bool $leap_year): string
254c1010edaSGreg Roach    {
25540c81a71SGreg Roach        return $this->monthNameNominativeCase($month_number, $leap_year);
256a25f0a04SGreg Roach    }
257a25f0a04SGreg Roach}
258