xref: /webtrees/app/Date/JalaliDate.php (revision f5558d03d2b82addeecce3d5688cd9c9501aa372)
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\PersianCalendar;
19use Fisharebest\Webtrees\I18N;
20
21/**
22 * Definitions for the Jalali calendar
23 */
24class JalaliDate extends CalendarDate
25{
26    /** @var int[] Convert GEDCOM month names to month numbers */
27    public static $MONTH_ABBREV = [
28        ''      => 0,
29        'FARVA' => 1,
30        'ORDIB' => 2,
31        'KHORD' => 3,
32        'TIR'   => 4,
33        'MORDA' => 5,
34        'SHAHR' => 6,
35        'MEHR'  => 7,
36        'ABAN'  => 8,
37        'AZAR'  => 9,
38        'DEY'   => 10,
39        'BAHMA' => 11,
40        'ESFAN' => 12,
41    ];
42
43    /**
44     * Create a date from either:
45     * a Julian day number
46     * day/month/year strings from a GEDCOM date
47     * another CalendarDate object
48     *
49     * @param array|int|CalendarDate $date
50     */
51    public function __construct($date)
52    {
53        $this->calendar = new PersianCalendar;
54        parent::__construct($date);
55    }
56
57    /**
58     * Full month name in nominative case.
59     *
60     * @param int  $month_number
61     * @param bool $leap_year Some calendars use leap months
62     *
63     * @return string
64     */
65    public static function monthNameNominativeCase($month_number, $leap_year)
66    {
67        static $translated_month_names;
68
69        if ($translated_month_names === null) {
70            $translated_month_names = [
71                0  => '',
72                1  => /* I18N: 1st month in the Persian/Jalali calendar */
73                    I18N::translateContext('NOMINATIVE', 'Farvardin'),
74                2  => /* I18N: 2nd month in the Persian/Jalali calendar */
75                    I18N::translateContext('NOMINATIVE', 'Ordibehesht'),
76                3  => /* I18N: 3rd month in the Persian/Jalali calendar */
77                    I18N::translateContext('NOMINATIVE', 'Khordad'),
78                4  => /* I18N: 4th month in the Persian/Jalali calendar */
79                    I18N::translateContext('NOMINATIVE', 'Tir'),
80                5  => /* I18N: 5th month in the Persian/Jalali calendar */
81                    I18N::translateContext('NOMINATIVE', 'Mordad'),
82                6  => /* I18N: 6th month in the Persian/Jalali calendar */
83                    I18N::translateContext('NOMINATIVE', 'Shahrivar'),
84                7  => /* I18N: 7th month in the Persian/Jalali calendar */
85                    I18N::translateContext('NOMINATIVE', 'Mehr'),
86                8  => /* I18N: 8th month in the Persian/Jalali calendar */
87                    I18N::translateContext('NOMINATIVE', 'Aban'),
88                9  => /* I18N: 9th month in the Persian/Jalali calendar */
89                    I18N::translateContext('NOMINATIVE', 'Azar'),
90                10 => /* I18N: 10th month in the Persian/Jalali calendar */
91                    I18N::translateContext('NOMINATIVE', 'Dey'),
92                11 => /* I18N: 11th month in the Persian/Jalali calendar */
93                    I18N::translateContext('NOMINATIVE', 'Bahman'),
94                12 => /* I18N: 12th month in the Persian/Jalali calendar */
95                    I18N::translateContext('NOMINATIVE', 'Esfand'),
96            ];
97        }
98
99        return $translated_month_names[$month_number];
100    }
101
102    /**
103     * Full month name in genitive case.
104     *
105     * @param int  $month_number
106     * @param bool $leap_year Some calendars use leap months
107     *
108     * @return string
109     */
110    protected function monthNameGenitiveCase($month_number, $leap_year)
111    {
112        static $translated_month_names;
113
114        if ($translated_month_names === null) {
115            $translated_month_names = [
116                0  => '',
117                1  => /* I18N: 1st month in the Persian/Jalali calendar */
118                    I18N::translateContext('GENITIVE', 'Farvardin'),
119                2  => /* I18N: 2nd month in the Persian/Jalali calendar */
120                    I18N::translateContext('GENITIVE', 'Ordibehesht'),
121                3  => /* I18N: 3rd month in the Persian/Jalali calendar */
122                    I18N::translateContext('GENITIVE', 'Khordad'),
123                4  => /* I18N: 4th month in the Persian/Jalali calendar */
124                    I18N::translateContext('GENITIVE', 'Tir'),
125                5  => /* I18N: 5th month in the Persian/Jalali calendar */
126                    I18N::translateContext('GENITIVE', 'Mordad'),
127                6  => /* I18N: 6th month in the Persian/Jalali calendar */
128                    I18N::translateContext('GENITIVE', 'Shahrivar'),
129                7  => /* I18N: 7th month in the Persian/Jalali calendar */
130                    I18N::translateContext('GENITIVE', 'Mehr'),
131                8  => /* I18N: 8th month in the Persian/Jalali calendar */
132                    I18N::translateContext('GENITIVE', 'Aban'),
133                9  => /* I18N: 9th month in the Persian/Jalali calendar */
134                    I18N::translateContext('GENITIVE', 'Azar'),
135                10 => /* I18N: 10th month in the Persian/Jalali calendar */
136                    I18N::translateContext('GENITIVE', 'Dey'),
137                11 => /* I18N: 11th month in the Persian/Jalali calendar */
138                    I18N::translateContext('GENITIVE', 'Bahman'),
139                12 => /* I18N: 12th month in the Persian/Jalali calendar */
140                    I18N::translateContext('GENITIVE', 'Esfand'),
141            ];
142        }
143
144        return $translated_month_names[$month_number];
145    }
146
147    /**
148     * Full month name in locative case.
149     *
150     * @param int  $month_number
151     * @param bool $leap_year Some calendars use leap months
152     *
153     * @return string
154     */
155    protected function monthNameLocativeCase($month_number, $leap_year)
156    {
157        static $translated_month_names;
158
159        if ($translated_month_names === null) {
160            $translated_month_names = [
161                0  => '',
162                1  => /* I18N: 1st month in the Persian/Jalali calendar */
163                    I18N::translateContext('LOCATIVE', 'Farvardin'),
164                2  => /* I18N: 2nd month in the Persian/Jalali calendar */
165                    I18N::translateContext('LOCATIVE', 'Ordibehesht'),
166                3  => /* I18N: 3rd month in the Persian/Jalali calendar */
167                    I18N::translateContext('LOCATIVE', 'Khordad'),
168                4  => /* I18N: 4th month in the Persian/Jalali calendar */
169                    I18N::translateContext('LOCATIVE', 'Tir'),
170                5  => /* I18N: 5th month in the Persian/Jalali calendar */
171                    I18N::translateContext('LOCATIVE', 'Mordad'),
172                6  => /* I18N: 6th month in the Persian/Jalali calendar */
173                    I18N::translateContext('LOCATIVE', 'Shahrivar'),
174                7  => /* I18N: 7th month in the Persian/Jalali calendar */
175                    I18N::translateContext('LOCATIVE', 'Mehr'),
176                8  => /* I18N: 8th month in the Persian/Jalali calendar */
177                    I18N::translateContext('LOCATIVE', 'Aban'),
178                9  => /* I18N: 9th month in the Persian/Jalali calendar */
179                    I18N::translateContext('LOCATIVE', 'Azar'),
180                10 => /* I18N: 10th month in the Persian/Jalali calendar */
181                    I18N::translateContext('LOCATIVE', 'Dey'),
182                11 => /* I18N: 11th month in the Persian/Jalali calendar */
183                    I18N::translateContext('LOCATIVE', 'Bahman'),
184                12 => /* I18N: 12th month in the Persian/Jalali calendar */
185                    I18N::translateContext('LOCATIVE', 'Esfand'),
186            ];
187        }
188
189        return $translated_month_names[$month_number];
190    }
191
192    /**
193     * Full month name in instrumental case.
194     *
195     * @param int  $month_number
196     * @param bool $leap_year Some calendars use leap months
197     *
198     * @return string
199     */
200    protected function monthNameInstrumentalCase($month_number, $leap_year)
201    {
202        static $translated_month_names;
203
204        if ($translated_month_names === null) {
205            $translated_month_names = [
206                0  => '',
207                1  => /* I18N: 1st month in the Persian/Jalali calendar */
208                    I18N::translateContext('INSTRUMENTAL', 'Farvardin'),
209                2  => /* I18N: 2nd month in the Persian/Jalali calendar */
210                    I18N::translateContext('INSTRUMENTAL', 'Ordibehesht'),
211                3  => /* I18N: 3rd month in the Persian/Jalali calendar */
212                    I18N::translateContext('INSTRUMENTAL', 'Khordad'),
213                4  => /* I18N: 4th month in the Persian/Jalali calendar */
214                    I18N::translateContext('INSTRUMENTAL', 'Tir'),
215                5  => /* I18N: 5th month in the Persian/Jalali calendar */
216                    I18N::translateContext('INSTRUMENTAL', 'Mordad'),
217                6  => /* I18N: 6th month in the Persian/Jalali calendar */
218                    I18N::translateContext('INSTRUMENTAL', 'Shahrivar'),
219                7  => /* I18N: 7th month in the Persian/Jalali calendar */
220                    I18N::translateContext('INSTRUMENTAL', 'Mehr'),
221                8  => /* I18N: 8th month in the Persian/Jalali calendar */
222                    I18N::translateContext('INSTRUMENTAL', 'Aban'),
223                9  => /* I18N: 9th month in the Persian/Jalali calendar */
224                    I18N::translateContext('INSTRUMENTAL', 'Azar'),
225                10 => /* I18N: 10th month in the Persian/Jalali calendar */
226                    I18N::translateContext('INSTRUMENTAL', 'Dey'),
227                11 => /* I18N: 11th month in the Persian/Jalali calendar */
228                    I18N::translateContext('INSTRUMENTAL', 'Bahman'),
229                12 => /* I18N: 12th month in the Persian/Jalali calendar */
230                    I18N::translateContext('INSTRUMENTAL', 'Esfand'),
231            ];
232        }
233
234        return $translated_month_names[$month_number];
235    }
236
237    /**
238     * Abbreviated month name
239     *
240     * @param int  $month_number
241     * @param bool $leap_year Some calendars use leap months
242     *
243     * @return string
244     */
245    protected function monthNameAbbreviated($month_number, $leap_year)
246    {
247        static $translated_month_names;
248
249        if ($translated_month_names === null) {
250            $translated_month_names = [
251                0  => '',
252                1  => I18N::translateContext('Abbreviation for Persian month: Farvardin', 'Far'),
253                2  => I18N::translateContext('Abbreviation for Persian month: Ordibehesht', 'Ord'),
254                3  => I18N::translateContext('Abbreviation for Persian month: Khordad', 'Khor'),
255                4  => I18N::translateContext('Abbreviation for Persian month: Tir', 'Tir'),
256                5  => I18N::translateContext('Abbreviation for Persian month: Mordad', 'Mor'),
257                6  => I18N::translateContext('Abbreviation for Persian month: Shahrivar', 'Shah'),
258                7  => I18N::translateContext('Abbreviation for Persian month: Mehr', 'Mehr'),
259                8  => I18N::translateContext('Abbreviation for Persian month: Aban', 'Aban'),
260                9  => I18N::translateContext('Abbreviation for Persian month: Azar', 'Azar'),
261                10 => I18N::translateContext('Abbreviation for Persian month: Dey', 'Dey'),
262                11 => I18N::translateContext('Abbreviation for Persian month: Bahman', 'Bah'),
263                12 => I18N::translateContext('Abbreviation for Persian month: Esfand', 'Esf'),
264            ];
265        }
266
267        return $translated_month_names[$month_number];
268    }
269}
270