xref: /webtrees/app/Statistics/Service/CenturyService.php (revision 4fbeb707df82fa5025e6110f443695700edd846c)
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\Statistics\Service;
19
20use Fisharebest\Webtrees\I18N;
21
22/**
23 * Functions for managing centuries.
24 */
25class CenturyService
26{
27    /**
28     * Century name, English => 21st, Polish => XXI, etc.
29     *
30     * @param int $century
31     *
32     * @return string
33     */
34    public function centuryName(int $century): string
35    {
36        if ($century < 0) {
37            return I18N::translate('%s BCE', $this->centuryName(-$century));
38        }
39
40        // The current chart engine (Google charts) can't handle <sup></sup> markup
41        switch ($century) {
42            case 21:
43                return strip_tags(I18N::translateContext('CENTURY', '21st'));
44            case 20:
45                return strip_tags(I18N::translateContext('CENTURY', '20th'));
46            case 19:
47                return strip_tags(I18N::translateContext('CENTURY', '19th'));
48            case 18:
49                return strip_tags(I18N::translateContext('CENTURY', '18th'));
50            case 17:
51                return strip_tags(I18N::translateContext('CENTURY', '17th'));
52            case 16:
53                return strip_tags(I18N::translateContext('CENTURY', '16th'));
54            case 15:
55                return strip_tags(I18N::translateContext('CENTURY', '15th'));
56            case 14:
57                return strip_tags(I18N::translateContext('CENTURY', '14th'));
58            case 13:
59                return strip_tags(I18N::translateContext('CENTURY', '13th'));
60            case 12:
61                return strip_tags(I18N::translateContext('CENTURY', '12th'));
62            case 11:
63                return strip_tags(I18N::translateContext('CENTURY', '11th'));
64            case 10:
65                return strip_tags(I18N::translateContext('CENTURY', '10th'));
66            case 9:
67                return strip_tags(I18N::translateContext('CENTURY', '9th'));
68            case 8:
69                return strip_tags(I18N::translateContext('CENTURY', '8th'));
70            case 7:
71                return strip_tags(I18N::translateContext('CENTURY', '7th'));
72            case 6:
73                return strip_tags(I18N::translateContext('CENTURY', '6th'));
74            case 5:
75                return strip_tags(I18N::translateContext('CENTURY', '5th'));
76            case 4:
77                return strip_tags(I18N::translateContext('CENTURY', '4th'));
78            case 3:
79                return strip_tags(I18N::translateContext('CENTURY', '3rd'));
80            case 2:
81                return strip_tags(I18N::translateContext('CENTURY', '2nd'));
82            case 1:
83                return strip_tags(I18N::translateContext('CENTURY', '1st'));
84            default:
85                return ($century - 1) . '01-' . $century . '00';
86        }
87    }
88}
89