1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace HMLB\Date\Tests\Date; |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Date package. |
7
|
|
|
* |
8
|
|
|
* (c) Hugues Maignol <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
use HMLB\Date\Date; |
15
|
|
|
use HMLB\Date\Tests\AbstractTestCase; |
16
|
|
|
|
17
|
|
|
class SubTest extends AbstractTestCase |
18
|
|
|
{ |
19
|
|
|
public function testSubYearsPositive() |
20
|
|
|
{ |
21
|
|
|
$this->assertSame(1974, Date::createFromDate(1975)->subYears(1)->getYear()); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function testSubYearsZero() |
25
|
|
|
{ |
26
|
|
|
$this->assertSame(1975, Date::createFromDate(1975)->subYears(0)->getYear()); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testSubYearsNegative() |
30
|
|
|
{ |
31
|
|
|
$this->assertSame(1976, Date::createFromDate(1975)->subYears(-1)->getYear()); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function testSubYear() |
35
|
|
|
{ |
36
|
|
|
$this->assertSame(1974, Date::createFromDate(1975)->subYear()->getYear()); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testSubMonthsPositive() |
40
|
|
|
{ |
41
|
|
|
$this->assertSame(12, Date::createFromDate(1975, 1, 1)->subMonths(1)->getMonth()); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testSubMonthsZero() |
45
|
|
|
{ |
46
|
|
|
$this->assertSame(1, Date::createFromDate(1975, 1, 1)->subMonths(0)->getMonth()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testSubMonthsNegative() |
50
|
|
|
{ |
51
|
|
|
$this->assertSame(2, Date::createFromDate(1975, 1, 1)->subMonths(-1)->getMonth()); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testSubMonth() |
55
|
|
|
{ |
56
|
|
|
$this->assertSame(12, Date::createFromDate(1975, 1, 1)->subMonth()->getMonth()); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function testSubDaysPositive() |
60
|
|
|
{ |
61
|
|
|
$this->assertSame(30, Date::createFromDate(1975, 5, 1)->subDays(1)->getDay()); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testSubDaysZero() |
65
|
|
|
{ |
66
|
|
|
$this->assertSame(1, Date::createFromDate(1975, 5, 1)->subDays(0)->getDay()); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function testSubDaysNegative() |
70
|
|
|
{ |
71
|
|
|
$this->assertSame(2, Date::createFromDate(1975, 5, 1)->subDays(-1)->getDay()); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function testSubDay() |
75
|
|
|
{ |
76
|
|
|
$this->assertSame(30, Date::createFromDate(1975, 5, 1)->subDay()->getDay()); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function testSubWeekdaysPositive() |
80
|
|
|
{ |
81
|
|
|
$this->assertSame(22, Date::createFromDate(2012, 1, 4)->subWeekdays(9)->getDay()); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function testSubWeekdaysZero() |
85
|
|
|
{ |
86
|
|
|
$this->assertSame(4, Date::createFromDate(2012, 1, 4)->subWeekdays(0)->getDay()); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function testSubWeekdaysNegative() |
90
|
|
|
{ |
91
|
|
|
$this->assertSame(13, Date::createFromDate(2012, 1, 31)->subWeekdays(-9)->getDay()); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function testSubWeekday() |
95
|
|
|
{ |
96
|
|
|
$this->assertSame(6, Date::createFromDate(2012, 1, 9)->subWeekday()->getDay()); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function testSubWeekdayDuringWeekend() |
100
|
|
|
{ |
101
|
|
|
$this->assertSame(6, Date::createFromDate(2012, 1, 8)->subWeekday()->getDay()); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function testSubWeeksPositive() |
105
|
|
|
{ |
106
|
|
|
$this->assertSame(14, Date::createFromDate(1975, 5, 21)->subWeeks(1)->getDay()); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function testSubWeeksZero() |
110
|
|
|
{ |
111
|
|
|
$this->assertSame(21, Date::createFromDate(1975, 5, 21)->subWeeks(0)->getDay()); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function testSubWeeksNegative() |
115
|
|
|
{ |
116
|
|
|
$this->assertSame(28, Date::createFromDate(1975, 5, 21)->subWeeks(-1)->getDay()); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
public function testSubWeek() |
120
|
|
|
{ |
121
|
|
|
$this->assertSame(14, Date::createFromDate(1975, 5, 21)->subWeek()->getDay()); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
public function testSubHoursPositive() |
125
|
|
|
{ |
126
|
|
|
$this->assertSame(23, Date::createFromTime(0)->subHours(1)->getHour()); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
public function testSubHoursZero() |
130
|
|
|
{ |
131
|
|
|
$this->assertSame(0, Date::createFromTime(0)->subHours(0)->getHour()); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
public function testSubHoursNegative() |
135
|
|
|
{ |
136
|
|
|
$this->assertSame(1, Date::createFromTime(0)->subHours(-1)->getHour()); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
public function testSubHour() |
140
|
|
|
{ |
141
|
|
|
$this->assertSame(23, Date::createFromTime(0)->subHour()->getHour()); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public function testSubMinutesPositive() |
145
|
|
|
{ |
146
|
|
|
$this->assertSame(59, Date::createFromTime(0, 0)->subMinutes(1)->getMinute()); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
public function testSubMinutesZero() |
150
|
|
|
{ |
151
|
|
|
$this->assertSame(0, Date::createFromTime(0, 0)->subMinutes(0)->getMinute()); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
public function testSubMinutesNegative() |
155
|
|
|
{ |
156
|
|
|
$this->assertSame(1, Date::createFromTime(0, 0)->subMinutes(-1)->getMinute()); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
public function testSubMinute() |
160
|
|
|
{ |
161
|
|
|
$this->assertSame(59, Date::createFromTime(0, 0)->subMinute()->getMinute()); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
public function testSubSecondsPositive() |
165
|
|
|
{ |
166
|
|
|
$this->assertSame(59, Date::createFromTime(0, 0, 0)->subSeconds(1)->getSecond()); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
public function testSubSecondsZero() |
170
|
|
|
{ |
171
|
|
|
$this->assertSame(0, Date::createFromTime(0, 0, 0)->subSeconds(0)->getSecond()); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
public function testSubSecondsNegative() |
175
|
|
|
{ |
176
|
|
|
$this->assertSame(1, Date::createFromTime(0, 0, 0)->subSeconds(-1)->getSecond()); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
public function testSubSecond() |
180
|
|
|
{ |
181
|
|
|
$this->assertSame(59, Date::createFromTime(0, 0, 0)->subSecond()->getSecond()); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/***** Test non plural methods with non default args *****/ |
185
|
|
|
|
186
|
|
|
public function testSubYearPassingArg() |
187
|
|
|
{ |
188
|
|
|
$this->assertSame(1973, Date::createFromDate(1975)->subYear(2)->getYear()); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
public function testSubMonthPassingArg() |
192
|
|
|
{ |
193
|
|
|
$this->assertSame(3, Date::createFromDate(1975, 5, 1)->subMonth(2)->getMonth()); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
public function testSubMonthNoOverflowPassingArg() |
197
|
|
|
{ |
198
|
|
|
$dt = Date::createFromDate(2011, 4, 30)->subMonthNoOverflow(2); |
199
|
|
|
$this->assertSame(2, $dt->getMonth()); |
200
|
|
|
$this->assertSame(28, $dt->getDay()); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
public function testSubDayPassingArg() |
204
|
|
|
{ |
205
|
|
|
$this->assertSame(8, Date::createFromDate(1975, 5, 10)->subDay(2)->getDay()); |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
public function testSubHourPassingArg() |
209
|
|
|
{ |
210
|
|
|
$this->assertSame(22, Date::createFromTime(0)->subHour(2)->getHour()); |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
public function testSubMinutePassingArg() |
214
|
|
|
{ |
215
|
|
|
$this->assertSame(58, Date::createFromTime(0)->subMinute(2)->getMinute()); |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
public function testSubSecondPassingArg() |
219
|
|
|
{ |
220
|
|
|
$this->assertSame(58, Date::createFromTime(0)->subSecond(2)->getSecond()); |
221
|
|
|
} |
222
|
|
|
} |
223
|
|
|
|