xref: /webtrees/app/Date/JalaliDate.php (revision 1062a1429914c995339f502856821457aa975a5a)
1a25f0a04SGreg Roach<?php
2a25f0a04SGreg Roach/**
3a25f0a04SGreg Roach * webtrees: online genealogy
4*1062a142SGreg 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 */
24a25f0a04SGreg Roachclass JalaliDate extends CalendarDate {
25e2052359SGreg Roach	/** @var int[] Convert GEDCOM month names to month numbers  */
2613abd6f3SGreg Roach	public static $MONTH_ABBREV = ['' => 0, 'FARVA' => 1, 'ORDIB' => 2, 'KHORD' => 3, 'TIR' => 4, 'MORDA' => 5, 'SHAHR' => 6, 'MEHR' => 7, 'ABAN' => 8, 'AZAR' => 9, 'DEY' => 10, 'BAHMA' => 11, 'ESFAN' => 12];
27a25f0a04SGreg Roach
2876692c8bSGreg Roach	/**
2976692c8bSGreg Roach	 * Create a date from either:
3076692c8bSGreg Roach	 * a Julian day number
3176692c8bSGreg Roach	 * day/month/year strings from a GEDCOM date
3276692c8bSGreg Roach	 * another CalendarDate object
3376692c8bSGreg Roach	 *
3476692c8bSGreg Roach	 * @param array|int|CalendarDate $date
3576692c8bSGreg Roach	 */
36a25f0a04SGreg Roach	public function __construct($date) {
37a25f0a04SGreg Roach		$this->calendar = new PersianCalendar;
38a25f0a04SGreg Roach		parent::__construct($date);
39a25f0a04SGreg Roach	}
40a25f0a04SGreg Roach
4176692c8bSGreg Roach	/**
4276692c8bSGreg Roach	 * Full month name in nominative case.
4376692c8bSGreg Roach	 *
4476692c8bSGreg Roach	 * @param int  $month_number
4576692c8bSGreg Roach	 * @param bool $leap_year    Some calendars use leap months
4676692c8bSGreg Roach	 *
4776692c8bSGreg Roach	 * @return string
4876692c8bSGreg Roach	 */
49a25f0a04SGreg Roach	public static function monthNameNominativeCase($month_number, $leap_year) {
50a25f0a04SGreg Roach		static $translated_month_names;
51a25f0a04SGreg Roach
52a25f0a04SGreg Roach		if ($translated_month_names === null) {
5313abd6f3SGreg Roach			$translated_month_names = [
54a25f0a04SGreg Roach				0  => '',
55764a01d9SGreg Roach				1  => /* I18N: 1st month in the Persian/Jalali calendar */ I18N::translateContext('NOMINATIVE', 'Farvardin'),
56764a01d9SGreg Roach				2  => /* I18N: 2nd month in the Persian/Jalali calendar */ I18N::translateContext('NOMINATIVE', 'Ordibehesht'),
57764a01d9SGreg Roach				3  => /* I18N: 3rd month in the Persian/Jalali calendar */ I18N::translateContext('NOMINATIVE', 'Khordad'),
58764a01d9SGreg Roach				4  => /* I18N: 4th month in the Persian/Jalali calendar */ I18N::translateContext('NOMINATIVE', 'Tir'),
59764a01d9SGreg Roach				5  => /* I18N: 5th month in the Persian/Jalali calendar */ I18N::translateContext('NOMINATIVE', 'Mordad'),
60764a01d9SGreg Roach				6  => /* I18N: 6th month in the Persian/Jalali calendar */ I18N::translateContext('NOMINATIVE', 'Shahrivar'),
61764a01d9SGreg Roach				7  => /* I18N: 7th month in the Persian/Jalali calendar */ I18N::translateContext('NOMINATIVE', 'Mehr'),
62764a01d9SGreg Roach				8  => /* I18N: 8th month in the Persian/Jalali calendar */ I18N::translateContext('NOMINATIVE', 'Aban'),
63764a01d9SGreg Roach				9  => /* I18N: 9th month in the Persian/Jalali calendar */ I18N::translateContext('NOMINATIVE', 'Azar'),
64764a01d9SGreg Roach				10 => /* I18N: 10th month in the Persian/Jalali calendar */ I18N::translateContext('NOMINATIVE', 'Dey'),
65764a01d9SGreg Roach				11 => /* I18N: 11th month in the Persian/Jalali calendar */ I18N::translateContext('NOMINATIVE', 'Bahman'),
66764a01d9SGreg Roach				12 => /* I18N: 12th month in the Persian/Jalali calendar */ I18N::translateContext('NOMINATIVE', 'Esfand'),
6713abd6f3SGreg Roach			];
68a25f0a04SGreg Roach		}
69a25f0a04SGreg Roach
70a25f0a04SGreg Roach		return $translated_month_names[$month_number];
71a25f0a04SGreg Roach	}
72a25f0a04SGreg Roach
7376692c8bSGreg Roach	/**
7476692c8bSGreg Roach	 * Full month name in genitive case.
7576692c8bSGreg Roach	 *
7676692c8bSGreg Roach	 * @param int  $month_number
7776692c8bSGreg Roach	 * @param bool $leap_year    Some calendars use leap months
7876692c8bSGreg Roach	 *
7976692c8bSGreg Roach	 * @return string
8076692c8bSGreg Roach	 */
8117920f94SGreg Roach	protected function monthNameGenitiveCase($month_number, $leap_year) {
82a25f0a04SGreg Roach		static $translated_month_names;
83a25f0a04SGreg Roach
84a25f0a04SGreg Roach		if ($translated_month_names === null) {
8513abd6f3SGreg Roach			$translated_month_names = [
86a25f0a04SGreg Roach				0  => '',
87764a01d9SGreg Roach				1  => /* I18N: 1st month in the Persian/Jalali calendar */ I18N::translateContext('GENITIVE', 'Farvardin'),
88764a01d9SGreg Roach				2  => /* I18N: 2nd month in the Persian/Jalali calendar */ I18N::translateContext('GENITIVE', 'Ordibehesht'),
89764a01d9SGreg Roach				3  => /* I18N: 3rd month in the Persian/Jalali calendar */ I18N::translateContext('GENITIVE', 'Khordad'),
90764a01d9SGreg Roach				4  => /* I18N: 4th month in the Persian/Jalali calendar */ I18N::translateContext('GENITIVE', 'Tir'),
91764a01d9SGreg Roach				5  => /* I18N: 5th month in the Persian/Jalali calendar */ I18N::translateContext('GENITIVE', 'Mordad'),
92764a01d9SGreg Roach				6  => /* I18N: 6th month in the Persian/Jalali calendar */ I18N::translateContext('GENITIVE', 'Shahrivar'),
93764a01d9SGreg Roach				7  => /* I18N: 7th month in the Persian/Jalali calendar */ I18N::translateContext('GENITIVE', 'Mehr'),
94764a01d9SGreg Roach				8  => /* I18N: 8th month in the Persian/Jalali calendar */ I18N::translateContext('GENITIVE', 'Aban'),
95764a01d9SGreg Roach				9  => /* I18N: 9th month in the Persian/Jalali calendar */ I18N::translateContext('GENITIVE', 'Azar'),
96764a01d9SGreg Roach				10 => /* I18N: 10th month in the Persian/Jalali calendar */ I18N::translateContext('GENITIVE', 'Dey'),
97764a01d9SGreg Roach				11 => /* I18N: 11th month in the Persian/Jalali calendar */ I18N::translateContext('GENITIVE', 'Bahman'),
98764a01d9SGreg Roach				12 => /* I18N: 12th month in the Persian/Jalali calendar */ I18N::translateContext('GENITIVE', 'Esfand'),
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 locative 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	 */
11317920f94SGreg Roach	protected function monthNameLocativeCase($month_number, $leap_year) {
114a25f0a04SGreg Roach		static $translated_month_names;
115a25f0a04SGreg Roach
116a25f0a04SGreg Roach		if ($translated_month_names === null) {
11713abd6f3SGreg Roach			$translated_month_names = [
118a25f0a04SGreg Roach				0  => '',
119764a01d9SGreg Roach				1  => /* I18N: 1st month in the Persian/Jalali calendar */ I18N::translateContext('LOCATIVE', 'Farvardin'),
120764a01d9SGreg Roach				2  => /* I18N: 2nd month in the Persian/Jalali calendar */ I18N::translateContext('LOCATIVE', 'Ordibehesht'),
121764a01d9SGreg Roach				3  => /* I18N: 3rd month in the Persian/Jalali calendar */ I18N::translateContext('LOCATIVE', 'Khordad'),
122764a01d9SGreg Roach				4  => /* I18N: 4th month in the Persian/Jalali calendar */ I18N::translateContext('LOCATIVE', 'Tir'),
123764a01d9SGreg Roach				5  => /* I18N: 5th month in the Persian/Jalali calendar */ I18N::translateContext('LOCATIVE', 'Mordad'),
124764a01d9SGreg Roach				6  => /* I18N: 6th month in the Persian/Jalali calendar */ I18N::translateContext('LOCATIVE', 'Shahrivar'),
125764a01d9SGreg Roach				7  => /* I18N: 7th month in the Persian/Jalali calendar */ I18N::translateContext('LOCATIVE', 'Mehr'),
126764a01d9SGreg Roach				8  => /* I18N: 8th month in the Persian/Jalali calendar */ I18N::translateContext('LOCATIVE', 'Aban'),
127764a01d9SGreg Roach				9  => /* I18N: 9th month in the Persian/Jalali calendar */ I18N::translateContext('LOCATIVE', 'Azar'),
128764a01d9SGreg Roach				10 => /* I18N: 10th month in the Persian/Jalali calendar */ I18N::translateContext('LOCATIVE', 'Dey'),
129764a01d9SGreg Roach				11 => /* I18N: 11th month in the Persian/Jalali calendar */ I18N::translateContext('LOCATIVE', 'Bahman'),
130764a01d9SGreg Roach				12 => /* I18N: 12th month in the Persian/Jalali calendar */ I18N::translateContext('LOCATIVE', 'Esfand'),
13113abd6f3SGreg Roach			];
132a25f0a04SGreg Roach		}
133a25f0a04SGreg Roach
134a25f0a04SGreg Roach		return $translated_month_names[$month_number];
135a25f0a04SGreg Roach	}
136a25f0a04SGreg Roach
13776692c8bSGreg Roach	/**
13876692c8bSGreg Roach	 * Full month name in instrumental case.
13976692c8bSGreg Roach	 *
14076692c8bSGreg Roach	 * @param int  $month_number
14176692c8bSGreg Roach	 * @param bool $leap_year    Some calendars use leap months
14276692c8bSGreg Roach	 *
14376692c8bSGreg Roach	 * @return string
14476692c8bSGreg Roach	 */
14517920f94SGreg Roach	protected function monthNameInstrumentalCase($month_number, $leap_year) {
146a25f0a04SGreg Roach		static $translated_month_names;
147a25f0a04SGreg Roach
148a25f0a04SGreg Roach		if ($translated_month_names === null) {
14913abd6f3SGreg Roach			$translated_month_names = [
150a25f0a04SGreg Roach				0  => '',
151764a01d9SGreg Roach				1  => /* I18N: 1st month in the Persian/Jalali calendar */ I18N::translateContext('INSTRUMENTAL', 'Farvardin'),
152764a01d9SGreg Roach				2  => /* I18N: 2nd month in the Persian/Jalali calendar */ I18N::translateContext('INSTRUMENTAL', 'Ordibehesht'),
153764a01d9SGreg Roach				3  => /* I18N: 3rd month in the Persian/Jalali calendar */ I18N::translateContext('INSTRUMENTAL', 'Khordad'),
154764a01d9SGreg Roach				4  => /* I18N: 4th month in the Persian/Jalali calendar */ I18N::translateContext('INSTRUMENTAL', 'Tir'),
155764a01d9SGreg Roach				5  => /* I18N: 5th month in the Persian/Jalali calendar */ I18N::translateContext('INSTRUMENTAL', 'Mordad'),
156764a01d9SGreg Roach				6  => /* I18N: 6th month in the Persian/Jalali calendar */ I18N::translateContext('INSTRUMENTAL', 'Shahrivar'),
157764a01d9SGreg Roach				7  => /* I18N: 7th month in the Persian/Jalali calendar */ I18N::translateContext('INSTRUMENTAL', 'Mehr'),
158764a01d9SGreg Roach				8  => /* I18N: 8th month in the Persian/Jalali calendar */ I18N::translateContext('INSTRUMENTAL', 'Aban'),
159764a01d9SGreg Roach				9  => /* I18N: 9th month in the Persian/Jalali calendar */ I18N::translateContext('INSTRUMENTAL', 'Azar'),
160764a01d9SGreg Roach				10 => /* I18N: 10th month in the Persian/Jalali calendar */ I18N::translateContext('INSTRUMENTAL', 'Dey'),
161764a01d9SGreg Roach				11 => /* I18N: 11th month in the Persian/Jalali calendar */ I18N::translateContext('INSTRUMENTAL', 'Bahman'),
162764a01d9SGreg Roach				12 => /* I18N: 12th month in the Persian/Jalali calendar */ I18N::translateContext('INSTRUMENTAL', 'Esfand'),
16313abd6f3SGreg Roach			];
164a25f0a04SGreg Roach		}
165a25f0a04SGreg Roach
166a25f0a04SGreg Roach		return $translated_month_names[$month_number];
167a25f0a04SGreg Roach	}
168a25f0a04SGreg Roach
16976692c8bSGreg Roach	/**
17076692c8bSGreg Roach	 * Abbreviated month name
17176692c8bSGreg Roach	 *
17276692c8bSGreg Roach	 * @param int  $month_number
17376692c8bSGreg Roach	 * @param bool $leap_year    Some calendars use leap months
17476692c8bSGreg Roach	 *
17576692c8bSGreg Roach	 * @return string
17676692c8bSGreg Roach	 */
17717920f94SGreg Roach	protected function monthNameAbbreviated($month_number, $leap_year) {
178a25f0a04SGreg Roach		static $translated_month_names;
179a25f0a04SGreg Roach
180a25f0a04SGreg Roach		if ($translated_month_names === null) {
18113abd6f3SGreg Roach			$translated_month_names = [
182a25f0a04SGreg Roach				0  => '',
183764a01d9SGreg Roach				1  => I18N::translateContext('Abbreviation for Persian month: Farvardin', 'Far'),
184764a01d9SGreg Roach				2  => I18N::translateContext('Abbreviation for Persian month: Ordibehesht', 'Ord'),
185764a01d9SGreg Roach				3  => I18N::translateContext('Abbreviation for Persian month: Khordad', 'Khor'),
186764a01d9SGreg Roach				4  => I18N::translateContext('Abbreviation for Persian month: Tir', 'Tir'),
187764a01d9SGreg Roach				5  => I18N::translateContext('Abbreviation for Persian month: Mordad', 'Mor'),
188764a01d9SGreg Roach				6  => I18N::translateContext('Abbreviation for Persian month: Shahrivar', 'Shah'),
189764a01d9SGreg Roach				7  => I18N::translateContext('Abbreviation for Persian month: Mehr', 'Mehr'),
190764a01d9SGreg Roach				8  => I18N::translateContext('Abbreviation for Persian month: Aban', 'Aban'),
191764a01d9SGreg Roach				9  => I18N::translateContext('Abbreviation for Persian month: Azar', 'Azar'),
192764a01d9SGreg Roach				10 => I18N::translateContext('Abbreviation for Persian month: Dey', 'Dey'),
193764a01d9SGreg Roach				11 => I18N::translateContext('Abbreviation for Persian month: Bahman', 'Bah'),
194764a01d9SGreg Roach				12 => I18N::translateContext('Abbreviation for Persian month: Esfand', 'Esf'),
19513abd6f3SGreg Roach			];
196a25f0a04SGreg Roach		}
197a25f0a04SGreg Roach
198a25f0a04SGreg Roach		return $translated_month_names[$month_number];
199a25f0a04SGreg Roach	}
200a25f0a04SGreg Roach}
201