xref: /webtrees/app/Date/AbstractGregorianJulianDate.php (revision 4a83f5d742e43c37a641392fe50a3db201bffb30)
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 */
16declare(strict_types=1);
17
18namespace Fisharebest\Webtrees\Date;
19
20use Fisharebest\ExtCalendar\CalendarInterface;
21use Fisharebest\ExtCalendar\JewishCalendar;
22use Fisharebest\Webtrees\DebugBar;
23use Fisharebest\Webtrees\I18N;
24
25/**
26 * Common definitions for Gregorian and Julian dates.
27 */
28abstract class AbstractGregorianJulianDate extends AbstractCalendarDate
29{
30    // Convert GEDCOM month names to month numbers
31    const MONTH_ABBREVIATIONS = [
32        ''    => 0,
33        'JAN' => 1,
34        'FEB' => 2,
35        'MAR' => 3,
36        'APR' => 4,
37        'MAY' => 5,
38        'JUN' => 6,
39        'JUL' => 7,
40        'AUG' => 8,
41        'SEP' => 9,
42        'OCT' => 10,
43        'NOV' => 11,
44        'DEC' => 12,
45    ];
46
47    /**
48     * Full month name in nominative case.
49     *
50     * We put these in the base class, to save duplicating it in the Julian and Gregorian calendars.
51     *
52     * @param int  $month_number
53     * @param bool $leap_year Some calendars use leap months
54     *
55     * @return string
56     */
57    protected function monthNameNominativeCase(int $month_number, bool $leap_year): string
58    {
59        static $translated_month_names;
60
61        if ($translated_month_names === null) {
62            $translated_month_names = [
63                0  => '',
64                1  => I18N::translateContext('NOMINATIVE', 'January'),
65                2  => I18N::translateContext('NOMINATIVE', 'February'),
66                3  => I18N::translateContext('NOMINATIVE', 'March'),
67                4  => I18N::translateContext('NOMINATIVE', 'April'),
68                5  => I18N::translateContext('NOMINATIVE', 'May'),
69                6  => I18N::translateContext('NOMINATIVE', 'June'),
70                7  => I18N::translateContext('NOMINATIVE', 'July'),
71                8  => I18N::translateContext('NOMINATIVE', 'August'),
72                9  => I18N::translateContext('NOMINATIVE', 'September'),
73                10 => I18N::translateContext('NOMINATIVE', 'October'),
74                11 => I18N::translateContext('NOMINATIVE', 'November'),
75                12 => I18N::translateContext('NOMINATIVE', 'December'),
76            ];
77        }
78
79        return $translated_month_names[$month_number];
80    }
81
82    /**
83     * Full month name in genitive case.
84     *
85     * We put these in the base class, to save duplicating it in the Julian and Gregorian calendars.
86     *
87     * @param int  $month_number
88     * @param bool $leap_year Some calendars use leap months
89     *
90     * @return string
91     */
92    protected function monthNameGenitiveCase(int $month_number, bool $leap_year): string
93    {
94        static $translated_month_names;
95
96        if ($translated_month_names === null) {
97            $translated_month_names = [
98                0  => '',
99                1  => I18N::translateContext('GENITIVE', 'January'),
100                2  => I18N::translateContext('GENITIVE', 'February'),
101                3  => I18N::translateContext('GENITIVE', 'March'),
102                4  => I18N::translateContext('GENITIVE', 'April'),
103                5  => I18N::translateContext('GENITIVE', 'May'),
104                6  => I18N::translateContext('GENITIVE', 'June'),
105                7  => I18N::translateContext('GENITIVE', 'July'),
106                8  => I18N::translateContext('GENITIVE', 'August'),
107                9  => I18N::translateContext('GENITIVE', 'September'),
108                10 => I18N::translateContext('GENITIVE', 'October'),
109                11 => I18N::translateContext('GENITIVE', 'November'),
110                12 => I18N::translateContext('GENITIVE', 'December'),
111            ];
112        }
113
114        return $translated_month_names[$month_number];
115    }
116
117    /**
118     * Full month name in locative case.
119     *
120     * We put these in the base class, to save duplicating it in the Julian and Gregorian calendars.
121     *
122     * @param int  $month_number
123     * @param bool $leap_year Some calendars use leap months
124     *
125     * @return string
126     */
127    protected function monthNameLocativeCase(int $month_number, bool $leap_year): string
128    {
129        static $translated_month_names;
130
131        if ($translated_month_names === null) {
132            $translated_month_names = [
133                0  => '',
134                1  => I18N::translateContext('LOCATIVE', 'January'),
135                2  => I18N::translateContext('LOCATIVE', 'February'),
136                3  => I18N::translateContext('LOCATIVE', 'March'),
137                4  => I18N::translateContext('LOCATIVE', 'April'),
138                5  => I18N::translateContext('LOCATIVE', 'May'),
139                6  => I18N::translateContext('LOCATIVE', 'June'),
140                7  => I18N::translateContext('LOCATIVE', 'July'),
141                8  => I18N::translateContext('LOCATIVE', 'August'),
142                9  => I18N::translateContext('LOCATIVE', 'September'),
143                10 => I18N::translateContext('LOCATIVE', 'October'),
144                11 => I18N::translateContext('LOCATIVE', 'November'),
145                12 => I18N::translateContext('LOCATIVE', 'December'),
146            ];
147        }
148
149        return $translated_month_names[$month_number];
150    }
151
152    /**
153     * Full month name in instrumental case.
154     *
155     * We put these in the base class, to save duplicating it in the Julian and Gregorian calendars.
156     *
157     * @param int  $month_number
158     * @param bool $leap_year Some calendars use leap months
159     *
160     * @return string
161     */
162    protected function monthNameInstrumentalCase(int $month_number, bool $leap_year): string
163    {
164        static $translated_month_names;
165
166        if ($translated_month_names === null) {
167            $translated_month_names = [
168                0  => '',
169                1  => I18N::translateContext('INSTRUMENTAL', 'January'),
170                2  => I18N::translateContext('INSTRUMENTAL', 'February'),
171                3  => I18N::translateContext('INSTRUMENTAL', 'March'),
172                4  => I18N::translateContext('INSTRUMENTAL', 'April'),
173                5  => I18N::translateContext('INSTRUMENTAL', 'May'),
174                6  => I18N::translateContext('INSTRUMENTAL', 'June'),
175                7  => I18N::translateContext('INSTRUMENTAL', 'July'),
176                8  => I18N::translateContext('INSTRUMENTAL', 'August'),
177                9  => I18N::translateContext('INSTRUMENTAL', 'September'),
178                10 => I18N::translateContext('INSTRUMENTAL', 'October'),
179                11 => I18N::translateContext('INSTRUMENTAL', 'November'),
180                12 => I18N::translateContext('INSTRUMENTAL', 'December'),
181            ];
182        }
183
184        return $translated_month_names[$month_number];
185    }
186
187    /**
188     * Abbreviated month name
189     *
190     * @param int  $month_number
191     * @param bool $leap_year Some calendars use leap months
192     *
193     * @return string
194     */
195    protected function monthNameAbbreviated(int $month_number, bool $leap_year): string
196    {
197        static $translated_month_names;
198
199        if ($translated_month_names === null) {
200            $translated_month_names = [
201                0  => '',
202                1  => I18N::translateContext('Abbreviation for January', 'Jan'),
203                2  => I18N::translateContext('Abbreviation for February', 'Feb'),
204                3  => I18N::translateContext('Abbreviation for March', 'Mar'),
205                4  => I18N::translateContext('Abbreviation for April', 'Apr'),
206                5  => I18N::translateContext('Abbreviation for May', 'May'),
207                6  => I18N::translateContext('Abbreviation for June', 'Jun'),
208                7  => I18N::translateContext('Abbreviation for July', 'Jul'),
209                8  => I18N::translateContext('Abbreviation for August', 'Aug'),
210                9  => I18N::translateContext('Abbreviation for September', 'Sep'),
211                10 => I18N::translateContext('Abbreviation for October', 'Oct'),
212                11 => I18N::translateContext('Abbreviation for November', 'Nov'),
213                12 => I18N::translateContext('Abbreviation for December', 'Dec'),
214            ];
215        }
216
217        return $translated_month_names[$month_number];
218    }
219}
220