xref: /webtrees/app/Statistics/Repository/ServerRepository.php (revision c5e5c1cea5f7d35d6fd56eb77c9a68e91d21befe)
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\Repository;
19
20use Carbon\Carbon;
21use Fisharebest\Webtrees\I18N;
22use Fisharebest\Webtrees\Site;
23use Fisharebest\Webtrees\Statistics\Repository\Interfaces\ServerRepositoryInterface;
24
25/**
26 * A repository providing methods for server related statistics.
27 */
28class ServerRepository implements ServerRepositoryInterface
29{
30    /**
31     * @inheritDoc
32     */
33    public function serverDate(): string
34    {
35        $format   = strtr(I18N::dateFormat(), ['%' => '']);
36        $timezone = Site::getPreference('TIMEZONE', 'UTC');
37
38        return I18N::localTime(Carbon::now(), $format, $timezone);
39    }
40
41    /**
42     * @inheritDoc
43     */
44    public function serverTime(): string
45    {
46        $format   = strtr(I18N::timeFormat(), ['%' => '']);
47        $timezone = Site::getPreference('TIMEZONE', 'UTC');
48
49        return I18N::localTime(Carbon::now(), $format, $timezone);
50    }
51
52    /**
53     * @inheritDoc
54     */
55    public function serverTime24(): string
56    {
57        $timezone = Site::getPreference('TIMEZONE', 'UTC');
58
59        return I18N::localTime(Carbon::now(), 'G:i', $timezone);
60    }
61
62    /**
63     * @inheritDoc
64     */
65    public function serverTimezone(): string
66    {
67        $timezone = Site::getPreference('TIMEZONE', 'UTC');
68
69        return I18N::localTime(Carbon::now(), 'T', $timezone);
70    }
71}
72