xref: /webtrees/app/Date/JewishDate.php (revision 17920f94befaa1d6150480429428429b0bee7e3a)
1<?php
2namespace Fisharebest\Webtrees;
3
4/**
5 * webtrees: online genealogy
6 * Copyright (C) 2015 webtrees development team
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19use Fisharebest\ExtCalendar\JewishCalendar;
20
21/**
22 * Class JewishDate - Definitions for the Jewish calendar
23 */
24class JewishDate extends CalendarDate {
25	/** {@inheritdoc} */
26	public static $MONTH_ABBREV = array('' => 0, 'TSH' => 1, 'CSH' => 2, 'KSL' => 3, 'TVT' => 4, 'SHV' => 5, 'ADR' => 6, 'ADS' => 7, 'NSN' => 8, 'IYR' => 9, 'SVN' => 10, 'TMZ' => 11, 'AAV' => 12, 'ELL' => 13);
27
28	/** {@inheritdoc} */
29	public function __construct($date) {
30		$this->calendar = new JewishCalendar;
31		parent::__construct($date);
32	}
33
34	/** {@inheritdoc} */
35	protected function formatDay() {
36		if (WT_LOCALE === 'he' || WT_LOCALE === 'yi') {
37			return $this->calendar->numberToHebrewNumerals($this->d, true);
38		} else {
39			return $this->d;
40		}
41	}
42
43	/** {@inheritdoc} */
44	protected function formatShortYear() {
45		if (WT_LOCALE === 'he' || WT_LOCALE === 'yi') {
46			return $this->calendar->numberToHebrewNumerals($this->y, false);
47		} else {
48			return $this->y;
49		}
50	}
51
52	/** {@inheritdoc} */
53	protected function formatLongYear() {
54		if (WT_LOCALE === 'he' || WT_LOCALE === 'yi') {
55			return $this->calendar->numberToHebrewNumerals($this->y, true);
56		} else {
57			return $this->y;
58		}
59	}
60
61	/** {@inheritdoc} */
62	public static function monthNameNominativeCase($month_number, $leap_year) {
63		static $translated_month_names;
64
65		if ($translated_month_names === null) {
66			$translated_month_names = array(
67				0  => '',
68				1  => /* I18N: a month in the Jewish calendar */ I18N::translateContext('NOMINATIVE', 'Tishrei'),
69				2  => /* I18N: a month in the Jewish calendar */ I18N::translateContext('NOMINATIVE', 'Heshvan'),
70				3  => /* I18N: a month in the Jewish calendar */ I18N::translateContext('NOMINATIVE', 'Kislev'),
71				4  => /* I18N: a month in the Jewish calendar */ I18N::translateContext('NOMINATIVE', 'Tevet'),
72				5  => /* I18N: a month in the Jewish calendar */ I18N::translateContext('NOMINATIVE', 'Shevat'),
73				6  => /* I18N: a month in the Jewish calendar */ I18N::translateContext('NOMINATIVE', 'Adar I'),
74				7  => /* I18N: a month in the Jewish calendar */ I18N::translateContext('NOMINATIVE', 'Adar'),
75				-7 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('NOMINATIVE', 'Adar II'),
76				8  => /* I18N: a month in the Jewish calendar */ I18N::translateContext('NOMINATIVE', 'Nissan'),
77				9  => /* I18N: a month in the Jewish calendar */ I18N::translateContext('NOMINATIVE', 'Iyar'),
78				10 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('NOMINATIVE', 'Sivan'),
79				11 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('NOMINATIVE', 'Tamuz'),
80				12 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('NOMINATIVE', 'Av'),
81				13 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('NOMINATIVE', 'Elul'),
82			);
83		}
84
85		if ($month_number === 7 && $leap_year) {
86			return $translated_month_names[-7];
87		} else {
88			return $translated_month_names[$month_number];
89		}
90	}
91
92	/** {@inheritdoc} */
93	protected function monthNameGenitiveCase($month_number, $leap_year) {
94		static $translated_month_names;
95
96		if ($translated_month_names === null) {
97			$translated_month_names = array(
98				0  => '',
99				1  => /* I18N: a month in the Jewish calendar */ I18N::translateContext('GENITIVE', 'Tishrei'),
100				2  => /* I18N: a month in the Jewish calendar */ I18N::translateContext('GENITIVE', 'Heshvan'),
101				3  => /* I18N: a month in the Jewish calendar */ I18N::translateContext('GENITIVE', 'Kislev'),
102				4  => /* I18N: a month in the Jewish calendar */ I18N::translateContext('GENITIVE', 'Tevet'),
103				5  => /* I18N: a month in the Jewish calendar */ I18N::translateContext('GENITIVE', 'Shevat'),
104				6  => /* I18N: a month in the Jewish calendar */ I18N::translateContext('GENITIVE', 'Adar I'),
105				7  => /* I18N: a month in the Jewish calendar */ I18N::translateContext('GENITIVE', 'Adar'),
106				-7 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('GENITIVE', 'Adar II'),
107				8  => /* I18N: a month in the Jewish calendar */ I18N::translateContext('GENITIVE', 'Nissan'),
108				9  => /* I18N: a month in the Jewish calendar */ I18N::translateContext('GENITIVE', 'Iyar'),
109				10 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('GENITIVE', 'Sivan'),
110				11 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('GENITIVE', 'Tamuz'),
111				12 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('GENITIVE', 'Av'),
112				13 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('GENITIVE', 'Elul'),
113			);
114		}
115
116		if ($month_number === 7 && $leap_year) {
117			return $translated_month_names[-7];
118		} else {
119			return $translated_month_names[$month_number];
120		}
121	}
122
123	/** {@inheritdoc} */
124	protected function monthNameLocativeCase($month_number, $leap_year) {
125		static $translated_month_names;
126
127		if ($translated_month_names === null) {
128			$translated_month_names = array(
129				0  => '',
130				1  => /* I18N: a month in the Jewish calendar */ I18N::translateContext('LOCATIVE', 'Tishrei'),
131				2  => /* I18N: a month in the Jewish calendar */ I18N::translateContext('LOCATIVE', 'Heshvan'),
132				3  => /* I18N: a month in the Jewish calendar */ I18N::translateContext('LOCATIVE', 'Kislev'),
133				4  => /* I18N: a month in the Jewish calendar */ I18N::translateContext('LOCATIVE', 'Tevet'),
134				5  => /* I18N: a month in the Jewish calendar */ I18N::translateContext('LOCATIVE', 'Shevat'),
135				6  => /* I18N: a month in the Jewish calendar */ I18N::translateContext('LOCATIVE', 'Adar I'),
136				7  => /* I18N: a month in the Jewish calendar */ I18N::translateContext('LOCATIVE', 'Adar'),
137				-7 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('LOCATIVE', 'Adar II'),
138				8  => /* I18N: a month in the Jewish calendar */ I18N::translateContext('LOCATIVE', 'Nissan'),
139				9  => /* I18N: a month in the Jewish calendar */ I18N::translateContext('LOCATIVE', 'Iyar'),
140				10 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('LOCATIVE', 'Sivan'),
141				11 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('LOCATIVE', 'Tamuz'),
142				12 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('LOCATIVE', 'Av'),
143				13 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('LOCATIVE', 'Elul'),
144			);
145		}
146
147		if ($month_number === 7 && $leap_year) {
148			return $translated_month_names[-7];
149		} else {
150			return $translated_month_names[$month_number];
151		}
152	}
153
154	/** {@inheritdoc} */
155	protected function monthNameInstrumentalCase($month_number, $leap_year) {
156		static $translated_month_names;
157
158		if ($translated_month_names === null) {
159			$translated_month_names = array(
160				0  => '',
161				1  => /* I18N: a month in the Jewish calendar */ I18N::translateContext('INSTRUMENTAL', 'Tishrei'),
162				2  => /* I18N: a month in the Jewish calendar */ I18N::translateContext('INSTRUMENTAL', 'Heshvan'),
163				3  => /* I18N: a month in the Jewish calendar */ I18N::translateContext('INSTRUMENTAL', 'Kislev'),
164				4  => /* I18N: a month in the Jewish calendar */ I18N::translateContext('INSTRUMENTAL', 'Tevet'),
165				5  => /* I18N: a month in the Jewish calendar */ I18N::translateContext('INSTRUMENTAL', 'Shevat'),
166				6  => /* I18N: a month in the Jewish calendar */ I18N::translateContext('INSTRUMENTAL', 'Adar I'),
167				7  => /* I18N: a month in the Jewish calendar */ I18N::translateContext('INSTRUMENTAL', 'Adar'),
168				-7 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('INSTRUMENTAL', 'Adar II'),
169				8  => /* I18N: a month in the Jewish calendar */ I18N::translateContext('INSTRUMENTAL', 'Nissan'),
170				9  => /* I18N: a month in the Jewish calendar */ I18N::translateContext('INSTRUMENTAL', 'Iyar'),
171				10 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('INSTRUMENTAL', 'Sivan'),
172				11 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('INSTRUMENTAL', 'Tamuz'),
173				12 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('INSTRUMENTAL', 'Av'),
174				13 => /* I18N: a month in the Jewish calendar */ I18N::translateContext('INSTRUMENTAL', 'Elul'),
175			);
176		}
177
178		if ($month_number === 7 && $leap_year) {
179			return $translated_month_names[-7];
180		} else {
181			return $translated_month_names[$month_number];
182		}
183	}
184
185	/** {@inheritdoc} */
186	protected function monthNameAbbreviated($month_number, $leap_year) {
187		return self::monthNameNominativeCase($month_number, $leap_year);
188	}
189
190	/** {@inheritdoc} */
191	protected function nextMonth() {
192		if ($this->m == 6 && !$this->isLeapYear()) {
193			return array($this->y, 8);
194		} else {
195			return array($this->y + ($this->m == 13 ? 1 : 0), ($this->m % 13) + 1);
196		}
197	}
198}
199