summaryrefslogtreecommitdiff
path: root/app/Date/AbstractGregorianJulianDate.php
blob: 00615a82943d3dad4f23707a0706e6fe9b9f70ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
<?php

/**
 * webtrees: online genealogy
 * Copyright (C) 2023 webtrees development team
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
 */

declare(strict_types=1);

namespace Fisharebest\Webtrees\Date;

use Fisharebest\Webtrees\I18N;

/**
 * Common definitions for Gregorian and Julian dates.
 */
abstract class AbstractGregorianJulianDate extends AbstractCalendarDate
{
    // Convert GEDCOM month names to month numbers
    protected const array MONTH_ABBREVIATIONS = [
        ''    => 0,
        'JAN' => 1,
        'FEB' => 2,
        'MAR' => 3,
        'APR' => 4,
        'MAY' => 5,
        'JUN' => 6,
        'JUL' => 7,
        'AUG' => 8,
        'SEP' => 9,
        'OCT' => 10,
        'NOV' => 11,
        'DEC' => 12,
    ];

    protected const array MONTH_TO_NUMBER = [
        'JAN' => 1,
        'FEB' => 2,
        'MAR' => 3,
        'APR' => 4,
        'MAY' => 5,
        'JUN' => 6,
        'JUL' => 7,
        'AUG' => 8,
        'SEP' => 9,
        'OCT' => 10,
        'NOV' => 11,
        'DEC' => 12,
    ];

    protected const array NUMBER_TO_MONTH = [
        1  => 'JAN',
        2  => 'FEB',
        3  => 'MAR',
        4  => 'APR',
        5  => 'MAY',
        6  => 'JUN',
        7  => 'JUL',
        8  => 'AUG',
        9  => 'SEP',
        10 => 'OCT',
        11 => 'NOV',
        12 => 'DEC',
    ];

    /**
     * Full month name in nominative case.
     *
     * We put these in the base class, to save duplicating it in the Julian and Gregorian calendars.
     *
     * @param int  $month
     * @param bool $leap_year Some calendars use leap months
     *
     * @return string
     */
    protected function monthNameNominativeCase(int $month, bool $leap_year): string
    {
        static $translated_month_names;

        if ($translated_month_names === null) {
            $translated_month_names = [
                0  => '',
                1  => I18N::translateContext('NOMINATIVE', 'January'),
                2  => I18N::translateContext('NOMINATIVE', 'February'),
                3  => I18N::translateContext('NOMINATIVE', 'March'),
                4  => I18N::translateContext('NOMINATIVE', 'April'),
                5  => I18N::translateContext('NOMINATIVE', 'May'),
                6  => I18N::translateContext('NOMINATIVE', 'June'),
                7  => I18N::translateContext('NOMINATIVE', 'July'),
                8  => I18N::translateContext('NOMINATIVE', 'August'),
                9  => I18N::translateContext('NOMINATIVE', 'September'),
                10 => I18N::translateContext('NOMINATIVE', 'October'),
                11 => I18N::translateContext('NOMINATIVE', 'November'),
                12 => I18N::translateContext('NOMINATIVE', 'December'),
            ];
        }

        return $translated_month_names[$month];
    }

    /**
     * Full month name in genitive case.
     *
     * We put these in the base class, to save duplicating it in the Julian and Gregorian calendars.
     *
     * @param int  $month
     * @param bool $leap_year Some calendars use leap months
     *
     * @return string
     */
    protected function monthNameGenitiveCase(int $month, bool $leap_year): string
    {
        static $translated_month_names;

        if ($translated_month_names === null) {
            $translated_month_names = [
                0  => '',
                1  => I18N::translateContext('GENITIVE', 'January'),
                2  => I18N::translateContext('GENITIVE', 'February'),
                3  => I18N::translateContext('GENITIVE', 'March'),
                4  => I18N::translateContext('GENITIVE', 'April'),
                5  => I18N::translateContext('GENITIVE', 'May'),
                6  => I18N::translateContext('GENITIVE', 'June'),
                7  => I18N::translateContext('GENITIVE', 'July'),
                8  => I18N::translateContext('GENITIVE', 'August'),
                9  => I18N::translateContext('GENITIVE', 'September'),
                10 => I18N::translateContext('GENITIVE', 'October'),
                11 => I18N::translateContext('GENITIVE', 'November'),
                12 => I18N::translateContext('GENITIVE', 'December'),
            ];
        }

        return $translated_month_names[$month];
    }

