DateTime::getMonth()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Andegna;
4
5
use DateTime as GregorianDateTime;
6
7
/**
8
 * Ethiopian Andegna DateTime class.
9
 */
10
class DateTime
11
{
12
    use Operations\Initiator,
13
        Operations\Processor,
14
        Operations\Formatter;
15
16
    /**
17
     * The Gregorian Date.
18
     *
19
     * @var GregorianDateTime
20
     */
21
    protected $dateTime;
22
23
    /** @var int */
24
    protected $year;
25
26
    /** @var int */
27
    protected $month;
28
29
    /** @var int */
30
    protected $day;
31
32
    /** @var bool */
33
    protected $leapYear;
34
35
    /** @var int */
36
    protected $dayOfYear;
37
38
    /** @var int */
39
    protected $daysInMonth;
40
41
    /**
42
     * Returns the Ethiopian Year.
43
     *
44
     * @return int year
45
     */
46 46
    public function getYear()
47
    {
48 46
        return $this->year;
49
    }
50
51
    /**
52
     * Returns the Ethiopian Month.
53
     *
54
     * @return int month
55
     */
56 45
    public function getMonth()
57
    {
58 45
        return $this->month;
59
    }
60
61
    /**
62
     * Returns the Ethiopian Day.
63
     *
64
     * @return int day
65
     */
66 45
    public function getDay()
67
    {
68 45
        return $this->day;
69
    }
70
71
    /**
72
     * Returns true if the Year is a leap.
73
     *
74
     * @return bool leap year
75
     */
76 2
    public function isLeapYear()
77
    {
78 2
        return $this->leapYear;
79
    }
80
81
    /**
82
     * Returns the day Of the Year.
83
     *
84
     * Day of the year is the number of days(inclusive)
85
     * have passed since the new year
86
     *
87
     * Eg. 'ኅዳር 29' day of the year is 89
88
     *
89
     * @return int day Of the Year
90
     */
91 2
    public function getDayOfYear()
92
    {
93 2
        return $this->dayOfYear;
94
    }
95
96
    /**
97
     * Returns number of days in the given year.
98
     *
99
     * It's 30 except 'ጳጉሜን'
100
     *
101
     * @return int days in the month
102
     */
103 2
    public function getDaysInMonth()
104
    {
105 2
        return $this->daysInMonth;
106
    }
107
108
    /**
109
     * Returns the Hour.
110
     *
111
     * @return int hour
112
     */
113 5
    public function getHour()
114
    {
115 5
        return (int) $this->dateTime->format('G');
116
    }
117
118
    /**
119
     * Returns the Minute.
120
     *
121
     * @return int minute
122
     */
123 1
    public function getMinute()
124
    {
125 1
        return (int) $this->dateTime->format('i');
126
    }
127
128
    /**
129
     * Returns the Second.
130
     *
131
     * @return int second
132
     */
133 1
    public function getSecond()
134
    {
135 1
        return (int) $this->dateTime->format('s');
136
    }
137
138
    /**
139
     * Returns the Micro.
140
     *
141
     * @return int micro
142
     */
143 1
    public function getMicro()
144
    {
145 1
        return (int) $this->dateTime->format('u');
146
    }
147
148
    /**
149
     * Returns the Day of the week.
150
     *
151
     * 1 (for ሰኞ) through 7 (for እሑድ)
152
     *
153
     * @return int day of the week
154
     */
155 4
    public function getDayOfWeek()
156
    {
157 4
        return (int) $this->dateTime->format('N');
158
    }
159
160
    /**
161
     * Returns the Timestamp.
162
     *
163
     * @see    time()
164
     *
165
     * @return int timestamp
166
     */
167 1
    public function getTimestamp()
168
    {
169 1
        return (int) $this->dateTime->format('U');
170
    }
171
172
    /**
173
     * DateTime constructor.
174
     *
175
     * @param GregorianDateTime|null $dateTime
176
     */
177 49
    public function __construct(GregorianDateTime $dateTime = null)
178
    {
179 49
        if (null === $dateTime) {
180 1
            $this->dateTime = new GregorianDateTime('now');
181
        } else {
182 49
            $this->dateTime = $dateTime;
183
        }
184
185 49
        $this->updateComputedFields();
186 49
    }
187
188
    /**
189
     * Return the <b>clone</b> of the base gregorian datetime.
190
     *
191
     * @return GregorianDateTime
192
     */
193 49
    public function toGregorian()
194
    {
195 49
        return clone $this->dateTime;
196
    }
197
}
198