Completed
Branch master (81e1f5)
by Pierre-Henry
35:31
created

CDateTime::__destruct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 21 and the first side effect is on line 15.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * @title            CDateTime Class
4
 * @desc             Some useful methods of dates, formatting managements of time relative to the language.
5
 *
6
 * @author           Pierre-Henry Soria <[email protected]>
7
 * @copyright        (c) 2012-2017, Pierre-Henry Soria. All Rights Reserved.
8
 * @license          GNU General Public License; See PH7.LICENSE.txt and PH7.COPYRIGHT.txt in the root directory.
9
 * @package          PH7 / Framework / Date
10
 * @version          1.2
11
 */
12
13
namespace PH7\Framework\Date;
14
15
defined('PH7') or exit('Restricted access');
16
17
use PH7\Framework\Config\Config;
18
use DateTime;
19
use DateTimeZone;
20
21
class CDateTime
22
{
23
    /** @var Config */
24
    private $_oConfig;
25
26
    /** @var DateTime */
27
    private $_oDateTime;
28
29
    public function __construct()
30
    {
31
        $this->_oConfig = Config::getInstance();
32
    }
33
34
    /**
35
     * Get, initialization method.
36
     *
37
     * @param string|integer $mTime If specified, you must enter a date/timestamp, otherwise it's the current time.
38
     *
39
     * @return CDateTime
40
     */
41
    public function get($mTime = null)
42
    {
43
        $sSetTime = (!empty($mTime)) ? date('Y-m-d H:i:s', (!is_numeric($mTime) ? strtotime($mTime) : $mTime) ) : 'now';
44
        $this->_oDateTime = new DateTime($sSetTime, new DateTimeZone($this->_oConfig->values['language.application']['timezone']));
45
46
        return $this;
47
    }
48
49
    /**
50
     * Get Date Time.
51
     *
52
     * @param string $sFormat
53
     *
54
     * @return string Date time format
55
     */
56
    public function dateTime($sFormat = null)
57
    {
58
        $sFormat = (empty($sFormat)) ? $this->_oConfig->values['language.application']['date_time_format'] : $sFormat;
59
60
        return $this->_oDateTime->format($sFormat);
61
    }
62
63
    /**
64
     * Get Date.
65
     *
66
     * @param string $sFormat
67
     *
68
     * @return string Date format
69
     */
70
    public function date($sFormat = null)
71
    {
72
        $sFormat = (empty($sFormat)) ? $this->_oConfig->values['language.application']['date_format'] : $sFormat;
73
74
        return $this->_oDateTime->format($sFormat);
75
    }
76
77
    /**
78
     * Get Time.
79
     *
80
     * @param string $sFormat
81
     *
82
     * @return string Time format
83
     */
84
    public function time($sFormat = null)
85
    {
86
        $sFormat = (empty($sFormat)) ? $this->_oConfig->values['language.application']['time_format'] : $sFormat;
87
88
        return $this->_oDateTime->format($sFormat);
89
    }
90
}
91