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