xref: /webtrees/app/Date/JalaliDate.php (revision 1f3fb95c905e623518962b025974a0e6c19d068b)
1<?php
2/**
3 * webtrees: online genealogy
4 * Copyright (C) 2017 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	/** @var int[] Convert GEDCOM month names to month numbers  */
26	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];
27
28	/**
29	 * Create a date from either:
30	 * a Julian day number
31	 * day/month/year strings from a GEDCOM date
32	 * another CalendarDate object
33	 *
34	 * @param array|int|CalendarDate $date
35	 */
36	public function __construct($date) {
37		$this->calendar = new PersianCalendar;
38		parent::__construct($date);
39	}
40
41	/**
42	 * Full month name in nominative case.
43	 *
44	 * @param int  $month_number
45	 * @param bool $leap_year    Some calendars use leap months
46	 *
47	 * @return string
48	 */
49	public static function monthNameNominativeCase($month_number, $leap_year) {
50		static $translated_month_names;
51
52		if ($translated_month_names === null) {
53			$translated_month_names = [
54				0  => '',
55				1  => /* I18N: 1st month in the Persian/Jalali calendar */ I18N::translateContext('NOMINATIVE', 'Farvardin'),
56				2  => /* I18N: 2nd month in the Persian/Jalali calendar */ I18N::translateContext('NOMINATIVE', 'Ordibehesht'),
57				3  => /* I18N: 3rd month in the Persian/Jalali calendar */ I18N::translateContext('NOMINATIVE', 'Khordad'),
58				4  => /* I18N: 4th month in the Persian/Jalali calendar */ I18N::translateContext('NOMINATIVE', 'Tir'),
59				5  => /* I18N: 5th month in the Persian/Jalali calendar */ I18N::translateContext('NOMINATIVE', 'Mordad'),
60				6  => /* I18N: 6th month in the Persian/Jalali calendar */ I18N::translateContext('NOMINATIVE', 'Shahrivar'),
61				7  => /* I18N: 7th month in the Persian/Jalali calendar */ I18N::translateContext('NOMINATIVE', 'Mehr'),
62				8  => /* I18N: 8th month in the Persian/Jalali calendar */ I18N::translateContext('NOMINATIVE', 'Aban'),
63				9  => /* I18N: 9th month in the Persian/Jalali calendar */ I18N::translateContext('NOMINATIVE', 'Azar'),
64				10 => /* I18N: 10th month in the Persian/Jalali calendar */ I18N::translateContext('NOMINATIVE', 'Dey'),
65				11 => /* I18N: 11th month in the Persian/Jalali calendar */ I18N::translateContext('NOMINATIVE', 'Bahman'),
66				12 => /* I18N: 12th month in the Persian/Jalali calendar */ I18N::translateContext('NOMINATIVE', 'Esfand'),
67			];
68		}
69
70		return $translated_month_names[$month_number];
71	}
72
73	/**
74	 * Full month name in genitive case.
75	 *
76	 * @param int  $month_number
77	 * @param bool $leap_year    Some calendars use leap months
78	 *
79	 * @return string
80	 */
81	protected function monthNameGenitiveCase($month_number, $leap_year) {
82		static $translated_month_names;
83
84		if ($translated_month_names === null) {
85			$translated_month_names = [
86				0  => '',
87				1  => /* I18N: 1st month in the Persian/Jalali calendar */ I18N::translateContext('GENITIVE', 'Farvardin'),
88				2  => /* I18N: 2nd month in the Persian/Jalali calendar */ I18N::translateContext('GENITIVE', 'Ordibehesht'),
89				3  => /* I18N: 3rd month in the Persian/Jalali calendar */ I18N::translateContext('GENITIVE', 'Khordad'),
90				4  => /* I18N: 4th month in the Persian/Jalali calendar */ I18N::translateContext('GENITIVE', 'Tir'),
91				5  => /* I18N: 5th month in the Persian/Jalali calendar */ I18N::translateContext('GENITIVE', 'Mordad'),
92				6  => /* I18N: 6th month in the Persian/Jalali calendar */ I18N::translateContext('GENITIVE', 'Shahrivar'),
93				7  => /* I18N: 7th month in the Persian/Jalali calendar */ I18N::translateContext('GENITIVE', 'Mehr'),
94				8  => /* I18N: 8th month in the Persian/Jalali calendar */ I18N::translateContext('GENITIVE', 'Aban'),
95				9  => /* I18N: 9th month in the Persian/Jalali calendar */ I18N::translateContext('GENITIVE', 'Azar'),
96				10 => /* I18N: 10th month in the Persian/Jalali calendar */ I18N::translateContext('GENITIVE', 'Dey'),
97				11 => /* I18N: 11th month in the Persian/Jalali calendar */ I18N::translateContext('GENITIVE', 'Bahman'),
98				12 => /* I18N: 12th month in the Persian/Jalali calendar */ I18N::translateContext('GENITIVE', 'Esfand'),
99			];
100		}
101
102		return $translated_month_names[$month_number];
103	}
104
105	/**
106	 * Full month name in locative 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 monthNameLocativeCase($month_number, $leap_year) {
114		static $translated_month_names;
115
116		if ($translated_month_names === null) {
117			$translated_month_names = [
118				0  => '',
119				1  => /* I18N: 1st month in the Persian/Jalali calendar */ I18N::translateContext('LOCATIVE', 'Farvardin'),
120				2  => /* I18N: 2nd month in the Persian/Jalali calendar */ I18N::translateContext('LOCATIVE', 'Ordibehesht'),
121				3  => /* I18N: 3rd month in the Persian/Jalali calendar */ I18N::translateContext('LOCATIVE', 'Khordad'),
122				4  => /* I18N: 4th month in the Persian/Jalali calendar */ I18N::translateContext('LOCATIVE', 'Tir'),
123				5  => /* I18N: 5th month in the Persian/Jalali calendar */ I18N::translateContext('LOCATIVE', 'Mordad'),
124				6  => /* I18N: 6th month in the Persian/Jalali calendar */ I18N::translateContext('LOCATIVE', 'Shahrivar'),
125				7  => /* I18N: 7th month in the Persian/Jalali calendar */ I18N::translateContext('LOCATIVE', 'Mehr'),
126				8  => /* I18N: 8th month in the Persian/Jalali calendar */ I18N::translateContext('LOCATIVE', 'Aban'),
127				9  => /* I18N: 9th month in the Persian/Jalali calendar */ I18N::translateContext('LOCATIVE', 'Azar'),
128				10 => /* I18N: 10th month in the Persian/Jalali calendar */ I18N::translateContext('LOCATIVE', 'Dey'),
129				11 => /* I18N: 11th month in the Persian/Jalali calendar */ I18N::translateContext('LOCATIVE', 'Bahman'),
130				12 => /* I18N: 12th month in the Persian/Jalali calendar */ I18N::translateContext('LOCATIVE', 'Esfand'),
131			];
132		}
133
134		return $translated_month_names[$month_number];
135	}
136
137	/**
138	 * Full month name in instrumental case.
139	 *
140	 * @param int  $month_number
141	 * @param bool $leap_year    Some calendars use leap months
142	 *
143	 * @return string
144	 */
145	protected function monthNameInstrumentalCase($month_number, $leap_year) {
146		static $translated_month_names;
147
148		if ($translated_month_names === null) {
149			$translated_month_names = [
150				0  => '',
151				1  => /* I18N: 1st month in the Persian/Jalali calendar */ I18N::translateContext('INSTRUMENTAL', 'Farvardin'),
152				2  => /* I18N: 2nd month in the Persian/Jalali calendar */ I18N::translateContext('INSTRUMENTAL', 'Ordibehesht'),
153				3  => /* I18N: 3rd month in the Persian/Jalali calendar */ I18N::translateContext('INSTRUMENTAL', 'Khordad'),
154				4  => /* I18N: 4th month in the Persian/Jalali calendar */ I18N::translateContext('INSTRUMENTAL', 'Tir'),
155				5  => /* I18N: 5th month in the Persian/Jalali calendar */ I18N::translateContext('INSTRUMENTAL', 'Mordad'),
156				6  => /* I18N: 6th month in the Persian/Jalali calendar */ I18N::translateContext('INSTRUMENTAL', 'Shahrivar'),
157				7  => /* I18N: 7th month in the Persian/Jalali calendar */ I18N::translateContext('INSTRUMENTAL', 'Mehr'),
158				8  => /* I18N: 8th month in the Persian/Jalali calendar */ I18N::translateContext('INSTRUMENTAL', 'Aban'),
159				9  => /* I18N: 9th month in the Persian/Jalali calendar */ I18N::translateContext('INSTRUMENTAL', 'Azar'),
160				10 => /* I18N: 10th month in the Persian/Jalali calendar */ I18N::translateContext('INSTRUMENTAL', 'Dey'),
161				11 => /* I18N: 11th month in the Persian/Jalali calendar */ I18N::translateContext('INSTRUMENTAL', 'Bahman'),
162				12 => /* I18N: 12th month in the Persian/Jalali calendar */ I18N::translateContext('INSTRUMENTAL', 'Esfand'),
163			];
164		}
165
166		return $translated_month_names[$month_number];
167	}
168
169	/**
170	 * Abbreviated month name
171	 *
172	 * @param int  $month_number
173	 * @param bool $leap_year    Some calendars use leap months
174	 *
175	 * @return string
176	 */
177	protected function monthNameAbbreviated($month_number, $leap_year) {
178		static $translated_month_names;
179
180		if ($translated_month_names === null) {
181			$translated_month_names = [
182				0  => '',
183				1  => I18N::translateContext('Abbreviation for Persian month: Farvardin', 'Far'),
184				2  => I18N::translateContext('Abbreviation for Persian month: Ordibehesht', 'Ord'),
185				3  => I18N::translateContext('Abbreviation for Persian month: Khordad', 'Khor'),
186				4  => I18N::translateContext('Abbreviation for Persian month: Tir', 'Tir'),
187				5  => I18N::translateContext('Abbreviation for Persian month: Mordad', 'Mor'),
188				6  => I18N::translateContext('Abbreviation for Persian month: Shahrivar', 'Shah'),
189				7  => I18N::translateContext('Abbreviation for Persian month: Mehr', 'Mehr'),
190				8  => I18N::translateContext('Abbreviation for Persian month: Aban', 'Aban'),
191				9  => I18N::translateContext('Abbreviation for Persian month: Azar', 'Azar'),
192				10 => I18N::translateContext('Abbreviation for Persian month: Dey', 'Dey'),
193				11 => I18N::translateContext('Abbreviation for Persian month: Bahman', 'Bah'),
194				12 => I18N::translateContext('Abbreviation for Persian month: Esfand', 'Esf'),
195			];
196		}
197
198		return $translated_month_names[$month_number];
199	}
200}
201