xref: /webtrees/app/Date/AbstractGregorianJulianDate.php (revision 8d018ab2fe3b6881cab8124d97e1a69e0be79d32)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2023 webtrees development team
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18declare(strict_types=1);
19
20namespace Fisharebest\Webtrees\Date;
21
22use Fisharebest\Webtrees\I18N;
23
24/**
25 * Common definitions for Gregorian and Julian dates.
26 */
27abstract class AbstractGregorianJulianDate extends AbstractCalendarDate
28{
29    // Convert GEDCOM month names to month numbers
30    protected const MONTH_ABBREVIATIONS = [
31        ''    => 0,
32        'JAN' => 1,
33        'FEB' => 2,
34        'MAR' => 3,
35        'APR' => 4,
36        'MAY' => 5,
37        'JUN' => 6,
38        'JUL' => 7,
39        'AUG' => 8,
40        'SEP' => 9,
41        'OCT' => 10,
42        'NOV' => 11,
43        'DEC' => 12,
44    ];
45
46    protected const MONTH_TO_NUMBER = [
47        'JAN' => 1,
48        'FEB' => 2,
49        'MAR' => 3,
50        'APR' => 4,
51        'MAY' => 5,
52        'JUN' => 6,
53        'JUL' => 7,
54        'AUG' => 8,
55        'SEP' => 9,
56        'OCT' => 10,
57        'NOV' => 11,
58        'DEC' => 12,
59    ];
60
61    protected const NUMBER_TO_MONTH = [
62        1  => 'JAN',
63        2  => 'FEB',
64        3  => 'MAR',
65        4  => 'APR',
66        5  => 'MAY',
67        6  => 'JUN',
68        7  => 'JUL',
69        8  => 'AUG',
70        9  => 'SEP',
71        10 => 'OCT',
72        11 => 'NOV',
73        12 => 'DEC',
74    ];
75
76    /**
77     * Full month name in nominative case.
78     *
79     * We put these in the base class, to save duplicating it in the Julian and Gregorian calendars.
80     *
81     * @param int  $month
82     * @param bool $leap_year Some calendars use leap months
83     *
84     * @return string
85     */
86    protected function monthNameNominativeCase(int $month, bool $leap_year): string
87    {
88        static $translated_month_names;
89
90        if ($translated_month_names === null) {
91            $translated_month_names = [
92                0  => '',
93                1  => I18N::translateContext('NOMINATIVE', 'January'),
94                2  => I18N::translateContext('NOMINATIVE', 'February'),
95                3  => I18N::translateContext('NOMINATIVE', 'March'),
96                4  => I18N::translateContext('NOMINATIVE', 'April'),
97                5  => I18N::translateContext('NOMINATIVE', 'May'),
98                6  => I18N::translateContext('NOMINATIVE', 'June'),
99                7  => I18N::translateContext('NOMINATIVE', 'July'),
100                8  => I18N::translateContext('NOMINATIVE', 'August'),
101                9  => I18N::translateContext('NOMINATIVE', 'September'),
102                10 => I18N::translateContext('NOMINATIVE', 'October'),
103                11 => I18N::translateContext('NOMINATIVE', 'November'),
104                12 => I18N::translateContext('NOMINATIVE', 'December'),
105            ];
106        }
107
108        return $translated_month_names[$month];
109    }
110
111    /**
112     * Full month name in genitive case.
113     *
114     * We put these in the base class, to save duplicating it in the Julian and Gregorian calendars.
115     *
116     * @param int  $month
117     * @param bool $leap_year Some calendars use leap months
118     *
119     * @return string
120     */
121    protected function monthNameGenitiveCase(int $month, bool $leap_year): string
122    {
123        static $translated_month_names;
124
125        if ($translated_month_names === null) {
126            $translated_month_names = [
127                0  => '',
128                1  => I18N::translateContext('GENITIVE', 'January'),
129                2  => I18N::translateContext('GENITIVE', 'February'),
130                3  => I18N::translateContext('GENITIVE', 'March'),
131                4  => I18N::translateContext('GENITIVE', 'April'),
132                5  => I18N::translateContext('GENITIVE', 'May'),
133                6  => I18N::translateContext('GENITIVE', 'June'),
134                7  => I18N::translateContext('GENITIVE', 'July'),
135                8  => I18N::translateContext('GENITIVE', 'August'),
136                9  => I18N::translateContext('GENITIVE', 'September'),
137                10 => I18N::translateContext('GENITIVE', 'October'),
138                11 => I18N::translateContext('GENITIVE', 'November'),
139                12 => I18N::translateContext('GENITIVE', 'December'),
140            ];
141        }
142
143        return $translated_month_names[$month];
144    }
145
146    /**
147     * Full month name in locative case.
148     *
149     * We put these in the base class, to save duplicating it in the Julian and Gregorian calendars.
150     *
151     * @param int  $month
152     * @param bool $leap_year Some calendars use leap months
153     *
154     * @return string
155     */
156    protected function monthNameLocativeCase(int $month, bool $leap_year): string
157    {
158        static $translated_month_names;
159
160        if ($translated_month_names === null) {
161            $translated_month_names = [
162                0  => '',
163                1  => I18N::translateContext('LOCATIVE', 'January'),
164                2  => I18N::translateContext('LOCATIVE', 'February'),
165                3  => I18N::translateContext('LOCATIVE', 'March'),
166                4  => I18N::translateContext('LOCATIVE', 'April'),
167                5  => I18N::translateContext('LOCATIVE', 'May'),
168                6  => I18N::translateContext('LOCATIVE', 'June'),
169                7  => I18N::translateContext('LOCATIVE', 'July'),
170                8  => I18N::translateContext('LOCATIVE', 'August'),
171                9  => I18N::translateContext('LOCATIVE', 'September'),
172                10 => I18N::translateContext('LOCATIVE', 'October'),
173                11 => I18N::translateContext('LOCATIVE', 'November'),
174                12 => I18N::translateContext('LOCATIVE', 'December'),
175            ];
176        }
177
178        return $translated_month_names[$month];
179    }
180
181    /**
182     * Full month name in instrumental case.
183     *
184     * We put these in the base class, to save duplicating it in the Julian and Gregorian calendars.
185     *
186     * @param int  $month
187     * @param bool $leap_year Some calendars use leap months
188     *
189     * @return string
190     */
191    protected function monthNameInstrumentalCase(int $month, bool $leap_year): string
192    {
193        static $translated_month_names;
194
195        if ($translated_month_names === null) {
196            $translated_month_names = [
197                0  => '',
198                1  => I18N::translateContext('INSTRUMENTAL', 'January'),
199                2  => I18N::translateContext('INSTRUMENTAL', 'February'),
200                3  => I18N::translateContext('INSTRUMENTAL', 'March'),
201                4  => I18N::translateContext('INSTRUMENTAL', 'April'),
202                5  => I18N::translateContext('INSTRUMENTAL', 'May'),
203                6  => I18N::translateContext('INSTRUMENTAL', 'June'),
204                7  => I18N::translateContext('INSTRUMENTAL', 'July'),
205                8  => I18N::translateContext('INSTRUMENTAL', 'August'),
206                9  => I18N::translateContext('INSTRUMENTAL', 'September'),
207                10 => I18N::translateContext('INSTRUMENTAL', 'October'),
208                11 => I18N::translateContext('INSTRUMENTAL', 'November'),
209                12 => I18N::translateContext('INSTRUMENTAL', 'December'),
210            ];
211        }
212
213        return $translated_month_names[$month];
214    }
215
216    /**
217     * Abbreviated month name
218     *
219     * @param int  $month
220     * @param bool $leap_year Some calendars use leap months
221     *
222     * @return string
223     */
224    protected function monthNameAbbreviated(int $month, bool $leap_year): string
225    {
226        static $translated_month_names;
227
228        if ($translated_month_names === null) {
229            $translated_month_names = [
230                0  => '',
231                1  => I18N::translateContext('Abbreviation for January', 'Jan'),
232                2  => I18N::translateContext('Abbreviation for February', 'Feb'),
233                3  => I18N::translateContext('Abbreviation for March', 'Mar'),
234                4  => I18N::translateContext('Abbreviation for April', 'Apr'),
235                5  => I18N::translateContext('Abbreviation for May', 'May'),
236                6  => I18N::translateContext('Abbreviation for June', 'Jun'),
237                7  => I18N::translateContext('Abbreviation for July', 'Jul'),
238                8  => I18N::translateContext('Abbreviation for August', 'Aug'),
239                9  => I18N::translateContext('Abbreviation for September', 'Sep'),
240                10 => I18N::translateContext('Abbreviation for October', 'Oct'),
241                11 => I18N::translateContext('Abbreviation for November', 'Nov'),
242                12 => I18N::translateContext('Abbreviation for December', 'Dec'),
243            ];
244        }
245
246        return $translated_month_names[$month];
247    }
248}
249