xref: /webtrees/app/Date/AbstractGregorianJulianDate.php (revision 315eb31683006273e24c08b447e6e1095d6f2147)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2021 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    /**
47     * Full month name in nominative case.
48     *
49     * We put these in the base class, to save duplicating it in the Julian and Gregorian calendars.
50     *
51     * @param int  $month
52     * @param bool $leap_year Some calendars use leap months
53     *
54     * @return string
55     */
56    protected function monthNameNominativeCase(int $month, bool $leap_year): string
57    {
58        static $translated_month_names;
59
60        if ($translated_month_names === null) {
61            $translated_month_names = [
62                0  => '',
63                1  => I18N::translateContext('NOMINATIVE', 'January'),
64                2  => I18N::translateContext('NOMINATIVE', 'February'),
65                3  => I18N::translateContext('NOMINATIVE', 'March'),
66                4  => I18N::translateContext('NOMINATIVE', 'April'),
67                5  => I18N::translateContext('NOMINATIVE', 'May'),
68                6  => I18N::translateContext('NOMINATIVE', 'June'),
69                7  => I18N::translateContext('NOMINATIVE', 'July'),
70                8  => I18N::translateContext('NOMINATIVE', 'August'),
71                9  => I18N::translateContext('NOMINATIVE', 'September'),
72                10 => I18N::translateContext('NOMINATIVE', 'October'),
73                11 => I18N::translateContext('NOMINATIVE', 'November'),
74                12 => I18N::translateContext('NOMINATIVE', 'December'),
75            ];
76        }
77
78        return $translated_month_names[$month];
79    }
80
81    /**
82     * Full month name in genitive case.
83     *
84     * We put these in the base class, to save duplicating it in the Julian and Gregorian calendars.
85     *
86     * @param int  $month
87     * @param bool $leap_year Some calendars use leap months
88     *
89     * @return string
90     */
91    protected function monthNameGenitiveCase(int $month, bool $leap_year): string
92    {
93        static $translated_month_names;
94
95        if ($translated_month_names === null) {
96            $translated_month_names = [
97                0  => '',
98                1  => I18N::translateContext('GENITIVE', 'January'),
99                2  => I18N::translateContext('GENITIVE', 'February'),
100                3  => I18N::translateContext('GENITIVE', 'March'),
101                4  => I18N::translateContext('GENITIVE', 'April'),
102                5  => I18N::translateContext('GENITIVE', 'May'),
103                6  => I18N::translateContext('GENITIVE', 'June'),
104                7  => I18N::translateContext('GENITIVE', 'July'),
105                8  => I18N::translateContext('GENITIVE', 'August'),
106                9  => I18N::translateContext('GENITIVE', 'September'),
107                10 => I18N::translateContext('GENITIVE', 'October'),
108                11 => I18N::translateContext('GENITIVE', 'November'),
109                12 => I18N::translateContext('GENITIVE', 'December'),
110            ];
111        }
112
113        return $translated_month_names[$month];
114    }
115
116    /**
117     * Full month name in locative case.
118     *
119     * We put these in the base class, to save duplicating it in the Julian and Gregorian calendars.
120     *
121     * @param int  $month
122     * @param bool $leap_year Some calendars use leap months
123     *
124     * @return string
125     */
126    protected function monthNameLocativeCase(int $month, bool $leap_year): string
127    {
128        static $translated_month_names;
129
130        if ($translated_month_names === null) {
131            $translated_month_names = [
132                0  => '',
133                1  => I18N::translateContext('LOCATIVE', 'January'),
134                2  => I18N::translateContext('LOCATIVE', 'February'),
135                3  => I18N::translateContext('LOCATIVE', 'March'),
136                4  => I18N::translateContext('LOCATIVE', 'April'),
137                5  => I18N::translateContext('LOCATIVE', 'May'),
138                6  => I18N::translateContext('LOCATIVE', 'June'),
139                7  => I18N::translateContext('LOCATIVE', 'July'),
140                8  => I18N::translateContext('LOCATIVE', 'August'),
141                9  => I18N::translateContext('LOCATIVE', 'September'),
142                10 => I18N::translateContext('LOCATIVE', 'October'),
143                11 => I18N::translateContext('LOCATIVE', 'November'),
144                12 => I18N::translateContext('LOCATIVE', 'December'),
145            ];
146        }
147
148        return $translated_month_names[$month];
149    }
150
151    /**
152     * Full month name in instrumental case.
153     *
154     * We put these in the base class, to save duplicating it in the Julian and Gregorian calendars.
155     *
156     * @param int  $month
157     * @param bool $leap_year Some calendars use leap months
158     *
159     * @return string
160     */
161    protected function monthNameInstrumentalCase(int $month, bool $leap_year): string
162    {
163        static $translated_month_names;
164
165        if ($translated_month_names === null) {
166            $translated_month_names = [
167                0  => '',
168                1  => I18N::translateContext('INSTRUMENTAL', 'January'),
169                2  => I18N::translateContext('INSTRUMENTAL', 'February'),
170                3  => I18N::translateContext('INSTRUMENTAL', 'March'),
171                4  => I18N::translateContext('INSTRUMENTAL', 'April'),
172                5  => I18N::translateContext('INSTRUMENTAL', 'May'),
173                6  => I18N::translateContext('INSTRUMENTAL', 'June'),
174                7  => I18N::translateContext('INSTRUMENTAL', 'July'),
175                8  => I18N::translateContext('INSTRUMENTAL', 'August'),
176                9  => I18N::translateContext('INSTRUMENTAL', 'September'),
177                10 => I18N::translateContext('INSTRUMENTAL', 'October'),
178                11 => I18N::translateContext('INSTRUMENTAL', 'November'),
179                12 => I18N::translateContext('INSTRUMENTAL', 'December'),
180            ];
181        }
182
183        return $translated_month_names[$month];
184    }
185
186    /**
187     * Abbreviated month name
188     *
189     * @param int  $month
190     * @param bool $leap_year Some calendars use leap months
191     *
192     * @return string
193     */
194    protected function monthNameAbbreviated(int $month, bool $leap_year): string
195    {
196        static $translated_month_names;
197
198        if ($translated_month_names === null) {
199            $translated_month_names = [
200                0  => '',
201                1  => I18N::translateContext('Abbreviation for January', 'Jan'),
202                2  => I18N::translateContext('Abbreviation for February', 'Feb'),
203                3  => I18N::translateContext('Abbreviation for March', 'Mar'),
204                4  => I18N::translateContext('Abbreviation for April', 'Apr'),
205                5  => I18N::translateContext('Abbreviation for May', 'May'),
206                6  => I18N::translateContext('Abbreviation for June', 'Jun'),
207                7  => I18N::translateContext('Abbreviation for July', 'Jul'),
208                8  => I18N::translateContext('Abbreviation for August', 'Aug'),
209                9  => I18N::translateContext('Abbreviation for September', 'Sep'),
210                10 => I18N::translateContext('Abbreviation for October', 'Oct'),
211                11 => I18N::translateContext('Abbreviation for November', 'Nov'),
212                12 => I18N::translateContext('Abbreviation for December', 'Dec'),
213            ];
214        }
215
216        return $translated_month_names[$month];
217    }
218}
219