Completed
Push — master ( b35b0f...acc097 )
by Greg
05:21
created

Time::timeBasicMinusDays()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * /classes/DomainMOD/Time.php
4
 *
5
 * This file is part of DomainMOD, an open source domain and internet asset manager.
6
 * Copyright (c) 2010-2017 Greg Chetcuti <[email protected]>
7
 *
8
 * Project: http://domainmod.org   Author: http://chetcuti.com
9
 *
10
 * DomainMOD is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
11
 * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
12
 * version.
13
 *
14
 * DomainMOD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
15
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License along with DomainMOD. If not, see
18
 * http://www.gnu.org/licenses/.
19
 *
20
 */
21
//@formatter:off
22
namespace DomainMOD;
23
24
class Time
25
{
26
27
    public function stamp()
28
    {
29
        return gmdate('Y-m-d H:i:s', mktime(date("H"), date("i"), date("s"), date("m"), date("d"), date("Y")));
30
    }
31
32
    public function timeLong()
33
    {
34
        return gmdate('l, F jS', mktime(date("H"), date("i"), date("s"), date("m"), date("d"), date("Y")));
35
    }
36
37
    public function timeBasic()
38
    {
39
        return gmdate("Y-m-d", mktime(date("H"), date("i"), date("s"), date("m"), date("d"), date("Y")));
40
    }
41
42
    public function timeBasicMinusDays($days)
43
    {
44
        return gmdate("Y-m-d", mktime(date("H"), date("i"), date("s"), date("m"), date("d") - $days, date("Y")));
45
    }
46
47
    public function timeBasicPlusDays($days)
48
    {
49
        return gmdate("Y-m-d", mktime(date("H"), date("i"), date("s"), date("m"), date("d") + $days, date("Y")));
50
    }
51
52
    public function timeBasicPlusYears($years)
53
    {
54
        return gmdate("Y-m-d", mktime(date("H"), date("i"), date("s"), date("m"), date("d"), date("Y") + $years));
55
    }
56
57
    public function toUserTimezone($input_time, $format = 'Y-m-d H:i:s')
58
    {
59
        $date = new \DateTime($input_time, new \DateTimeZone('UTC'));
60
        $date->setTimezone(new \DateTimeZone($_SESSION['s_default_timezone']));
61
        return $date->format($format);
62
    }
63
64
    public function toUtcTimezone($input_time, $format = 'Y-m-d H:i:s')
65
    {
66
        $date = new \DateTime($input_time, new \DateTimeZone($_SESSION['s_default_timezone']));
67
        $date->setTimezone(new \DateTimeZone('UTC'));
68
        return $date->format($format);
69
    }
70
71
} //@formatter:on
72