xref: /webtrees/app/Date/JalaliDate.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\PersianCalendar;
190e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N;
20a25f0a04SGreg Roach
21a25f0a04SGreg Roach/**
2276692c8bSGreg Roach * Definitions for the Jalali calendar
23a25f0a04SGreg Roach */
24c1010edaSGreg Roachclass JalaliDate extends CalendarDate
25c1010edaSGreg Roach{
26e2052359SGreg Roach    /** @var int[] Convert GEDCOM month names to month numbers */
27*b61e86aaSGreg Roach    public static $MONTH_ABBREV = [
28*b61e86aaSGreg Roach        ''      => 0,
29c1010edaSGreg Roach        'FARVA' => 1,
30c1010edaSGreg Roach        'ORDIB' => 2,
31c1010edaSGreg Roach        'KHORD' => 3,
32c1010edaSGreg Roach        'TIR'   => 4,
33c1010edaSGreg Roach        'MORDA' => 5,
34c1010edaSGreg Roach        'SHAHR' => 6,
35c1010edaSGreg Roach        'MEHR'  => 7,
36c1010edaSGreg Roach        'ABAN'  => 8,
37c1010edaSGreg Roach        'AZAR'  => 9,
38c1010edaSGreg Roach        'DEY'   => 10,
39c1010edaSGreg Roach        'BAHMA' => 11,
40c1010edaSGreg Roach        'ESFAN' => 12,
41c1010edaSGreg Roach    ];
42a25f0a04SGreg Roach
4376692c8bSGreg Roach    /**
4476692c8bSGreg Roach     * Create a date from either:
4576692c8bSGreg Roach     * a Julian day number
4676692c8bSGreg Roach     * day/month/year strings from a GEDCOM date
4776692c8bSGreg Roach     * another CalendarDate object
4876692c8bSGreg Roach     *
4976692c8bSGreg Roach     * @param array|int|CalendarDate $date
5076692c8bSGreg Roach     */
51c1010edaSGreg Roach    public function __construct($date)
52c1010edaSGreg Roach    {
53a25f0a04SGreg Roach        $this->calendar = new PersianCalendar;
54a25f0a04SGreg Roach        parent::__construct($date);
55a25f0a04SGreg Roach    }
56a25f0a04SGreg Roach
5776692c8bSGreg Roach    /**
5876692c8bSGreg Roach     * Full month name in nominative case.
5976692c8bSGreg Roach     *
6076692c8bSGreg Roach     * @param int  $month_number
6176692c8bSGreg Roach     * @param bool $leap_year Some calendars use leap months
6276692c8bSGreg Roach     *
6376692c8bSGreg Roach     * @return string
6476692c8bSGreg Roach     */
65c1010edaSGreg Roach    public static function monthNameNominativeCase($month_number, $leap_year)
66c1010edaSGreg Roach    {
67a25f0a04SGreg Roach        static $translated_month_names;
68a25f0a04SGreg Roach
69a25f0a04SGreg Roach        if ($translated_month_names === null) {
7013abd6f3SGreg Roach            $translated_month_names = [
71a25f0a04SGreg Roach                0  => '',
72c1010edaSGreg Roach                1  => /* I18N: 1st month in the Persian/Jalali calendar */
73c1010edaSGreg Roach                    I18N::translateContext('NOMINATIVE', 'Farvardin'),
74c1010edaSGreg Roach                2  => /* I18N: 2nd month in the Persian/Jalali calendar */
75c1010edaSGreg Roach                    I18N::translateContext('NOMINATIVE', 'Ordibehesht'),
76c1010edaSGreg Roach                3  => /* I18N: 3rd month in the Persian/Jalali calendar */
77c1010edaSGreg Roach                    I18N::translateContext('NOMINATIVE', 'Khordad'),
78c1010edaSGreg Roach                4  => /* I18N: 4th month in the Persian/Jalali calendar */
79c1010edaSGreg Roach                    I18N::translateContext('NOMINATIVE', 'Tir'),
80c1010edaSGreg Roach                5  => /* I18N: 5th month in the Persian/Jalali calendar */
81c1010edaSGreg Roach                    I18N::translateContext('NOMINATIVE', 'Mordad'),
82c1010edaSGreg Roach                6  => /* I18N: 6th month in the Persian/Jalali calendar */
83c1010edaSGreg Roach                    I18N::translateContext('NOMINATIVE', 'Shahrivar'),
84c1010edaSGreg Roach                7  => /* I18N: 7th month in the Persian/Jalali calendar */
85c1010edaSGreg Roach                    I18N::translateContext('NOMINATIVE', 'Mehr'),
86c1010edaSGreg Roach                8  => /* I18N: 8th month in the Persian/Jalali calendar */
87c1010edaSGreg Roach                    I18N::translateContext('NOMINATIVE', 'Aban'),
88c1010edaSGreg Roach                9  => /* I18N: 9th month in the Persian/Jalali calendar */
89c1010edaSGreg Roach                    I18N::translateContext('NOMINATIVE', 'Azar'),
90c1010edaSGreg Roach                10 => /* I18N: 10th month in the Persian/Jalali calendar */
91c1010edaSGreg Roach                    I18N::translateContext('NOMINATIVE', 'Dey'),
92c1010edaSGreg Roach                11 => /* I18N: 11th month in the Persian/Jalali calendar */
93c1010edaSGreg Roach                    I18N::translateContext('NOMINATIVE', 'Bahman'),
94c1010edaSGreg Roach                12 => /* I18N: 12th month in the Persian/Jalali calendar */
95c1010edaSGreg Roach                    I18N::translateContext('NOMINATIVE', 'Esfand'),
9613abd6f3SGreg Roach            ];
97a25f0a04SGreg Roach        }
98a25f0a04SGreg Roach
99a25f0a04SGreg Roach        return $translated_month_names[$month_number];
100a25f0a04SGreg Roach    }
101a25f0a04SGreg Roach
10276692c8bSGreg Roach    /**
10376692c8bSGreg Roach     * Full month name in genitive case.
10476692c8bSGreg Roach     *
10576692c8bSGreg Roach     * @param int  $month_number
10676692c8bSGreg Roach     * @param bool $leap_year Some calendars use leap months
10776692c8bSGreg Roach     *
10876692c8bSGreg Roach     * @return string
10976692c8bSGreg Roach     */
110c1010edaSGreg Roach    protected function monthNameGenitiveCase($month_number, $leap_year)
111c1010edaSGreg Roach    {
112a25f0a04SGreg Roach        static $translated_month_names;
113a25f0a04SGreg Roach
114a25f0a04SGreg Roach        if ($translated_month_names === null) {
11513abd6f3SGreg Roach            $translated_month_names = [
116a25f0a04SGreg Roach                0  => '',
117c1010edaSGreg Roach                1  => /* I18N: 1st month in the Persian/Jalali calendar */
118c1010edaSGreg Roach                    I18N::translateContext('GENITIVE', 'Farvardin'),
119c1010edaSGreg Roach                2  => /* I18N: 2nd month in the Persian/Jalali calendar */
120c1010edaSGreg Roach                    I18N::translateContext('GENITIVE', 'Ordibehesht'),
121c1010edaSGreg Roach                3  => /* I18N: 3rd month in the Persian/Jalali calendar */
122c1010edaSGreg Roach                    I18N::translateContext('GENITIVE', 'Khordad'),
123c1010edaSGreg Roach                4  => /* I18N: 4th month in the Persian/Jalali calendar */
124c1010edaSGreg Roach                    I18N::translateContext('GENITIVE', 'Tir'),
125c1010edaSGreg Roach                5  => /* I18N: 5th month in the Persian/Jalali calendar */
126c1010edaSGreg Roach                    I18N::translateContext('GENITIVE', 'Mordad'),
127c1010edaSGreg Roach                6  => /* I18N: 6th month in the Persian/Jalali calendar */
128c1010edaSGreg Roach                    I18N::translateContext('GENITIVE', 'Shahrivar'),
129c1010edaSGreg Roach                7  => /* I18N: 7th month in the Persian/Jalali calendar */
130c1010edaSGreg Roach                    I18N::translateContext('GENITIVE', 'Mehr'),
131c1010edaSGreg Roach                8  => /* I18N: 8th month in the Persian/Jalali calendar */
132c1010edaSGreg Roach                    I18N::translateContext('GENITIVE', 'Aban'),
133c1010edaSGreg Roach                9  => /* I18N: 9th month in the Persian/Jalali calendar */
134c1010edaSGreg Roach                    I18N::translateContext('GENITIVE', 'Azar'),
135c1010edaSGreg Roach                10 => /* I18N: 10th month in the Persian/Jalali calendar */
136c1010edaSGreg Roach                    I18N::translateContext('GENITIVE', 'Dey'),
137c1010edaSGreg Roach                11 => /* I18N: 11th month in the Persian/Jalali calendar */
138c1010edaSGreg Roach                    I18N::translateContext('GENITIVE', 'Bahman'),
139c1010edaSGreg Roach                12 => /* I18N: 12th month in the Persian/Jalali calendar */
140c1010edaSGreg Roach                    I18N::translateContext('GENITIVE', 'Esfand'),
14113abd6f3SGreg Roach            ];
142a25f0a04SGreg Roach        }
143a25f0a04SGreg Roach
144a25f0a04SGreg Roach        return $translated_month_names[$month_number];
145a25f0a04SGreg Roach    }
146a25f0a04SGreg Roach
14776692c8bSGreg Roach    /**
14876692c8bSGreg Roach     * Full month name in locative case.
14976692c8bSGreg Roach     *
15076692c8bSGreg Roach     * @param int  $month_number
15176692c8bSGreg Roach     * @param bool $leap_year Some calendars use leap months
15276692c8bSGreg Roach     *
15376692c8bSGreg Roach     * @return string
15476692c8bSGreg Roach     */
155c1010edaSGreg Roach    protected function monthNameLocativeCase($month_number, $leap_year)
156c1010edaSGreg Roach    {
157a25f0a04SGreg Roach        static $translated_month_names;
158a25f0a04SGreg Roach
159a25f0a04SGreg Roach        if ($translated_month_names === null) {
16013abd6f3SGreg Roach            $translated_month_names = [
161a25f0a04SGreg Roach                0  => '',
162c1010edaSGreg Roach                1  => /* I18N: 1st month in the Persian/Jalali calendar */
163c1010edaSGreg Roach                    I18N::translateContext('LOCATIVE', 'Farvardin'),
164c1010edaSGreg Roach                2  => /* I18N: 2nd month in the Persian/Jalali calendar */
165c1010edaSGreg Roach                    I18N::translateContext('LOCATIVE', 'Ordibehesht'),
166c1010edaSGreg Roach                3  => /* I18N: 3rd month in the Persian/Jalali calendar */
167c1010edaSGreg Roach                    I18N::translateContext('LOCATIVE', 'Khordad'),
168c1010edaSGreg Roach                4  => /* I18N: 4th month in the Persian/Jalali calendar */
169c1010edaSGreg Roach                    I18N::translateContext('LOCATIVE', 'Tir'),
170c1010edaSGreg Roach                5  => /* I18N: 5th month in the Persian/Jalali calendar */
171c1010edaSGreg Roach                    I18N::translateContext('LOCATIVE', 'Mordad'),
172c1010edaSGreg Roach                6  => /* I18N: 6th month in the Persian/Jalali calendar */
173c1010edaSGreg Roach                    I18N::translateContext('LOCATIVE', 'Shahrivar'),
174c1010edaSGreg Roach                7  => /* I18N: 7th month in the Persian/Jalali calendar */
175c1010edaSGreg Roach                    I18N::translateContext('LOCATIVE', 'Mehr'),
176c1010edaSGreg Roach                8  => /* I18N: 8th month in the Persian/Jalali calendar */
177c1010edaSGreg Roach                    I18N::translateContext('LOCATIVE', 'Aban'),
178c1010edaSGreg Roach                9  => /* I18N: 9th month in the Persian/Jalali calendar */
179c1010edaSGreg Roach                    I18N::translateContext('LOCATIVE', 'Azar'),
180c1010edaSGreg Roach                10 => /* I18N: 10th month in the Persian/Jalali calendar */
181c1010edaSGreg Roach                    I18N::translateContext('LOCATIVE', 'Dey'),
182c1010edaSGreg Roach                11 => /* I18N: 11th month in the Persian/Jalali calendar */
183c1010edaSGreg Roach                    I18N::translateContext('LOCATIVE', 'Bahman'),
184c1010edaSGreg Roach                12 => /* I18N: 12th month in the Persian/Jalali calendar */
185c1010edaSGreg Roach                    I18N::translateContext('LOCATIVE', 'Esfand'),
18613abd6f3SGreg Roach            ];
187a25f0a04SGreg Roach        }
188a25f0a04SGreg Roach
189a25f0a04SGreg Roach        return $translated_month_names[$month_number];
190a25f0a04SGreg Roach    }
191a25f0a04SGreg Roach
19276692c8bSGreg Roach    /**
19376692c8bSGreg Roach     * Full month name in instrumental case.
19476692c8bSGreg Roach     *
19576692c8bSGreg Roach     * @param int  $month_number
19676692c8bSGreg Roach     * @param bool $leap_year Some calendars use leap months
19776692c8bSGreg Roach     *
19876692c8bSGreg Roach     * @return string
19976692c8bSGreg Roach     */
200c1010edaSGreg Roach    protected function monthNameInstrumentalCase($month_number, $leap_year)
201c1010edaSGreg Roach    {
202a25f0a04SGreg Roach        static $translated_month_names;
203a25f0a04SGreg Roach
204a25f0a04SGreg Roach        if ($translated_month_names === null) {
20513abd6f3SGreg Roach            $translated_month_names = [
206a25f0a04SGreg Roach                0  => '',
207c1010edaSGreg Roach                1  => /* I18N: 1st month in the Persian/Jalali calendar */
208c1010edaSGreg Roach                    I18N::translateContext('INSTRUMENTAL', 'Farvardin'),
209c1010edaSGreg Roach                2  => /* I18N: 2nd month in the Persian/Jalali calendar */
210c1010edaSGreg Roach                    I18N::translateContext('INSTRUMENTAL', 'Ordibehesht'),
211c1010edaSGreg Roach                3  => /* I18N: 3rd month in the Persian/Jalali calendar */
212c1010edaSGreg Roach                    I18N::translateContext('INSTRUMENTAL', 'Khordad'),
213c1010edaSGreg Roach                4  => /* I18N: 4th month in the Persian/Jalali calendar */
214c1010edaSGreg Roach                    I18N::translateContext('INSTRUMENTAL', 'Tir'),
215c1010edaSGreg Roach                5  => /* I18N: 5th month in the Persian/Jalali calendar */
216c1010edaSGreg Roach                    I18N::translateContext('INSTRUMENTAL', 'Mordad'),
217c1010edaSGreg Roach                6  => /* I18N: 6th month in the Persian/Jalali calendar */
218c1010edaSGreg Roach                    I18N::translateContext('INSTRUMENTAL', 'Shahrivar'),
219c1010edaSGreg Roach                7  => /* I18N: 7th month in the Persian/Jalali calendar */
220c1010edaSGreg Roach                    I18N::translateContext('INSTRUMENTAL', 'Mehr'),
221c1010edaSGreg Roach                8  => /* I18N: 8th month in the Persian/Jalali calendar */
222c1010edaSGreg Roach                    I18N::translateContext('INSTRUMENTAL', 'Aban'),
223c1010edaSGreg Roach                9  => /* I18N: 9th month in the Persian/Jalali calendar */
224c1010edaSGreg Roach                    I18N::translateContext('INSTRUMENTAL', 'Azar'),
225c1010edaSGreg Roach                10 => /* I18N: 10th month in the Persian/Jalali calendar */
226c1010edaSGreg Roach                    I18N::translateContext('INSTRUMENTAL', 'Dey'),
227c1010edaSGreg Roach                11 => /* I18N: 11th month in the Persian/Jalali calendar */
228c1010edaSGreg Roach                    I18N::translateContext('INSTRUMENTAL', 'Bahman'),
229c1010edaSGreg Roach                12 => /* I18N: 12th month in the Persian/Jalali calendar */
230c1010edaSGreg Roach                    I18N::translateContext('INSTRUMENTAL', 'Esfand'),
23113abd6f3SGreg Roach            ];
232a25f0a04SGreg Roach        }
233a25f0a04SGreg Roach
234a25f0a04SGreg Roach        return $translated_month_names[$month_number];
235a25f0a04SGreg Roach    }
236a25f0a04SGreg Roach
23776692c8bSGreg Roach    /**
23876692c8bSGreg Roach     * Abbreviated month name
23976692c8bSGreg Roach     *
24076692c8bSGreg Roach     * @param int  $month_number
24176692c8bSGreg Roach     * @param bool $leap_year Some calendars use leap months
24276692c8bSGreg Roach     *
24376692c8bSGreg Roach     * @return string
24476692c8bSGreg Roach     */
245c1010edaSGreg Roach    protected function monthNameAbbreviated($month_number, $leap_year)
246c1010edaSGreg Roach    {
247a25f0a04SGreg Roach        static $translated_month_names;
248a25f0a04SGreg Roach
249a25f0a04SGreg Roach        if ($translated_month_names === null) {
25013abd6f3SGreg Roach            $translated_month_names = [
251a25f0a04SGreg Roach                0  => '',
252764a01d9SGreg Roach                1  => I18N::translateContext('Abbreviation for Persian month: Farvardin', 'Far'),
253764a01d9SGreg Roach                2  => I18N::translateContext('Abbreviation for Persian month: Ordibehesht', 'Ord'),
254764a01d9SGreg Roach                3  => I18N::translateContext('Abbreviation for Persian month: Khordad', 'Khor'),
255764a01d9SGreg Roach                4  => I18N::translateContext('Abbreviation for Persian month: Tir', 'Tir'),
256764a01d9SGreg Roach                5  => I18N::translateContext('Abbreviation for Persian month: Mordad', 'Mor'),
257764a01d9SGreg Roach                6  => I18N::translateContext('Abbreviation for Persian month: Shahrivar', 'Shah'),
258764a01d9SGreg Roach                7  => I18N::translateContext('Abbreviation for Persian month: Mehr', 'Mehr'),
259764a01d9SGreg Roach                8  => I18N::translateContext('Abbreviation for Persian month: Aban', 'Aban'),
260764a01d9SGreg Roach                9  => I18N::translateContext('Abbreviation for Persian month: Azar', 'Azar'),
261764a01d9SGreg Roach                10 => I18N::translateContext('Abbreviation for Persian month: Dey', 'Dey'),
262764a01d9SGreg Roach                11 => I18N::translateContext('Abbreviation for Persian month: Bahman', 'Bah'),
263764a01d9SGreg Roach                12 => I18N::translateContext('Abbreviation for Persian month: Esfand', 'Esf'),
26413abd6f3SGreg Roach            ];
265a25f0a04SGreg Roach        }
266a25f0a04SGreg Roach
267a25f0a04SGreg Roach        return $translated_month_names[$month_number];
268a25f0a04SGreg Roach    }
269a25f0a04SGreg Roach}
270