    /**
     * Full month name in locative case.
     *
     * We put these in the base class, to save duplicating it in the Julian and Gregorian calendars.
     *
     * @param int  $month
     * @param bool $leap_year Some calendars use leap months
     *
     * @return string
     */
    protected function monthNameLocativeCase(int $month, bool $leap_year): string
    {
        static $translated_month_names;

        if ($translated_month_names === null) {
            $translated_month_names = [
                0  => '',
                1  => I18N::translateContext('LOCATIVE', 'January'),
                2  => I18N::translateContext('LOCATIVE', 'February'),
                3  => I18N::translateContext('LOCATIVE', 'March'),
                4  => I18N::translateContext('LOCATIVE', 'April'),
                5  => I18N::translateContext('LOCATIVE', 'May'),
                6  => I18N::translateContext('LOCATIVE', 'June'),
                7  => I18N::translateContext('LOCATIVE', 'July'),
                8  => I18N::translateContext('LOCATIVE', 'August'),
                9  => I18N::translateContext('LOCATIVE', 'September'),
                10 => I18N::translateContext('LOCATIVE', 'October'),
                11 => I18N::translateContext('LOCATIVE', 'November'),
                12 => I18N::translateContext('LOCATIVE', 'December'),
            ];
        }

        return $translated_month_names[$month];
    }

    /**
     * Full month name in instrumental case.
     *
     * We put these in the base class, to save duplicating it in the Julian and Gregorian calendars.
     *
     * @param int  $month
     * @param bool $leap_year Some calendars use leap months
     *
     * @return string
     */
    protected function monthNameInstrumentalCase(int $month, bool $leap_year): string
    {
        static $translated_month_names;

        if ($translated_month_names === null) {
            $translated_month_names = [
                0  => '',
                1  => I18N::translateContext('INSTRUMENTAL', 'January'),
                2  => I18N::translateContext('INSTRUMENTAL', 'February'),
                3  => I18N::translateContext('INSTRUMENTAL', 'March'),
                4  => I18N::translateContext('INSTRUMENTAL', 'April'),
                5  => I18N::translateContext('INSTRUMENTAL', 'May'),
                6  => I18N::translateContext('INSTRUMENTAL', 'June'),
                7  => I18N::translateContext('INSTRUMENTAL', 'July'),
                8  => I18N::translateContext('INSTRUMENTAL', 'August'),
                9  => I18N::translateContext('INSTRUMENTAL', 'September'),
                10 => I18N::translateContext('INSTRUMENTAL', 'October'),
                11 => I18N::translateContext('INSTRUMENTAL', 'November'),
                12 => I18N::translateContext('INSTRUMENTAL', 'December'),
            ];
        }

        return $translated_month_names[$month];
    }

    /**
     * Abbreviated month name
     *
     * @param int  $month
     * @param bool $leap_year Some calendars use leap months
     *
     * @return string
     */
    protected function monthNameAbbreviated(int $month, bool $leap_year): string
    {
        static $translated_month_names;

        if ($translated_month_names === null) {
            $translated_month_names = [
                0  => '',
                1  => I18N::translateContext('Abbreviation for January', 'Jan'),
                2  => I18N::translateContext('Abbreviation for February', 'Feb'),
                3  => I18N::translateContext('Abbreviation for March', 'Mar'),
                4  => I18N::translateContext('Abbreviation for April', 'Apr'),
                5  => I18N::translateContext('Abbreviation for May', 'May'),
                6  => I18N::translateContext('Abbreviation for June', 'Jun'),
                7  => I18N::translateContext('Abbreviation for July', 'Jul'),
                8  => I18N::translateContext('Abbreviation for August', 'Aug'),
                9  => I18N::translateContext('Abbreviation for September', 'Sep'),
                10 => I18N::translateContext('Abbreviation for October', 'Oct'),
                11 => I18N::translateContext('Abbreviation for November', 'Nov'),
                12 => I18N::translateContext('Abbreviation for December', 'Dec'),
            ];
        }

        return $translated_month_names[$month];
    }
}