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