xref: /webtrees/app/Date/FrenchDate.php (revision bfaf8159bfb7825b9a3af52cb2a71378e3117bec)
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 */
16namespace Fisharebest\Webtrees\Date;
17
18use Fisharebest\ExtCalendar\FrenchCalendar;
19use Fisharebest\Webtrees\I18N;
20
21/**
22 * Definitions for the French Republican calendar
23 */
24class FrenchDate extends CalendarDate
25{
26    /** @var int[] Convert GEDCOM month names to month numbers */
27    public static $MONTH_ABBREV = [
28        ''     => 0,
29        'VEND' => 1,
30        'BRUM' => 2,
31        'FRIM' => 3,
32        'NIVO' => 4,
33        'PLUV' => 5,
34        'VENT' => 6,
35        'GERM' => 7,
36        'FLOR' => 8,
37        'PRAI' => 9,
38        'MESS' => 10,
39        'THER' => 11,
40        'FRUC' => 12,
41        'COMP' => 13,
42    ];
43
44    /**
45     * Create a date from either:
46     * a Julian day number
47     * day/month/year strings from a GEDCOM date
48     * another CalendarDate object
49     *
50     * @param array|int|CalendarDate $date
51     */
52    public function __construct($date)
53    {
54        $this->calendar = new FrenchCalendar;
55        parent::__construct($date);
56    }
57
58    /**
59     * Full month name in nominative case.
60     *
61     * @param int  $month_number
62     * @param bool $leap_year Some calendars use leap months
63     *
64     * @return string
65     */
66    public static function monthNameNominativeCase($month_number, $leap_year)
67    {
68        static $translated_month_names;
69
70        if ($translated_month_names === null) {
71            $translated_month_names = [
72                0  => '',
73                1  => /* I18N: a month in the French republican calendar */
74                    I18N::translateContext('NOMINATIVE', 'Vendemiaire'),
75                2  => /* I18N: a month in the French republican calendar */
76                    I18N::translateContext('NOMINATIVE', 'Brumaire'),
77                3  => /* I18N: a month in the French republican calendar */
78                    I18N::translateContext('NOMINATIVE', 'Frimaire'),
79                4  => /* I18N: a month in the French republican calendar */
80                    I18N::translateContext('NOMINATIVE', 'Nivose'),
81                5  => /* I18N: a month in the French republican calendar */
82                    I18N::translateContext('NOMINATIVE', 'Pluviose'),
83                6  => /* I18N: a month in the French republican calendar */
84                    I18N::translateContext('NOMINATIVE', 'Ventose'),
85                7  => /* I18N: a month in the French republican calendar */
86                    I18N::translateContext('NOMINATIVE', 'Germinal'),
87                8  => /* I18N: a month in the French republican calendar */
88                    I18N::translateContext('NOMINATIVE', 'Floreal'),
89                9  => /* I18N: a month in the French republican calendar */
90                    I18N::translateContext('NOMINATIVE', 'Prairial'),
91                10 => /* I18N: a month in the French republican calendar */
92                    I18N::translateContext('NOMINATIVE', 'Messidor'),
93                11 => /* I18N: a month in the French republican calendar */
94                    I18N::translateContext('NOMINATIVE', 'Thermidor'),
95                12 => /* I18N: a month in the French republican calendar */
96                    I18N::translateContext('NOMINATIVE', 'Fructidor'),
97                13 => /* I18N: a month in the French republican calendar */
98                    I18N::translateContext('NOMINATIVE', 'jours complementaires'),
99            ];
100        }
101
102        return $translated_month_names[$month_number];
103    }
104
105    /**
106     * Full month name in genitive case.
107     *
108     * @param int  $month_number
109     * @param bool $leap_year Some calendars use leap months
110     *
111     * @return string
112     */
113    protected function monthNameGenitiveCase($month_number, $leap_year)
114    {
115        static $translated_month_names;
116
117        if ($translated_month_names === null) {
118            $translated_month_names = [
119                0  => '',
120                1  => /* I18N: a month in the French republican calendar */
121                    I18N::translateContext('GENITIVE', 'Vendemiaire'),
122                2  => /* I18N: a month in the French republican calendar */
123                    I18N::translateContext('GENITIVE', 'Brumaire'),
124                3  => /* I18N: a month in the French republican calendar */
125                    I18N::translateContext('GENITIVE', 'Frimaire'),
126                4  => /* I18N: a month in the French republican calendar */
127                    I18N::translateContext('GENITIVE', 'Nivose'),
128                5  => /* I18N: a month in the French republican calendar */
129                    I18N::translateContext('GENITIVE', 'Pluviose'),
130                6  => /* I18N: a month in the French republican calendar */
131                    I18N::translateContext('GENITIVE', 'Ventose'),
132                7  => /* I18N: a month in the French republican calendar */
133                    I18N::translateContext('GENITIVE', 'Germinal'),
134                8  => /* I18N: a month in the French republican calendar */
135                    I18N::translateContext('GENITIVE', 'Floreal'),
136                9  => /* I18N: a month in the French republican calendar */
137                    I18N::translateContext('GENITIVE', 'Prairial'),
138                10 => /* I18N: a month in the French republican calendar */
139                    I18N::translateContext('GENITIVE', 'Messidor'),
140                11 => /* I18N: a month in the French republican calendar */
141                    I18N::translateContext('GENITIVE', 'Thermidor'),
142                12 => /* I18N: a month in the French republican calendar */
143                    I18N::translateContext('GENITIVE', 'Fructidor'),
144                13 => /* I18N: a month in the French republican calendar */
145                    I18N::translateContext('GENITIVE', 'jours complementaires'),
146            ];
147        }
148
149        return $translated_month_names[$month_number];
150    }
151
152    /**
153     * Full month name in locative case.
154     *
155     * @param int  $month_number
156     * @param bool $leap_year Some calendars use leap months
157     *
158     * @return string
159     */
160    protected function monthNameLocativeCase($month_number, $leap_year)
161    {
162        static $translated_month_names;
163
164        if ($translated_month_names === null) {
165            $translated_month_names = [
166                0  => '',
167                1  => /* I18N: a month in the French republican calendar */
168                    I18N::translateContext('LOCATIVE', 'Vendemiaire'),
169                2  => /* I18N: a month in the French republican calendar */
170                    I18N::translateContext('LOCATIVE', 'Brumaire'),
171                3  => /* I18N: a month in the French republican calendar */
172                    I18N::translateContext('LOCATIVE', 'Frimaire'),
173                4  => /* I18N: a month in the French republican calendar */
174                    I18N::translateContext('LOCATIVE', 'Nivose'),
175                5  => /* I18N: a month in the French republican calendar */
176                    I18N::translateContext('LOCATIVE', 'Pluviose'),
177                6  => /* I18N: a month in the French republican calendar */
178                    I18N::translateContext('LOCATIVE', 'Ventose'),
179                7  => /* I18N: a month in the French republican calendar */
180                    I18N::translateContext('LOCATIVE', 'Germinal'),
181                8  => /* I18N: a month in the French republican calendar */
182                    I18N::translateContext('LOCATIVE', 'Floreal'),
183                9  => /* I18N: a month in the French republican calendar */
184                    I18N::translateContext('LOCATIVE', 'Prairial'),
185                10 => /* I18N: a month in the French republican calendar */
186                    I18N::translateContext('LOCATIVE', 'Messidor'),
187                11 => /* I18N: a month in the French republican calendar */
188                    I18N::translateContext('LOCATIVE', 'Thermidor'),
189                12 => /* I18N: a month in the French republican calendar */
190                    I18N::translateContext('LOCATIVE', 'Fructidor'),
191                13 => /* I18N: a month in the French republican calendar */
192                    I18N::translateContext('LOCATIVE', 'jours complementaires'),
193            ];
194        }
195
196        return $translated_month_names[$month_number];
197    }
198
199    /**
200     * Full month name in instrumental case.
201     *
202     * @param int  $month_number
203     * @param bool $leap_year Some calendars use leap months
204     *
205     * @return string
206     */
207    protected function monthNameInstrumentalCase($month_number, $leap_year)
208    {
209        static $translated_month_names;
210
211        if ($translated_month_names === null) {
212            $translated_month_names = [
213                0  => '',
214                1  => /* I18N: a month in the French republican calendar */
215                    I18N::translateContext('INSTRUMENTAL', 'Vendemiaire'),
216                2  => /* I18N: a month in the French republican calendar */
217                    I18N::translateContext('INSTRUMENTAL', 'Brumaire'),
218                3  => /* I18N: a month in the French republican calendar */
219                    I18N::translateContext('INSTRUMENTAL', 'Frimaire'),
220                4  => /* I18N: a month in the French republican calendar */
221                    I18N::translateContext('INSTRUMENTAL', 'Nivose'),
222                5  => /* I18N: a month in the French republican calendar */
223                    I18N::translateContext('INSTRUMENTAL', 'Pluviose'),
224                6  => /* I18N: a month in the French republican calendar */
225                    I18N::translateContext('INSTRUMENTAL', 'Ventose'),
226                7  => /* I18N: a month in the French republican calendar */
227                    I18N::translateContext('INSTRUMENTAL', 'Germinal'),
228                8  => /* I18N: a month in the French republican calendar */
229                    I18N::translateContext('INSTRUMENTAL', 'Floreal'),
230                9  => /* I18N: a month in the French republican calendar */
231                    I18N::translateContext('INSTRUMENTAL', 'Prairial'),
232                10 => /* I18N: a month in the French republican calendar */
233                    I18N::translateContext('INSTRUMENTAL', 'Messidor'),
234                11 => /* I18N: a month in the French republican calendar */
235                    I18N::translateContext('INSTRUMENTAL', 'Thermidor'),
236                12 => /* I18N: a month in the French republican calendar */
237                    I18N::translateContext('INSTRUMENTAL', 'Fructidor'),
238                13 => /* I18N: a month in the French republican calendar */
239                    I18N::translateContext('INSTRUMENTAL', 'jours complementaires'),
240            ];
241        }
242
243        return $translated_month_names[$month_number];
244    }
245
246    /**
247     * Abbreviated month name
248     *
249     * @param int  $month_number
250     * @param bool $leap_year Some calendars use leap months
251     *
252     * @return string
253     */
254    protected function monthNameAbbreviated($month_number, $leap_year)
255    {
256        return self::monthNameNominativeCase($month_number, $leap_year);
257    }
258
259    /**
260     * Full day of th eweek
261     *
262     * @param int $day_number
263     *
264     * @return string
265     */
266    public function dayNames($day_number)
267    {
268        static $translated_day_names;
269
270        if ($translated_day_names === null) {
271            $translated_day_names = [
272                0 => /* I18N: The first day in the French republican calendar */
273                    I18N::translate('Primidi'),
274                1 => /* I18N: The second day in the French republican calendar */
275                    I18N::translate('Duodi'),
276                2 => /* I18N: The third day in the French republican calendar */
277                    I18N::translate('Tridi'),
278                3 => /* I18N: The fourth day in the French republican calendar */
279                    I18N::translate('Quartidi'),
280                4 => /* I18N: The fifth day in the French republican calendar */
281                    I18N::translate('Quintidi'),
282                5 => /* I18N: The sixth day in the French republican calendar */
283                    I18N::translate('Sextidi'),
284                6 => /* I18N: The seventh day in the French republican calendar */
285                    I18N::translate('Septidi'),
286                7 => /* I18N: The eighth day in the French republican calendar */
287                    I18N::translate('Octidi'),
288                8 => /* I18N: The ninth day in the French republican calendar */
289                    I18N::translate('Nonidi'),
290                9 => /* I18N: The tenth day in the French republican calendar */
291                    I18N::translate('Decidi'),
292            ];
293        }
294
295        return $translated_day_names[$day_number];
296    }
297
298    /**
299     * Abbreviated day of the week
300     *
301     * @param int $day_number
302     *
303     * @return string
304     */
305    protected function dayNamesAbbreviated($day_number)
306    {
307        return $this->dayNames($day_number);
308    }
309
310    /**
311     * Generate the %Y format for a date.
312     *
313     * @return string
314     */
315    protected function formatLongYear()
316    {
317        return $this->numberToRomanNumerals($this->y);
318    }
319}
320