xref: /webtrees/app/Date/HijriDate.php (revision 342dcecd8628deacd49d86f3247fd77e64bf33c3)
1<?php
2/**
3 * webtrees: online genealogy
4 * Copyright (C) 2018 webtrees development team
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16namespace Fisharebest\Webtrees\Date;
17
18use Fisharebest\ExtCalendar\ArabicCalendar;
19use Fisharebest\Webtrees\I18N;
20
21/**
22 * Definitions for the Hijri calendar.
23 *
24 * Note that these are "theoretical" dates.
25 * "True" dates are based on local lunar observations, and can be a +/- one day.
26 */
27class HijriDate extends CalendarDate
28{
29    /** @var int[] Convert GEDCOM month names to month numbers */
30    public static $MONTH_ABBREV = [
31        ''      => 0,
32        'MUHAR' => 1,
33        'SAFAR' => 2,
34        'RABIA' => 3,
35        'RABIT' => 4,
36        'JUMAA' => 5,
37        'JUMAT' => 6,
38        'RAJAB' => 7,
39        'SHAAB' => 8,
40        'RAMAD' => 9,
41        'SHAWW' => 10,
42        'DHUAQ' => 11,
43        'DHUAH' => 12,
44    ];
45
46    /**
47     * Create a date from either:
48     * a Julian day number
49     * day/month/year strings from a GEDCOM date
50     * another CalendarDate object
51     *
52     * @param array|int|CalendarDate $date
53     */
54    public function __construct($date)
55    {
56        $this->calendar = new ArabicCalendar;
57        parent::__construct($date);
58    }
59
60    /**
61     * Full month name in nominative case.
62     *
63     * @param int  $month_number
64     * @param bool $leap_year Some calendars use leap months
65     *
66     * @return string
67     */
68    public static function monthNameNominativeCase($month_number, $leap_year)
69    {
70        static $translated_month_names;
71
72        if ($translated_month_names === null) {
73            $translated_month_names = [
74                0  => '',
75                /* I18N: http://en.wikipedia.org/wiki/Muharram */
76                1  => I18N::translateContext('NOMINATIVE', 'Muharram'),
77                /* I18N: http://en.wikipedia.org/wiki/Safar */
78                2  => I18N::translateContext('NOMINATIVE', 'Safar'),
79                /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-awwal */
80                3  => I18N::translateContext('NOMINATIVE', 'Rabi’ al-awwal'),
81                /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-thani */
82                4  => I18N::translateContext('NOMINATIVE', 'Rabi’ al-thani'),
83                /* I18N: http://en.wikipedia.org/wiki/Jumada_al-awwal */
84                5  => I18N::translateContext('NOMINATIVE', 'Jumada al-awwal'),
85                /* I18N: http://en.wikipedia.org/wiki/Jumada_al-thani */
86                6  => I18N::translateContext('NOMINATIVE', 'Jumada al-thani'),
87                /* I18N: http://en.wikipedia.org/wiki/Rajab */
88                7  => I18N::translateContext('NOMINATIVE', 'Rajab'),
89                /* I18N: http://en.wikipedia.org/wiki/Sha%27aban */
90                8  => I18N::translateContext('NOMINATIVE', 'Sha’aban'),
91                /* I18N: http://en.wikipedia.org/wiki/Ramadan_%28calendar_month%29 */
92                9  => I18N::translateContext('NOMINATIVE', 'Ramadan'),
93                /* I18N: http://en.wikipedia.org/wiki/Shawwal */
94                10 => I18N::translateContext('NOMINATIVE', 'Shawwal'),
95                /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Qi%27dah */
96                11 => I18N::translateContext('NOMINATIVE', 'Dhu al-Qi’dah'),
97                /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Hijjah */
98                12 => I18N::translateContext('NOMINATIVE', 'Dhu al-Hijjah'),
99            ];
100        }
101
102        return $translated_month_names[$month_number];
103    }
104
105    /**
106     * Full month name in genitive case.
107     *
108     * @param int  $month_number
109     * @param bool $leap_year Some calendars use leap months
110     *
111     * @return string
112     */
113    protected function monthNameGenitiveCase($month_number, $leap_year)
114    {
115        static $translated_month_names;
116
117        if ($translated_month_names === null) {
118            $translated_month_names = [
119                0  => '',
120                /* I18N: http://en.wikipedia.org/wiki/Muharram */
121                1  => I18N::translateContext('GENITIVE', 'Muharram'),
122                /* I18N: http://en.wikipedia.org/wiki/Safar */
123                2  => I18N::translateContext('GENITIVE', 'Safar'),
124                /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-awwal */
125                3  => I18N::translateContext('GENITIVE', 'Rabi’ al-awwal'),
126                /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-thani */
127                4  => I18N::translateContext('GENITIVE', 'Rabi’ al-thani'),
128                /* I18N: http://en.wikipedia.org/wiki/Jumada_al-awwal */
129                5  => I18N::translateContext('GENITIVE', 'Jumada al-awwal'),
130                /* I18N: http://en.wikipedia.org/wiki/Jumada_al-thani */
131                6  => I18N::translateContext('GENITIVE', 'Jumada al-thani'),
132                /* I18N: http://en.wikipedia.org/wiki/Rajab */
133                7  => I18N::translateContext('GENITIVE', 'Rajab'),
134                /* I18N: http://en.wikipedia.org/wiki/Sha%27aban */
135                8  => I18N::translateContext('GENITIVE', 'Sha’aban'),
136                /* I18N: http://en.wikipedia.org/wiki/Ramadan_%28calendar_month%29 */
137                9  => I18N::translateContext('GENITIVE', 'Ramadan'),
138                /* I18N: http://en.wikipedia.org/wiki/Shawwal */
139                10 => I18N::translateContext('GENITIVE', 'Shawwal'),
140                /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Qi%27dah */
141                11 => I18N::translateContext('GENITIVE', 'Dhu al-Qi’dah'),
142                /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Hijjah */
143                12 => I18N::translateContext('GENITIVE', 'Dhu al-Hijjah'),
144            ];
145        }
146
147        return $translated_month_names[$month_number];
148    }
149
150    /**
151     * Full month name in locative case.
152     *
153     * @param int  $month_number
154     * @param bool $leap_year Some calendars use leap months
155     *
156     * @return string
157     */
158    protected function monthNameLocativeCase($month_number, $leap_year)
159    {
160        static $translated_month_names;
161
162        if ($translated_month_names === null) {
163            $translated_month_names = [
164                0  => '',
165                /* I18N: http://en.wikipedia.org/wiki/Muharram */
166                1  => I18N::translateContext('LOCATIVE', 'Muharram'),
167                /* I18N: http://en.wikipedia.org/wiki/Safar */
168                2  => I18N::translateContext('LOCATIVE', 'Safar'),
169                /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-awwal */
170                3  => I18N::translateContext('LOCATIVE', 'Rabi’ al-awwal'),
171                /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-thani */
172                4  => I18N::translateContext('LOCATIVE', 'Rabi’ al-thani'),
173                /* I18N: http://en.wikipedia.org/wiki/Jumada_al-awwal */
174                5  => I18N::translateContext('LOCATIVE', 'Jumada al-awwal'),
175                /* I18N: http://en.wikipedia.org/wiki/Jumada_al-thani */
176                6  => I18N::translateContext('LOCATIVE', 'Jumada al-thani'),
177                /* I18N: http://en.wikipedia.org/wiki/Rajab */
178                7  => I18N::translateContext('LOCATIVE', 'Rajab'),
179                /* I18N: http://en.wikipedia.org/wiki/Sha%27aban */
180                8  => I18N::translateContext('LOCATIVE', 'Sha’aban'),
181                /* I18N: http://en.wikipedia.org/wiki/Ramadan_%28calendar_month%29 */
182                9  => I18N::translateContext('LOCATIVE', 'Ramadan'),
183                /* I18N: http://en.wikipedia.org/wiki/Shawwal */
184                10 => I18N::translateContext('LOCATIVE', 'Shawwal'),
185                /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Qi%27dah */
186                11 => I18N::translateContext('LOCATIVE', 'Dhu al-Qi’dah'),
187                /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Hijjah */
188                12 => I18N::translateContext('LOCATIVE', 'Dhu al-Hijjah'),
189            ];
190        }
191
192        return $translated_month_names[$month_number];
193    }
194
195    /**
196     * Full month name in instrumental case.
197     *
198     * @param int  $month_number
199     * @param bool $leap_year Some calendars use leap months
200     *
201     * @return string
202     */
203    protected function monthNameInstrumentalCase($month_number, $leap_year)
204    {
205        static $translated_month_names;
206
207        if ($translated_month_names === null) {
208            $translated_month_names = [
209                0  => '',
210                /* I18N: http://en.wikipedia.org/wiki/Muharram */
211                1  => I18N::translateContext('INSTRUMENTAL', 'Muharram'),
212                /* I18N: http://en.wikipedia.org/wiki/Safar */
213                2  => I18N::translateContext('INSTRUMENTAL', 'Safar'),
214                /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-awwal */
215                3  => I18N::translateContext('INSTRUMENTAL', 'Rabi’ al-awwal'),
216                /* I18N: http://en.wikipedia.org/wiki/Rabi%27_al-thani */
217                4  => I18N::translateContext('INSTRUMENTAL', 'Rabi’ al-thani'),
218                /* I18N: http://en.wikipedia.org/wiki/Jumada_al-awwal */
219                5  => I18N::translateContext('INSTRUMENTAL', 'Jumada al-awwal'),
220                /* I18N: http://en.wikipedia.org/wiki/Jumada_al-thani */
221                6  => I18N::translateContext('INSTRUMENTAL', 'Jumada al-thani'),
222                /* I18N: http://en.wikipedia.org/wiki/Rajab */
223                7  => I18N::translateContext('INSTRUMENTAL', 'Rajab'),
224                /* I18N: http://en.wikipedia.org/wiki/Sha%27aban */
225                8  => I18N::translateContext('INSTRUMENTAL', 'Sha’aban'),
226                /* I18N: http://en.wikipedia.org/wiki/Ramadan_%28calendar_month%29 */
227                9  => I18N::translateContext('INSTRUMENTAL', 'Ramadan'),
228                /* I18N: http://en.wikipedia.org/wiki/Shawwal */
229                10 => I18N::translateContext('INSTRUMENTAL', 'Shawwal'),
230                /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Qi%27dah */
231                11 => I18N::translateContext('INSTRUMENTAL', 'Dhu al-Qi’dah'),
232                /* I18N: http://en.wikipedia.org/wiki/Dhu_al-Hijjah */
233                12 => I18N::translateContext('INSTRUMENTAL', 'Dhu al-Hijjah'),
234            ];
235        }
236
237        return $translated_month_names[$month_number];
238    }
239
240    /**
241     * Abbreviated month name
242     *
243     * @param int  $month_number
244     * @param bool $leap_year Some calendars use leap months
245     *
246     * @return string
247     */
248    protected function monthNameAbbreviated($month_number, $leap_year)
249    {
250        return self::monthNameNominativeCase($month_number, $leap_year);
251    }
252}
253