xref: /webtrees/app/Date/HijriDate.php (revision b61e86aa9976938325cee03206e8031fe3123ea8)
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 */
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 */
27c1010edaSGreg Roachclass HijriDate extends CalendarDate
28c1010edaSGreg Roach{
29e2052359SGreg Roach    /** @var int[] Convert GEDCOM month names to month numbers */
30*b61e86aaSGreg Roach    public static $MONTH_ABBREV = [
31*b61e86aaSGreg Roach        ''      => 0,
32c1010edaSGreg Roach        'MUHAR' => 1,
33c1010edaSGreg Roach        'SAFAR' => 2,
34c1010edaSGreg Roach        'RABIA' => 3,
35c1010edaSGreg Roach        'RABIT' => 4,
36c1010edaSGreg Roach        'JUMAA' => 5,
37c1010edaSGreg Roach        'JUMAT' => 6,
38c1010edaSGreg Roach        'RAJAB' => 7,
39c1010edaSGreg Roach        'SHAAB' => 8,
40c1010edaSGreg Roach        'RAMAD' => 9,
41c1010edaSGreg Roach        'SHAWW' => 10,
42c1010edaSGreg Roach        'DHUAQ' => 11,
43c1010edaSGreg Roach        'DHUAH' => 12,
44c1010edaSGreg Roach    ];
45a25f0a04SGreg Roach
4676692c8bSGreg Roach    /**
4776692c8bSGreg Roach     * Create a date from either:
4876692c8bSGreg Roach     * a Julian day number
4976692c8bSGreg Roach     * day/month/year strings from a GEDCOM date
5076692c8bSGreg Roach     * another CalendarDate object
5176692c8bSGreg Roach     *
5276692c8bSGreg Roach     * @param array|int|CalendarDate $date
5376692c8bSGreg Roach     */
54c1010edaSGreg Roach    public function __construct($date)
55c1010edaSGreg Roach    {
56a25f0a04SGreg Roach        $this->calendar = new ArabicCalendar;
57a25f0a04SGreg Roach        parent::__construct($date);
58a25f0a04SGreg Roach    }
59a25f0a04SGreg Roach
6076692c8bSGreg Roach    /**
6176692c8bSGreg Roach     * Full month name in nominative case.
6276692c8bSGreg Roach     *
6376692c8bSGreg Roach     * @param int  $month_number
6476692c8bSGreg Roach     * @param bool $leap_year Some calendars use leap months
6576692c8bSGreg Roach     *
6676692c8bSGreg Roach     * @return string
6776692c8bSGreg Roach     */
68c1010edaSGreg Roach    public static function monthNameNominativeCase($month_number, $leap_year)
69c1010edaSGreg Roach    {
70a25f0a04SGreg Roach        static $translated_month_names;
71a25f0a04SGreg Roach
72a25f0a04SGreg Roach        if ($translated_month_names === null) {
7313abd6f3SGreg Roach            $translated_month_names = [
74a25f0a04SGreg Roach                0  => '',
75c1010edaSGreg Roach                1  => /* I18N: http://en.wikipedia.org/wiki/Muharram */
76c1010edaSGreg Roach                    I18N::translateContext('NOMINATIVE', 'Muharram'),
77c1010edaSGreg Roach                2  => /* I18N: http://en.wikipedia.org/wiki/Safar */
78c1010edaSGreg Roach                    I18N::translateContext('NOMINATIVE', 'Safar'),
79c1010edaSGreg Roach                3  => /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-awwal */
80c1010edaSGreg Roach                    I18N::translateContext('NOMINATIVE', 'Rabi’ al-awwal'),
81c1010edaSGreg Roach                4  => /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-thani */
82c1010edaSGreg Roach                    I18N::translateContext('NOMINATIVE', 'Rabi’ al-thani'),
83c1010edaSGreg Roach                5  => /* I18N: http://en.wikipedia.org/wiki/Jumada_al-awwal */
84c1010edaSGreg Roach                    I18N::translateContext('NOMINATIVE', 'Jumada al-awwal'),
85c1010edaSGreg Roach                6  => /* I18N: http://en.wikipedia.org/wiki/Jumada_al-thani */
86c1010edaSGreg Roach                    I18N::translateContext('NOMINATIVE', 'Jumada al-thani'),
87c1010edaSGreg Roach                7  => /* I18N: http://en.wikipedia.org/wiki/Rajab */
88c1010edaSGreg Roach                    I18N::translateContext('NOMINATIVE', 'Rajab'),
89c1010edaSGreg Roach                8  => /* I18N: http://en.wikipedia.org/wiki/Sha%27aban */
90c1010edaSGreg Roach                    I18N::translateContext('NOMINATIVE', 'Sha’aban'),
91c1010edaSGreg Roach                9  => /* I18N: http://en.wikipedia.org/wiki/Ramadan_%28calendar_month%29 */
92c1010edaSGreg Roach                    I18N::translateContext('NOMINATIVE', 'Ramadan'),
93c1010edaSGreg Roach                10 => /* I18N: http://en.wikipedia.org/wiki/Shawwal */
94c1010edaSGreg Roach                    I18N::translateContext('NOMINATIVE', 'Shawwal'),
95c1010edaSGreg Roach                11 => /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Qi%27dah */
96c1010edaSGreg Roach                    I18N::translateContext('NOMINATIVE', 'Dhu al-Qi’dah'),
97c1010edaSGreg Roach                12 => /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Hijjah */
98c1010edaSGreg Roach                    I18N::translateContext('NOMINATIVE', 'Dhu al-Hijjah'),
9913abd6f3SGreg Roach            ];
100a25f0a04SGreg Roach        }
101a25f0a04SGreg Roach
102a25f0a04SGreg Roach        return $translated_month_names[$month_number];
103a25f0a04SGreg Roach    }
104a25f0a04SGreg Roach
10576692c8bSGreg Roach    /**
10676692c8bSGreg Roach     * Full month name in genitive case.
10776692c8bSGreg Roach     *
10876692c8bSGreg Roach     * @param int  $month_number
10976692c8bSGreg Roach     * @param bool $leap_year Some calendars use leap months
11076692c8bSGreg Roach     *
11176692c8bSGreg Roach     * @return string
11276692c8bSGreg Roach     */
113c1010edaSGreg Roach    protected function monthNameGenitiveCase($month_number, $leap_year)
114c1010edaSGreg Roach    {
115a25f0a04SGreg Roach        static $translated_month_names;
116a25f0a04SGreg Roach
117a25f0a04SGreg Roach        if ($translated_month_names === null) {
11813abd6f3SGreg Roach            $translated_month_names = [
119a25f0a04SGreg Roach                0  => '',
120c1010edaSGreg Roach                1  => /* I18N: http://en.wikipedia.org/wiki/Muharram */
121c1010edaSGreg Roach                    I18N::translateContext('GENITIVE', 'Muharram'),
122c1010edaSGreg Roach                2  => /* I18N: http://en.wikipedia.org/wiki/Safar */
123c1010edaSGreg Roach                    I18N::translateContext('GENITIVE', 'Safar'),
124c1010edaSGreg Roach                3  => /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-awwal */
125c1010edaSGreg Roach                    I18N::translateContext('GENITIVE', 'Rabi’ al-awwal'),
126c1010edaSGreg Roach                4  => /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-thani */
127c1010edaSGreg Roach                    I18N::translateContext('GENITIVE', 'Rabi’ al-thani'),
128c1010edaSGreg Roach                5  => /* I18N: http://en.wikipedia.org/wiki/Jumada_al-awwal */
129c1010edaSGreg Roach                    I18N::translateContext('GENITIVE', 'Jumada al-awwal'),
130c1010edaSGreg Roach                6  => /* I18N: http://en.wikipedia.org/wiki/Jumada_al-thani */
131c1010edaSGreg Roach                    I18N::translateContext('GENITIVE', 'Jumada al-thani'),
132c1010edaSGreg Roach                7  => /* I18N: http://en.wikipedia.org/wiki/Rajab */
133c1010edaSGreg Roach                    I18N::translateContext('GENITIVE', 'Rajab'),
134c1010edaSGreg Roach                8  => /* I18N: http://en.wikipedia.org/wiki/Sha%27aban */
135c1010edaSGreg Roach                    I18N::translateContext('GENITIVE', 'Sha’aban'),
136c1010edaSGreg Roach                9  => /* I18N: http://en.wikipedia.org/wiki/Ramadan_%28calendar_month%29 */
137c1010edaSGreg Roach                    I18N::translateContext('GENITIVE', 'Ramadan'),
138c1010edaSGreg Roach                10 => /* I18N: http://en.wikipedia.org/wiki/Shawwal */
139c1010edaSGreg Roach                    I18N::translateContext('GENITIVE', 'Shawwal'),
140c1010edaSGreg Roach                11 => /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Qi%27dah */
141c1010edaSGreg Roach                    I18N::translateContext('GENITIVE', 'Dhu al-Qi’dah'),
142c1010edaSGreg Roach                12 => /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Hijjah */
143c1010edaSGreg Roach                    I18N::translateContext('GENITIVE', 'Dhu al-Hijjah'),
14413abd6f3SGreg Roach            ];
145a25f0a04SGreg Roach        }
146a25f0a04SGreg Roach
147a25f0a04SGreg Roach        return $translated_month_names[$month_number];
148a25f0a04SGreg Roach    }
149a25f0a04SGreg Roach
15076692c8bSGreg Roach    /**
15176692c8bSGreg Roach     * Full month name in locative case.
15276692c8bSGreg Roach     *
15376692c8bSGreg Roach     * @param int  $month_number
15476692c8bSGreg Roach     * @param bool $leap_year Some calendars use leap months
15576692c8bSGreg Roach     *
15676692c8bSGreg Roach     * @return string
15776692c8bSGreg Roach     */
158c1010edaSGreg Roach    protected function monthNameLocativeCase($month_number, $leap_year)
159c1010edaSGreg Roach    {
160a25f0a04SGreg Roach        static $translated_month_names;
161a25f0a04SGreg Roach
162a25f0a04SGreg Roach        if ($translated_month_names === null) {
16313abd6f3SGreg Roach            $translated_month_names = [
164a25f0a04SGreg Roach                0  => '',
165c1010edaSGreg Roach                1  => /* I18N: http://en.wikipedia.org/wiki/Muharram */
166c1010edaSGreg Roach                    I18N::translateContext('LOCATIVE', 'Muharram'),
167c1010edaSGreg Roach                2  => /* I18N: http://en.wikipedia.org/wiki/Safar */
168c1010edaSGreg Roach                    I18N::translateContext('LOCATIVE', 'Safar'),
169c1010edaSGreg Roach                3  => /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-awwal */
170c1010edaSGreg Roach                    I18N::translateContext('LOCATIVE', 'Rabi’ al-awwal'),
171c1010edaSGreg Roach                4  => /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-thani */
172c1010edaSGreg Roach                    I18N::translateContext('LOCATIVE', 'Rabi’ al-thani'),
173c1010edaSGreg Roach                5  => /* I18N: http://en.wikipedia.org/wiki/Jumada_al-awwal */
174c1010edaSGreg Roach                    I18N::translateContext('LOCATIVE', 'Jumada al-awwal'),
175c1010edaSGreg Roach                6  => /* I18N: http://en.wikipedia.org/wiki/Jumada_al-thani */
176c1010edaSGreg Roach                    I18N::translateContext('LOCATIVE', 'Jumada al-thani'),
177c1010edaSGreg Roach                7  => /* I18N: http://en.wikipedia.org/wiki/Rajab */
178c1010edaSGreg Roach                    I18N::translateContext('LOCATIVE', 'Rajab'),
179c1010edaSGreg Roach                8  => /* I18N: http://en.wikipedia.org/wiki/Sha%27aban */
180c1010edaSGreg Roach                    I18N::translateContext('LOCATIVE', 'Sha’aban'),
181c1010edaSGreg Roach                9  => /* I18N: http://en.wikipedia.org/wiki/Ramadan_%28calendar_month%29 */
182c1010edaSGreg Roach                    I18N::translateContext('LOCATIVE', 'Ramadan'),
183c1010edaSGreg Roach                10 => /* I18N: http://en.wikipedia.org/wiki/Shawwal */
184c1010edaSGreg Roach                    I18N::translateContext('LOCATIVE', 'Shawwal'),
185c1010edaSGreg Roach                11 => /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Qi%27dah */
186c1010edaSGreg Roach                    I18N::translateContext('LOCATIVE', 'Dhu al-Qi’dah'),
187c1010edaSGreg Roach                12 => /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Hijjah */
188c1010edaSGreg Roach                    I18N::translateContext('LOCATIVE', 'Dhu al-Hijjah'),
18913abd6f3SGreg Roach            ];
190a25f0a04SGreg Roach        }
191a25f0a04SGreg Roach
192a25f0a04SGreg Roach        return $translated_month_names[$month_number];
193a25f0a04SGreg Roach    }
194a25f0a04SGreg Roach
19576692c8bSGreg Roach    /**
19676692c8bSGreg Roach     * Full month name in instrumental case.
19776692c8bSGreg Roach     *
19876692c8bSGreg Roach     * @param int  $month_number
19976692c8bSGreg Roach     * @param bool $leap_year Some calendars use leap months
20076692c8bSGreg Roach     *
20176692c8bSGreg Roach     * @return string
20276692c8bSGreg Roach     */
203c1010edaSGreg Roach    protected function monthNameInstrumentalCase($month_number, $leap_year)
204c1010edaSGreg Roach    {
205a25f0a04SGreg Roach        static $translated_month_names;
206a25f0a04SGreg Roach
207a25f0a04SGreg Roach        if ($translated_month_names === null) {
20813abd6f3SGreg Roach            $translated_month_names = [
209a25f0a04SGreg Roach                0  => '',
210c1010edaSGreg Roach                1  => /* I18N: http://en.wikipedia.org/wiki/Muharram */
211c1010edaSGreg Roach                    I18N::translateContext('INSTRUMENTAL', 'Muharram'),
212c1010edaSGreg Roach                2  => /* I18N: http://en.wikipedia.org/wiki/Safar */
213c1010edaSGreg Roach                    I18N::translateContext('INSTRUMENTAL', 'Safar'),
214c1010edaSGreg Roach                3  => /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-awwal */
215c1010edaSGreg Roach                    I18N::translateContext('INSTRUMENTAL', 'Rabi’ al-awwal'),
216c1010edaSGreg Roach                4  => /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-thani */
217c1010edaSGreg Roach                    I18N::translateContext('INSTRUMENTAL', 'Rabi’ al-thani'),
218c1010edaSGreg Roach                5  => /* I18N: http://en.wikipedia.org/wiki/Jumada_al-awwal */
219c1010edaSGreg Roach                    I18N::translateContext('INSTRUMENTAL', 'Jumada al-awwal'),
220c1010edaSGreg Roach                6  => /* I18N: http://en.wikipedia.org/wiki/Jumada_al-thani */
221c1010edaSGreg Roach                    I18N::translateContext('INSTRUMENTAL', 'Jumada al-thani'),
222c1010edaSGreg Roach                7  => /* I18N: http://en.wikipedia.org/wiki/Rajab */
223c1010edaSGreg Roach                    I18N::translateContext('INSTRUMENTAL', 'Rajab'),
224c1010edaSGreg Roach                8  => /* I18N: http://en.wikipedia.org/wiki/Sha%27aban */
225c1010edaSGreg Roach                    I18N::translateContext('INSTRUMENTAL', 'Sha’aban'),
226c1010edaSGreg Roach                9  => /* I18N: http://en.wikipedia.org/wiki/Ramadan_%28calendar_month%29 */
227c1010edaSGreg Roach                    I18N::translateContext('INSTRUMENTAL', 'Ramadan'),
228c1010edaSGreg Roach                10 => /* I18N: http://en.wikipedia.org/wiki/Shawwal */
229c1010edaSGreg Roach                    I18N::translateContext('INSTRUMENTAL', 'Shawwal'),
230c1010edaSGreg Roach                11 => /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Qi%27dah */
231c1010edaSGreg Roach                    I18N::translateContext('INSTRUMENTAL', 'Dhu al-Qi’dah'),
232c1010edaSGreg Roach                12 => /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Hijjah */
233c1010edaSGreg Roach                    I18N::translateContext('INSTRUMENTAL', 'Dhu al-Hijjah'),
23413abd6f3SGreg Roach            ];
235a25f0a04SGreg Roach        }
236a25f0a04SGreg Roach
237a25f0a04SGreg Roach        return $translated_month_names[$month_number];
238a25f0a04SGreg Roach    }
239a25f0a04SGreg Roach
24076692c8bSGreg Roach    /**
24176692c8bSGreg Roach     * Abbreviated month name
24276692c8bSGreg Roach     *
24376692c8bSGreg Roach     * @param int  $month_number
24476692c8bSGreg Roach     * @param bool $leap_year Some calendars use leap months
24576692c8bSGreg Roach     *
24676692c8bSGreg Roach     * @return string
24776692c8bSGreg Roach     */
248c1010edaSGreg Roach    protected function monthNameAbbreviated($month_number, $leap_year)
249c1010edaSGreg Roach    {
250a25f0a04SGreg Roach        return self::monthNameNominativeCase($month_number, $leap_year);
251a25f0a04SGreg Roach    }
252a25f0a04SGreg Roach}
253