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