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