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