Issues (75)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

tests/Date/DiffTest.php (18 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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 Closure;
15
use HMLB\Date\Date;
16
use HMLB\Date\Interval;
17
use HMLB\Date\Tests\AbstractTestCase;
18
19
class DiffTest extends AbstractTestCase
20
{
21
    protected function wrapWithTestNow(Closure $func, Date $dt = null)
22
    {
23
        parent::wrapWithTestNow($func, ($dt === null) ? Date::createFromDate(2012, 1, 1) : $dt);
24
    }
25
26
    public function testDiffInYearsPositive()
27
    {
28
        $dt = Date::createFromDate(2000, 1, 1);
29
        $this->assertSame(1, $dt->diffInYears($dt->copy()->addYear()));
30
    }
31
32
    public function testDiffInYearsNegativeWithSign()
33
    {
34
        $dt = Date::createFromDate(2000, 1, 1);
35
        $this->assertSame(-1, $dt->diffInYears($dt->copy()->subYear(), false));
36
    }
37
38
    public function testDiffInYearsNegativeNoSign()
39
    {
40
        $dt = Date::createFromDate(2000, 1, 1);
41
        $this->assertSame(1, $dt->diffInYears($dt->copy()->subYear()));
42
    }
43
44
    public function testDiffInYearsVsDefaultNow()
45
    {
46
        $scope = $this;
47
        $this->wrapWithTestNow(
48
            function () use ($scope) {
49
                $scope->assertSame(1, Date::now()->subYear()->diffInYears());
50
            }
51
        );
52
    }
53
54
    public function testDiffInYearsEnsureIsTruncated()
55
    {
56
        $dt = Date::createFromDate(2000, 1, 1);
57
        $this->assertSame(1, $dt->diffInYears($dt->copy()->addYear()->addMonths(7)));
58
    }
59
60
    public function testDiffInMonthsPositive()
61
    {
62
        $dt = Date::createFromDate(2000, 1, 1);
63
        $this->assertSame(13, $dt->diffInMonths($dt->copy()->addYear()->addMonth()));
64
    }
65
66
    public function testDiffInMonthsNegativeWithSign()
67
    {
68
        $dt = Date::createFromDate(2000, 1, 1);
69
        $this->assertSame(-11, $dt->diffInMonths($dt->copy()->subYear()->addMonth(), false));
70
    }
71
72
    public function testDiffInMonthsNegativeNoSign()
73
    {
74
        $dt = Date::createFromDate(2000, 1, 1);
75
        $this->assertSame(11, $dt->diffInMonths($dt->copy()->subYear()->addMonth()));
76
    }
77
78
    public function testDiffInMonthsVsDefaultNow()
79
    {
80
        $scope = $this;
81
        $this->wrapWithTestNow(
82
            function () use ($scope) {
83
                $scope->assertSame(12, Date::now()->subYear()->diffInMonths());
84
            }
85
        );
86
    }
87
88
    public function testDiffInMonthsEnsureIsTruncated()
89
    {
90
        $dt = Date::createFromDate(2000, 1, 1);
91
        $this->assertSame(1, $dt->diffInMonths($dt->copy()->addMonth()->addDays(16)));
92
    }
93
94
    public function testDiffInDaysPositive()
95
    {
96
        $dt = Date::createFromDate(2000, 1, 1);
97
        $this->assertSame(366, $dt->diffInDays($dt->copy()->addYear()));
98
    }
99
100
    public function testDiffInDaysNegativeWithSign()
101
    {
102
        $dt = Date::createFromDate(2000, 1, 1);
103
        $this->assertSame(-365, $dt->diffInDays($dt->copy()->subYear(), false));
104
    }
105
106
    public function testDiffInDaysNegativeNoSign()
107
    {
108
        $dt = Date::createFromDate(2000, 1, 1);
109
        $this->assertSame(365, $dt->diffInDays($dt->copy()->subYear()));
110
    }
111
112
    public function testDiffInDaysVsDefaultNow()
113
    {
114
        $scope = $this;
115
        $this->wrapWithTestNow(
116
            function () use ($scope) {
117
                $scope->assertSame(7, Date::now()->subWeek()->diffInDays());
118
            }
119
        );
120
    }
121
122
    public function testDiffInDaysEnsureIsTruncated()
123
    {
124
        $dt = Date::createFromDate(2000, 1, 1);
125
        $this->assertSame(1, $dt->diffInDays($dt->copy()->addDay()->addHours(13)));
126
    }
127
128
    public function testDiffInDaysFilteredPositiveWithMutated()
129
    {
130
        $dt = Date::createFromDate(2000, 1, 1);
131
        $this->assertSame(
132
            5,
133
            $dt->diffInDaysFiltered(
134
                function (Date $date) {
135
                    return $date->getDayOfWeek() === 1;
136
                },
137
                $dt->copy()->endOfMonth()
138
            )
139
        );
140
    }
141
142
    public function testDiffInDaysFilteredPositiveWithSecondObject()
143
    {
144
        $dt1 = Date::createFromDate(2000, 1, 1);
145
        $dt2 = Date::createFromDate(2000, 1, 31);
146
147
        $this->assertSame(
148
            5,
149
            $dt1->diffInDaysFiltered(
150
                function (Date $date) {
151
                    return $date->getDayOfWeek() === Date::SUNDAY;
152
                },
153
                $dt2
154
            )
155
        );
156
    }
157
158
    public function testDiffInDaysFilteredNegativeNoSignWithMutated()
159
    {
160
        $dt = Date::createFromDate(2000, 1, 31);
161
        $this->assertSame(
162
            5,
163
            $dt->diffInDaysFiltered(
164
                function (Date $date) {
165
                    return $date->getDayOfWeek() === Date::SUNDAY;
166
                },
167
                $dt->copy()->startOfMonth()
168
            )
169
        );
170
    }
171
172
    public function testDiffInDaysFilteredNegativeNoSignWithSecondObject()
173
    {
174
        $dt1 = Date::createFromDate(2000, 1, 31);
175
        $dt2 = Date::createFromDate(2000, 1, 1);
176
177
        $this->assertSame(
178
            5,
179
            $dt1->diffInDaysFiltered(
180
                function (Date $date) {
181
                    return $date->getDayOfWeek() === Date::SUNDAY;
182
                },
183
                $dt2
184
            )
185
        );
186
    }
187
188
    public function testDiffInDaysFilteredNegativeWithSignWithMutated()
189
    {
190
        $dt = Date::createFromDate(2000, 1, 31);
191
        $this->assertSame(
192
            -5,
193
            $dt->diffInDaysFiltered(
194
                function (Date $date) {
195
                    return $date->getDayOfWeek() === 1;
196
                },
197
                $dt->copy()->startOfMonth(),
198
                false
199
            )
200
        );
201
    }
202
203 View Code Duplication
    public function testDiffInDaysFilteredNegativeWithSignWithSecondObject()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
204
    {
205
        $dt1 = Date::createFromDate(2000, 1, 31);
206
        $dt2 = Date::createFromDate(2000, 1, 1);
207
208
        $this->assertSame(
209
            -5,
210
            $dt1->diffInDaysFiltered(
211
                function (Date $date) {
212
                    return $date->getDayOfWeek() === Date::SUNDAY;
213
                },
214
                $dt2,
215
                false
216
            )
217
        );
218
    }
219
220
    public function testDiffInHoursFiltered()
221
    {
222
        $dt1 = Date::createFromDate(2000, 1, 31)->endOfDay();
223
        $dt2 = Date::createFromDate(2000, 1, 1)->startOfDay();
224
225
        $this->assertSame(
226
            31,
227
            $dt1->diffInHoursFiltered(
228
                function (Date $date) {
229
                    return $date->getHour() === 9;
230
                },
231
                $dt2
232
            )
233
        );
234
    }
235
236 View Code Duplication
    public function testDiffInHoursFilteredNegative()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
237
    {
238
        $dt1 = Date::createFromDate(2000, 1, 31)->endOfDay();
239
        $dt2 = Date::createFromDate(2000, 1, 1)->startOfDay();
240
241
        $this->assertSame(
242
            -31,
243
            $dt1->diffInHoursFiltered(
244
                function (Date $date) {
245
                    return $date->getHour() === 9;
246
                },
247
                $dt2,
248
                false
249
            )
250
        );
251
    }
252
253
    public function testDiffInHoursFilteredWorkHoursPerWeek()
254
    {
255
        $dt1 = Date::createFromDate(2000, 1, 5)->endOfDay();
256
        $dt2 = Date::createFromDate(2000, 1, 1)->startOfDay();
257
258
        $this->assertSame(
259
            40,
260
            $dt1->diffInHoursFiltered(
261
                function (Date $date) {
262
                    return ($date->getHour() > 8 && $date->getHour() < 17);
263
                },
264
                $dt2
265
            )
266
        );
267
    }
268
269 View Code Duplication
    public function testDiffFilteredUsingMinutesPositiveWithMutated()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
270
    {
271
        $dt = Date::createFromDate(2000, 1, 1)->startOfDay();
272
        $this->assertSame(
273
            60,
274
            $dt->diffFiltered(
275
                Interval::minute(),
276
                function (Date $date) {
277
                    return $date->getHour() === 12;
278
                },
279
                Date::createFromDate(2000, 1, 1)->endOfDay()
280
            )
281
        );
282
    }
283
284
    public function testDiffFilteredPositiveWithSecondObject()
285
    {
286
        $dt1 = Date::create(2000, 1, 1);
287
        $dt2 = $dt1->copy()->addSeconds(80);
288
289
        $this->assertSame(
290
            40,
291
            $dt1->diffFiltered(
292
                Interval::second(),
293
                function (Date $date) {
294
                    return $date->getSecond() % 2 === 0;
295
                },
296
                $dt2
297
            )
298
        );
299
    }
300
301 View Code Duplication
    public function testDiffFilteredNegativeNoSignWithMutated()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
302
    {
303
        $dt = Date::createFromDate(2000, 1, 31);
304
305
        $this->assertSame(
306
            2,
307
            $dt->diffFiltered(
308
                Interval::days(2),
309
                function (Date $date) {
310
                    return $date->getDayOfWeek() === Date::SUNDAY;
311
                },
312
                $dt->copy()->startOfMonth()
313
            )
314
        );
315
    }
316
317
    public function testDiffFilteredNegativeNoSignWithSecondObject()
318
    {
319
        $dt1 = Date::createFromDate(2006, 1, 31);
320
        $dt2 = Date::createFromDate(2000, 1, 1);
321
322
        $this->assertSame(
323
            7,
324
            $dt1->diffFiltered(
325
                Interval::year(),
326
                function (Date $date) {
327
                    return $date->getMonth() === 1;
328
                },
329
                $dt2
330
            )
331
        );
332
    }
333
334 View Code Duplication
    public function testDiffFilteredNegativeWithSignWithMutated()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
335
    {
336
        $dt = Date::createFromDate(2000, 1, 31);
337
        $this->assertSame(
338
            -4,
339
            $dt->diffFiltered(
340
                Interval::week(),
341
                function (Date $date) {
342
                    return $date->getMonth() === 12;
343
                },
344
                $dt->copy()->subMonths(3),
345
                false
346
            )
347
        );
348
    }
349
350 View Code Duplication
    public function testDiffFilteredNegativeWithSignWithSecondObject()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
351
    {
352
        $dt1 = Date::createFromDate(2001, 1, 31);
353
        $dt2 = Date::createFromDate(1999, 1, 1);
354
355
        $this->assertSame(
356
            -12,
357
            $dt1->diffFiltered(
358
                Interval::month(),
359
                function (Date $date) {
360
                    return $date->getYear() === 2000;
361
                },
362
                $dt2,
363
                false
364
            )
365
        );
366
    }
367
368 View Code Duplication
    public function testBug188DiffWithSameDates()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
369
    {
370
        $start = Date::create(2014, 10, 8, 15, 20, 0);
371
        $end = $start->copy();
372
373
        $this->assertSame(0, $start->diffInDays($end));
374
        $this->assertSame(0, $start->diffInWeekdays($end));
375
    }
376
377 View Code Duplication
    public function testBug188DiffWithDatesOnlyHoursApart()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
378
    {
379
        $start = Date::create(2014, 10, 8, 15, 20, 0);
380
        $end = $start->copy();
381
382
        $this->assertSame(0, $start->diffInDays($end));
383
        $this->assertSame(0, $start->diffInWeekdays($end));
384
    }
385
386 View Code Duplication
    public function testBug188DiffWithSameDates1DayApart()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
387
    {
388
        $start = Date::create(2014, 10, 8, 15, 20, 0);
389
        $end = $start->copy()->addDay();
390
391
        $this->assertSame(1, $start->diffInDays($end));
392
        $this->assertSame(1, $start->diffInWeekdays($end));
393
    }
394
395 View Code Duplication
    public function testBug188DiffWithDatesOnTheWeekend()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
396
    {
397
        $start = Date::create(2014, 1, 1, 0, 0, 0)->next(Date::SATURDAY);
398
        $end = $start->addDay();
399
400
        $this->assertSame(1, $start->diffInDays($end));
401
        $this->assertSame(0, $start->diffInWeekdays($end));
402
    }
403
404
    public function testDiffInWeekdaysPositive()
405
    {
406
        $dt = Date::createFromDate(2000, 1, 1);
407
        $this->assertSame(21, $dt->diffInWeekdays($dt->copy()->endOfMonth()));
408
    }
409
410
    public function testDiffInWeekdaysNegativeNoSign()
411
    {
412
        $dt = Date::createFromDate(2000, 1, 31);
413
        $this->assertSame(21, $dt->diffInWeekdays($dt->copy()->startOfMonth()));
414
    }
415
416
    public function testDiffInWeekdaysNegativeWithSign()
417
    {
418
        $dt = Date::createFromDate(2000, 1, 31);
419
        $this->assertSame(-21, $dt->diffInWeekdays($dt->copy()->startOfMonth(), false));
420
    }
421
422
    public function testDiffInWeekendDaysPositive()
423
    {
424
        $dt = Date::createFromDate(2000, 1, 1);
425
        $this->assertSame(10, $dt->diffInWeekendDays($dt->copy()->endOfMonth()));
426
    }
427
428
    public function testDiffInWeekendDaysNegativeNoSign()
429
    {
430
        $dt = Date::createFromDate(2000, 1, 31);
431
        $this->assertSame(10, $dt->diffInWeekendDays($dt->copy()->startOfMonth()));
432
    }
433
434
    public function testDiffInWeekendDaysNegativeWithSign()
435
    {
436
        $dt = Date::createFromDate(2000, 1, 31);
437
        $this->assertSame(-10, $dt->diffInWeekendDays($dt->copy()->startOfMonth(), false));
438
    }
439
440
    public function testDiffInWeeksPositive()
441
    {
442
        $dt = Date::createFromDate(2000, 1, 1);
443
        $this->assertSame(52, $dt->diffInWeeks($dt->copy()->addYear()));
444
    }
445
446
    public function testDiffInWeeksNegativeWithSign()
447
    {
448
        $dt = Date::createFromDate(2000, 1, 1);
449
        $this->assertSame(-52, $dt->diffInWeeks($dt->copy()->subYear(), false));
450
    }
451
452
    public function testDiffInWeeksNegativeNoSign()
453
    {
454
        $dt = Date::createFromDate(2000, 1, 1);
455
        $this->assertSame(52, $dt->diffInWeeks($dt->copy()->subYear()));
456
    }
457
458
    public function testDiffInWeeksVsDefaultNow()
459
    {
460
        $scope = $this;
461
        $this->wrapWithTestNow(
462
            function () use ($scope) {
463
                $scope->assertSame(1, Date::now()->subWeek()->diffInWeeks());
464
            }
465
        );
466
    }
467
468
    public function testDiffInWeeksEnsureIsTruncated()
469
    {
470
        $dt = Date::createFromDate(2000, 1, 1);
471
        $this->assertSame(0, $dt->diffInWeeks($dt->copy()->addWeek()->subDay()));
472
    }
473
474
    public function testDiffInHoursPositive()
475
    {
476
        $dt = Date::createFromDate(2000, 1, 1);
477
        $this->assertSame(26, $dt->diffInHours($dt->copy()->addDay()->addHours(2)));
478
    }
479
480
    public function testDiffInHoursNegativeWithSign()
481
    {
482
        $dt = Date::createFromDate(2000, 1, 1);
483
        $this->assertSame(-22, $dt->diffInHours($dt->copy()->subDay()->addHours(2), false));
484
    }
485
486
    public function testDiffInHoursNegativeNoSign()
487
    {
488
        $dt = Date::createFromDate(2000, 1, 1);
489
        $this->assertSame(22, $dt->diffInHours($dt->copy()->subDay()->addHours(2)));
490
    }
491
492
    public function testDiffInHoursVsDefaultNow()
493
    {
494
        $scope = $this;
495
        $this->wrapWithTestNow(
496
            function () use ($scope) {
497
                $scope->assertSame(48, Date::now()->subDays(2)->diffInHours());
498
            },
499
            Date::create(2012, 1, 15)
500
        );
501
    }
502
503
    public function testDiffInHoursEnsureIsTruncated()
504
    {
505
        $dt = Date::createFromDate(2000, 1, 1);
506
        $this->assertSame(1, $dt->diffInHours($dt->copy()->addHour()->addMinutes(31)));
507
    }
508
509
    public function testDiffInMinutesPositive()
510
    {
511
        $dt = Date::createFromDate(2000, 1, 1);
512
        $this->assertSame(62, $dt->diffInMinutes($dt->copy()->addHour()->addMinutes(2)));
513
    }
514
515
    public function testDiffInMinutesPositiveAlot()
516
    {
517
        $dt = Date::createFromDate(2000, 1, 1);
518
        $this->assertSame(1502, $dt->diffInMinutes($dt->copy()->addHours(25)->addMinutes(2)));
519
    }
520
521
    public function testDiffInMinutesNegativeWithSign()
522
    {
523
        $dt = Date::createFromDate(2000, 1, 1);
524
        $this->assertSame(-58, $dt->diffInMinutes($dt->copy()->subHour()->addMinutes(2), false));
525
    }
526
527
    public function testDiffInMinutesNegativeNoSign()
528
    {
529
        $dt = Date::createFromDate(2000, 1, 1);
530
        $this->assertSame(58, $dt->diffInMinutes($dt->copy()->subHour()->addMinutes(2)));
531
    }
532
533
    public function testDiffInMinutesVsDefaultNow()
534
    {
535
        $scope = $this;
536
        $this->wrapWithTestNow(
537
            function () use ($scope) {
538
                $scope->assertSame(60, Date::now()->subHour()->diffInMinutes());
539
            }
540
        );
541
    }
542
543
    public function testDiffInMinutesEnsureIsTruncated()
544
    {
545
        $dt = Date::createFromDate(2000, 1, 1);
546
        $this->assertSame(1, $dt->diffInMinutes($dt->copy()->addMinute()->addSeconds(31)));
547
    }
548
549
    public function testDiffInSecondsPositive()
550
    {
551
        $dt = Date::createFromDate(2000, 1, 1);
552
        $this->assertSame(62, $dt->diffInSeconds($dt->copy()->addMinute()->addSeconds(2)));
553
    }
554
555
    public function testDiffInSecondsPositiveAlot()
556
    {
557
        $dt = Date::createFromDate(2000, 1, 1);
558
        $this->assertSame(7202, $dt->diffInSeconds($dt->copy()->addHours(2)->addSeconds(2)));
559
    }
560
561
    public function testDiffInSecondsNegativeWithSign()
562
    {
563
        $dt = Date::createFromDate(2000, 1, 1);
564
        $this->assertSame(-58, $dt->diffInSeconds($dt->copy()->subMinute()->addSeconds(2), false));
565
    }
566
567
    public function testDiffInSecondsNegativeNoSign()
568
    {
569
        $dt = Date::createFromDate(2000, 1, 1);
570
        $this->assertSame(58, $dt->diffInSeconds($dt->copy()->subMinute()->addSeconds(2)));
571
    }
572
573
    public function testDiffInSecondsVsDefaultNow()
574
    {
575
        $scope = $this;
576
        $this->wrapWithTestNow(
577
            function () use ($scope) {
578
                $scope->assertSame(3600, Date::now()->subHour()->diffInSeconds());
579
            }
580
        );
581
    }
582
583
    public function testDiffInSecondsEnsureIsTruncated()
584
    {
585
        $dt = Date::createFromDate(2000, 1, 1);
586
        $this->assertSame(1, $dt->diffInSeconds($dt->copy()->addSeconds(1.9)));
587
    }
588
589
    public function testDiffInSecondsWithTimezones()
590
    {
591
        $dtOttawa = Date::createFromDate(2000, 1, 1, 'America/Toronto');
592
        $dtVancouver = Date::createFromDate(2000, 1, 1, 'America/Vancouver');
593
        $this->assertSame(3 * 60 * 60, $dtOttawa->diffInSeconds($dtVancouver));
594
    }
595
596
    public function testDiffInSecondsWithTimezonesAndVsDefauisBefore()
597
    {
598
        $vanNow = Date::now('America/Vancouver');
599
        $hereNow = $vanNow->setTimezone(Date::now()->getTimezone());
600
        $vanNow = $vanNow->setTimezone(Date::now()->getTimezone());
601
602
        $scope = $this;
603
        $this->wrapWithTestNow(
604
            function () use ($vanNow, $scope) {
605
                $scope->assertSame(0, $vanNow->diffInSeconds());
606
            },
607
            $hereNow
608
        );
609
    }
610
611
    public function testDiffForHumansNowAndSecond()
612
    {
613
        $scope = $this;
614
        $this->wrapWithTestNow(
615
            function () use ($scope) {
616
                $scope->assertSame('1 second ago', Date::now()->diffForHumans());
617
            }
618
        );
619
    }
620
621
    public function testDiffForHumansNowAndSecondWithTimezone()
622
    {
623
        $vanNow = Date::now('America/Vancouver');
624
        $hereNow = $vanNow->setTimezone(Date::now()->getTimezone());
625
626
        $scope = $this;
627
        $this->wrapWithTestNow(
628
            function () use ($vanNow, $scope) {
629
                $scope->assertSame('1 second ago', $vanNow->diffForHumans());
630
            },
631
            $hereNow
632
        );
633
    }
634
635
    public function testDiffForHumansNowAndSeconds()
636
    {
637
        $scope = $this;
638
        $this->wrapWithTestNow(
639
            function () use ($scope) {
640
                $scope->assertSame('2 seconds ago', Date::now()->subSeconds(2)->diffForHumans());
641
            }
642
        );
643
    }
644
645
    public function testDiffForHumansNowAndNearlyMinute()
646
    {
647
        $scope = $this;
648
        $this->wrapWithTestNow(
649
            function () use ($scope) {
650
                $scope->assertSame('59 seconds ago', Date::now()->subSeconds(59)->diffForHumans());
651
            }
652
        );
653
    }
654
655
    public function testDiffForHumansNowAndMinute()
656
    {
657
        $scope = $this;
658
        $this->wrapWithTestNow(
659
            function () use ($scope) {
660
                $scope->assertSame('1 minute ago', Date::now()->subMinute()->diffForHumans());
661
            }
662
        );
663
    }
664
665
    public function testDiffForHumansNowAndMinutes()
666
    {
667
        $scope = $this;
668
        $this->wrapWithTestNow(
669
            function () use ($scope) {
670
                $scope->assertSame('2 minutes ago', Date::now()->subMinutes(2)->diffForHumans());
671
            }
672
        );
673
    }
674
675
    public function testDiffForHumansNowAndNearlyHour()
676
    {
677
        $scope = $this;
678
        $this->wrapWithTestNow(
679
            function () use ($scope) {
680
                $scope->assertSame('59 minutes ago', Date::now()->subMinutes(59)->diffForHumans());
681
            }
682
        );
683
    }
684
685
    public function testDiffForHumansNowAndHour()
686
    {
687
        $scope = $this;
688
        $this->wrapWithTestNow(
689
            function () use ($scope) {
690
                $scope->assertSame('1 hour ago', Date::now()->subHour()->diffForHumans());
691
            }
692
        );
693
    }
694
695
    public function testDiffForHumansNowAndHours()
696
    {
697
        $scope = $this;
698
        $this->wrapWithTestNow(
699
            function () use ($scope) {
700
                $scope->assertSame('2 hours ago', Date::now()->subHours(2)->diffForHumans());
701
            }
702
        );
703
    }
704
705
    public function testDiffForHumansNowAndNearlyDay()
706
    {
707
        $scope = $this;
708
        $this->wrapWithTestNow(
709
            function () use ($scope) {
710
                $scope->assertSame('23 hours ago', Date::now()->subHours(23)->diffForHumans());
711
            }
712
        );
713
    }
714
715
    public function testDiffForHumansNowAndDay()
716
    {
717
        $scope = $this;
718
        $this->wrapWithTestNow(
719
            function () use ($scope) {
720
                $scope->assertSame('1 day ago', Date::now()->subDay()->diffForHumans());
721
            }
722
        );
723
    }
724
725
    public function testDiffForHumansNowAndDays()
726
    {
727
        $scope = $this;
728
        $this->wrapWithTestNow(
729
            function () use ($scope) {
730
                $scope->assertSame('2 days ago', Date::now()->subDays(2)->diffForHumans());
731
            }
732
        );
733
    }
734
735
    public function testDiffForHumansNowAndNearlyWeek()
736
    {
737
        $scope = $this;
738
        $this->wrapWithTestNow(
739
            function () use ($scope) {
740
                $scope->assertSame('6 days ago', Date::now()->subDays(6)->diffForHumans());
741
            }
742
        );
743
    }
744
745
    public function testDiffForHumansNowAndWeek()
746
    {
747
        $scope = $this;
748
        $this->wrapWithTestNow(
749
            function () use ($scope) {
750
                $scope->assertSame('1 week ago', Date::now()->subWeek()->diffForHumans());
751
            }
752
        );
753
    }
754
755
    public function testDiffForHumansNowAndWeeks()
756
    {
757
        $scope = $this;
758
        $this->wrapWithTestNow(
759
            function () use ($scope) {
760
                $scope->assertSame('2 weeks ago', Date::now()->subWeeks(2)->diffForHumans());
761
            }
762
        );
763
    }
764
765
    public function testDiffForHumansNowAndNearlyMonth()
766
    {
767
        $scope = $this;
768
        $this->wrapWithTestNow(
769
            function () use ($scope) {
770
                $scope->assertSame('3 weeks ago', Date::now()->subWeeks(3)->diffForHumans());
771
            }
772
        );
773
    }
774
775
    public function testDiffForHumansNowAndMonth()
776
    {
777
        $scope = $this;
778
        $this->wrapWithTestNow(
779
            function () use ($scope) {
780
                $scope->assertSame('4 weeks ago', Date::now()->subWeeks(4)->diffForHumans());
781
                $scope->assertSame('1 month ago', Date::now()->subMonth()->diffForHumans());
782
            }
783
        );
784
    }
785
786
    public function testDiffForHumansNowAndMonths()
787
    {
788
        $scope = $this;
789
        $this->wrapWithTestNow(
790
            function () use ($scope) {
791
                $scope->assertSame('2 months ago', Date::now()->subMonths(2)->diffForHumans());
792
            }
793
        );
794
    }
795
796
    public function testDiffForHumansNowAndNearlyYear()
797
    {
798
        $scope = $this;
799
        $this->wrapWithTestNow(
800
            function () use ($scope) {
801
                $scope->assertSame('11 months ago', Date::now()->subMonths(11)->diffForHumans());
802
            }
803
        );
804
    }
805
806
    public function testDiffForHumansNowAndYear()
807
    {
808
        $scope = $this;
809
        $this->wrapWithTestNow(
810
            function () use ($scope) {
811
                $scope->assertSame('1 year ago', Date::now()->subYear()->diffForHumans());
812
            }
813
        );
814
    }
815
816
    public function testDiffForHumansNowAndYears()
817
    {
818
        $scope = $this;
819
        $this->wrapWithTestNow(
820
            function () use ($scope) {
821
                $scope->assertSame('2 years ago', Date::now()->subYears(2)->diffForHumans());
822
            }
823
        );
824
    }
825
826
    public function testDiffForHumansNowAndFutureSecond()
827
    {
828
        $scope = $this;
829
        $this->wrapWithTestNow(
830
            function () use ($scope) {
831
                $scope->assertSame('1 second from now', Date::now()->addSecond()->diffForHumans());
832
            }
833
        );
834
    }
835
836
    public function testDiffForHumansNowAndFutureSeconds()
837
    {
838
        $scope = $this;
839
        $this->wrapWithTestNow(
840
            function () use ($scope) {
841
                $scope->assertSame('2 seconds from now', Date::now()->addSeconds(2)->diffForHumans());
842
            }
843
        );
844
    }
845
846
    public function testDiffForHumansNowAndNearlyFutureMinute()
847
    {
848
        $scope = $this;
849
        $this->wrapWithTestNow(
850
            function () use ($scope) {
851
                $scope->assertSame('59 seconds from now', Date::now()->addSeconds(59)->diffForHumans());
852
            }
853
        );
854
    }
855
856
    public function testDiffForHumansNowAndFutureMinute()
857
    {
858
        $scope = $this;
859
        $this->wrapWithTestNow(
860
            function () use ($scope) {
861
                $scope->assertSame('1 minute from now', Date::now()->addMinute()->diffForHumans());
862
            }
863
        );
864
    }
865
866
    public function testDiffForHumansNowAndFutureMinutes()
867
    {
868
        $scope = $this;
869
        $this->wrapWithTestNow(
870
            function () use ($scope) {
871
                $scope->assertSame('2 minutes from now', Date::now()->addMinutes(2)->diffForHumans());
872
            }
873
        );
874
    }
875
876
    public function testDiffForHumansNowAndNearlyFutureHour()
877
    {
878
        $scope = $this;
879
        $this->wrapWithTestNow(
880
            function () use ($scope) {
881
                $scope->assertSame('59 minutes from now', Date::now()->addMinutes(59)->diffForHumans());
882
            }
883
        );
884
    }
885
886
    public function testDiffForHumansNowAndFutureHour()
887
    {
888
        $scope = $this;
889
        $this->wrapWithTestNow(
890
            function () use ($scope) {
891
                $scope->assertSame('1 hour from now', Date::now()->addHour()->diffForHumans());
892
            }
893
        );
894
    }
895
896
    public function testDiffForHumansNowAndFutureHours()
897
    {
898
        $scope = $this;
899
        $this->wrapWithTestNow(
900
            function () use ($scope) {
901
                $scope->assertSame('2 hours from now', Date::now()->addHours(2)->diffForHumans());
902
            }
903
        );
904
    }
905
906
    public function testDiffForHumansNowAndNearlyFutureDay()
907
    {
908
        $scope = $this;
909
        $this->wrapWithTestNow(
910
            function () use ($scope) {
911
                $scope->assertSame('23 hours from now', Date::now()->addHours(23)->diffForHumans());
912
            }
913
        );
914
    }
915
916
    public function testDiffForHumansNowAndFutureDay()
917
    {
918
        $scope = $this;
919
        $this->wrapWithTestNow(
920
            function () use ($scope) {
921
                $scope->assertSame('1 day from now', Date::now()->addDay()->diffForHumans());
922
            }
923
        );
924
    }
925
926
    public function testDiffForHumansNowAndFutureDays()
927
    {
928
        $scope = $this;
929
        $this->wrapWithTestNow(
930
            function () use ($scope) {
931
                $scope->assertSame('2 days from now', Date::now()->addDays(2)->diffForHumans());
932
            }
933
        );
934
    }
935
936
    public function testDiffForHumansNowAndNearlyFutureWeek()
937
    {
938
        $scope = $this;
939
        $this->wrapWithTestNow(
940
            function () use ($scope) {
941
                $scope->assertSame('6 days from now', Date::now()->addDays(6)->diffForHumans());
942
            }
943
        );
944
    }
945
946
    public function testDiffForHumansNowAndFutureWeek()
947
    {
948
        $scope = $this;
949
        $this->wrapWithTestNow(
950
            function () use ($scope) {
951
                $scope->assertSame('1 week from now', Date::now()->addWeek()->diffForHumans());
952
            }
953
        );
954
    }
955
956
    public function testDiffForHumansNowAndFutureWeeks()
957
    {
958
        $scope = $this;
959
        $this->wrapWithTestNow(
960
            function () use ($scope) {
961
                $scope->assertSame('2 weeks from now', Date::now()->addWeeks(2)->diffForHumans());
962
            }
963
        );
964
    }
965
966
    public function testDiffForHumansNowAndNearlyFutureMonth()
967
    {
968
        $scope = $this;
969
        $this->wrapWithTestNow(
970
            function () use ($scope) {
971
                $scope->assertSame('3 weeks from now', Date::now()->addWeeks(3)->diffForHumans());
972
            }
973
        );
974
    }
975
976
    public function testDiffForHumansNowAndFutureMonth()
977
    {
978
        $scope = $this;
979
        $this->wrapWithTestNow(
980
            function () use ($scope) {
981
                $scope->assertSame('4 weeks from now', Date::now()->addWeeks(4)->diffForHumans());
982
                $scope->assertSame('1 month from now', Date::now()->addMonth()->diffForHumans());
983
            }
984
        );
985
    }
986
987
    public function testDiffForHumansNowAndFutureMonths()
988
    {
989
        $scope = $this;
990
        $this->wrapWithTestNow(
991
            function () use ($scope) {
992
                $scope->assertSame('2 months from now', Date::now()->addMonths(2)->diffForHumans());
993
            }
994
        );
995
    }
996
997
    public function testDiffForHumansNowAndNearlyFutureYear()
998
    {
999
        $scope = $this;
1000
        $this->wrapWithTestNow(
1001
            function () use ($scope) {
1002
                $scope->assertSame('11 months from now', Date::now()->addMonths(11)->diffForHumans());
1003
            }
1004
        );
1005
    }
1006
1007
    public function testDiffForHumansNowAndFutureYear()
1008
    {
1009
        $scope = $this;
1010
        $this->wrapWithTestNow(
1011
            function () use ($scope) {
1012
                $scope->assertSame('1 year from now', Date::now()->addYear()->diffForHumans());
1013
            }
1014
        );
1015
    }
1016
1017
    public function testDiffForHumansNowAndFutureYears()
1018
    {
1019
        $scope = $this;
1020
        $this->wrapWithTestNow(
1021
            function () use ($scope) {
1022
                $scope->assertSame('2 years from now', Date::now()->addYears(2)->diffForHumans());
1023
            }
1024
        );
1025
    }
1026
1027
    public function testDiffForHumansOtherAndSecond()
1028
    {
1029
        $scope = $this;
1030
        $this->wrapWithTestNow(
1031
            function () use ($scope) {
1032
                $scope->assertSame('1 second before', Date::now()->diffForHumans(Date::now()->addSecond()));
1033
            }
1034
        );
1035
    }
1036
1037
    public function testDiffForHumansOtherAndSeconds()
1038
    {
1039
        $scope = $this;
1040
        $this->wrapWithTestNow(
1041
            function () use ($scope) {
1042
                $scope->assertSame('2 seconds before', Date::now()->diffForHumans(Date::now()->addSeconds(2)));
1043
            }
1044
        );
1045
    }
1046
1047
    public function testDiffForHumansOtherAndNearlyMinute()
1048
    {
1049
        $scope = $this;
1050
        $this->wrapWithTestNow(
1051
            function () use ($scope) {
1052
                $scope->assertSame('59 seconds before', Date::now()->diffForHumans(Date::now()->addSeconds(59)));
1053
            }
1054
        );
1055
    }
1056
1057
    public function testDiffForHumansOtherAndMinute()
1058
    {
1059
        $scope = $this;
1060
        $this->wrapWithTestNow(
1061
            function () use ($scope) {
1062
                $scope->assertSame('1 minute before', Date::now()->diffForHumans(Date::now()->addMinute()));
1063
            }
1064
        );
1065
    }
1066
1067
    public function testDiffForHumansOtherAndMinutes()
1068
    {
1069
        $scope = $this;
1070
        $this->wrapWithTestNow(
1071
            function () use ($scope) {
1072
                $scope->assertSame('2 minutes before', Date::now()->diffForHumans(Date::now()->addMinutes(2)));
1073
            }
1074
        );
1075
    }
1076
1077
    public function testDiffForHumansOtherAndNearlyHour()
1078
    {
1079
        $scope = $this;
1080
        $this->wrapWithTestNow(
1081
            function () use ($scope) {
1082
                $scope->assertSame('59 minutes before', Date::now()->diffForHumans(Date::now()->addMinutes(59)));
1083
            }
1084
        );
1085
    }
1086
1087
    public function testDiffForHumansOtherAndHour()
1088
    {
1089
        $scope = $this;
1090
        $this->wrapWithTestNow(
1091
            function () use ($scope) {
1092
                $scope->assertSame('1 hour before', Date::now()->diffForHumans(Date::now()->addHour()));
1093
            }
1094
        );
1095
    }
1096
1097
    public function testDiffForHumansOtherAndHours()
1098
    {
1099
        $scope = $this;
1100
        $this->wrapWithTestNow(
1101
            function () use ($scope) {
1102
                $scope->assertSame('2 hours before', Date::now()->diffForHumans(Date::now()->addHours(2)));
1103
            }
1104
        );
1105
    }
1106
1107
    public function testDiffForHumansOtherAndNearlyDay()
1108
    {
1109
        $scope = $this;
1110
        $this->wrapWithTestNow(
1111
            function () use ($scope) {
1112
                $scope->assertSame('23 hours before', Date::now()->diffForHumans(Date::now()->addHours(23)));
1113
            }
1114
        );
1115
    }
1116
1117
    public function testDiffForHumansOtherAndDay()
1118
    {
1119
        $scope = $this;
1120
        $this->wrapWithTestNow(
1121
            function () use ($scope) {
1122
                $scope->assertSame('1 day before', Date::now()->diffForHumans(Date::now()->addDay()));
1123
            }
1124
        );
1125
    }
1126
1127
    public function testDiffForHumansOtherAndDays()
1128
    {
1129
        $scope = $this;
1130
        $this->wrapWithTestNow(
1131
            function () use ($scope) {
1132
                $scope->assertSame('2 days before', Date::now()->diffForHumans(Date::now()->addDays(2)));
1133
            }
1134
        );
1135
    }
1136
1137
    public function testDiffForHumansOtherAndNearlyWeek()
1138
    {
1139
        $scope = $this;
1140
        $this->wrapWithTestNow(
1141
            function () use ($scope) {
1142
                $scope->assertSame('6 days before', Date::now()->diffForHumans(Date::now()->addDays(6)));
1143
            }
1144
        );
1145
    }
1146
1147
    public function testDiffForHumansOtherAndWeek()
1148
    {
1149
        $scope = $this;
1150
        $this->wrapWithTestNow(
1151
            function () use ($scope) {
1152
                $scope->assertSame('1 week before', Date::now()->diffForHumans(Date::now()->addWeek()));
1153
            }
1154
        );
1155
    }
1156
1157
    public function testDiffForHumansOtherAndWeeks()
1158
    {
1159
        $scope = $this;
1160
        $this->wrapWithTestNow(
1161
            function () use ($scope) {
1162
                $scope->assertSame('2 weeks before', Date::now()->diffForHumans(Date::now()->addWeeks(2)));
1163
            }
1164
        );
1165
    }
1166
1167
    public function testDiffForHumansOtherAndNearlyMonth()
1168
    {
1169
        $scope = $this;
1170
        $this->wrapWithTestNow(
1171
            function () use ($scope) {
1172
                $scope->assertSame('3 weeks before', Date::now()->diffForHumans(Date::now()->addWeeks(3)));
1173
            }
1174
        );
1175
    }
1176
1177
    public function testDiffForHumansOtherAndMonth()
1178
    {
1179
        $scope = $this;
1180
        $this->wrapWithTestNow(
1181
            function () use ($scope) {
1182
                $scope->assertSame('4 weeks before', Date::now()->diffForHumans(Date::now()->addWeeks(4)));
1183
                $scope->assertSame('1 month before', Date::now()->diffForHumans(Date::now()->addMonth()));
1184
            }
1185
        );
1186
    }
1187
1188
    public function testDiffForHumansOtherAndMonths()
1189
    {
1190
        $scope = $this;
1191
        $this->wrapWithTestNow(
1192
            function () use ($scope) {
1193
                $scope->assertSame('2 months before', Date::now()->diffForHumans(Date::now()->addMonths(2)));
1194
            }
1195
        );
1196
    }
1197
1198
    public function testDiffForHumansOtherAndNearlyYear()
1199
    {
1200
        $scope = $this;
1201
        $this->wrapWithTestNow(
1202
            function () use ($scope) {
1203
                $scope->assertSame('11 months before', Date::now()->diffForHumans(Date::now()->addMonths(11)));
1204
            }
1205
        );
1206
    }
1207
1208
    public function testDiffForHumansOtherAndYear()
1209
    {
1210
        $scope = $this;
1211
        $this->wrapWithTestNow(
1212
            function () use ($scope) {
1213
                $scope->assertSame('1 year before', Date::now()->diffForHumans(Date::now()->addYear()));
1214
            }
1215
        );
1216
    }
1217
1218
    public function testDiffForHumansOtherAndYears()
1219
    {
1220
        $scope = $this;
1221
        $this->wrapWithTestNow(
1222
            function () use ($scope) {
1223
                $scope->assertSame('2 years before', Date::now()->diffForHumans(Date::now()->addYears(2)));
1224
            }
1225
        );
1226
    }
1227
1228 View Code Duplication
    public function testDiffForHumansOtherAndFutureSecond()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1229
    {
1230
        $scope = $this;
1231
        $this->wrapWithTestNow(
1232
            function () use ($scope) {
1233
                $scope->assertSame('1 second after', Date::now()->diffForHumans(Date::now()->subSecond()));
1234
            }
1235
        );
1236
    }
1237
1238
    public function testDiffForHumansOtherAndFutureSeconds()
1239
    {
1240
        $scope = $this;
1241
        $this->wrapWithTestNow(
1242
            function () use ($scope) {
1243
                $scope->assertSame('2 seconds after', Date::now()->diffForHumans(Date::now()->subSeconds(2)));
1244
            }
1245
        );
1246
    }
1247
1248
    public function testDiffForHumansOtherAndNearlyFutureMinute()
1249
    {
1250
        $scope = $this;
1251
        $this->wrapWithTestNow(
1252
            function () use ($scope) {
1253
                $scope->assertSame('59 seconds after', Date::now()->diffForHumans(Date::now()->subSeconds(59)));
1254
            }
1255
        );
1256
    }
1257
1258
    public function testDiffForHumansOtherAndFutureMinute()
1259
    {
1260
        $scope = $this;
1261
        $this->wrapWithTestNow(
1262
            function () use ($scope) {
1263
                $scope->assertSame('1 minute after', Date::now()->diffForHumans(Date::now()->subMinute()));
1264
            }
1265
        );
1266
    }
1267
1268
    public function testDiffForHumansOtherAndFutureMinutes()
1269
    {
1270
        $scope = $this;
1271
        $this->wrapWithTestNow(
1272
            function () use ($scope) {
1273
                $scope->assertSame('2 minutes after', Date::now()->diffForHumans(Date::now()->subMinutes(2)));
1274
            }
1275
        );
1276
    }
1277
1278
    public function testDiffForHumansOtherAndNearlyFutureHour()
1279
    {
1280
        $scope = $this;
1281
        $this->wrapWithTestNow(
1282
            function () use ($scope) {
1283
                $scope->assertSame('59 minutes after', Date::now()->diffForHumans(Date::now()->subMinutes(59)));
1284
            }
1285
        );
1286
    }
1287
1288
    public function testDiffForHumansOtherAndFutureHour()
1289
    {
1290
        $scope = $this;
1291
        $this->wrapWithTestNow(
1292
            function () use ($scope) {
1293
                $scope->assertSame('1 hour after', Date::now()->diffForHumans(Date::now()->subHour()));
1294
            }
1295
        );
1296
    }
1297
1298
    public function testDiffForHumansOtherAndFutureHours()
1299
    {
1300
        $scope = $this;
1301
        $this->wrapWithTestNow(
1302
            function () use ($scope) {
1303
                $scope->assertSame('2 hours after', Date::now()->diffForHumans(Date::now()->subHours(2)));
1304
            }
1305
        );
1306
    }
1307
1308
    public function testDiffForHumansOtherAndNearlyFutureDay()
1309
    {
1310
        $scope = $this;
1311
        $this->wrapWithTestNow(
1312
            function () use ($scope) {
1313
                $scope->assertSame('23 hours after', Date::now()->diffForHumans(Date::now()->subHours(23)));
1314
            }
1315
        );
1316
    }
1317
1318
    public function testDiffForHumansOtherAndFutureDay()
1319
    {
1320
        $scope = $this;
1321
        $this->wrapWithTestNow(
1322
            function () use ($scope) {
1323
                $scope->assertSame('1 day after', Date::now()->diffForHumans(Date::now()->subDay()));
1324
            }
1325
        );
1326
    }
1327
1328
    public function testDiffForHumansOtherAndFutureDays()
1329
    {
1330
        $scope = $this;
1331
        $this->wrapWithTestNow(
1332
            function () use ($scope) {
1333
                $scope->assertSame('2 days after', Date::now()->diffForHumans(Date::now()->subDays(2)));
1334
            }
1335
        );
1336
    }
1337
1338
    public function testDiffForHumansOtherAndNearlyFutureWeek()
1339
    {
1340
        $scope = $this;
1341
        $this->wrapWithTestNow(
1342
            function () use ($scope) {
1343
                $scope->assertSame('6 days after', Date::now()->diffForHumans(Date::now()->subDays(6)));
1344
            }
1345
        );
1346
    }
1347
1348
    public function testDiffForHumansOtherAndFutureWeek()
1349
    {
1350
        $scope = $this;
1351
        $this->wrapWithTestNow(
1352
            function () use ($scope) {
1353
                $scope->assertSame('1 week after', Date::now()->diffForHumans(Date::now()->subWeek()));
1354
            }
1355
        );
1356
    }
1357
1358
    public function testDiffForHumansOtherAndFutureWeeks()
1359
    {
1360
        $scope = $this;
1361
        $this->wrapWithTestNow(
1362
            function () use ($scope) {
1363
                $scope->assertSame('2 weeks after', Date::now()->diffForHumans(Date::now()->subWeeks(2)));
1364
            }
1365
        );
1366
    }
1367
1368
    public function testDiffForHumansOtherAndNearlyFutureMonth()
1369
    {
1370
        $scope = $this;
1371
        $this->wrapWithTestNow(
1372
            function () use ($scope) {
1373
                $scope->assertSame('3 weeks after', Date::now()->diffForHumans(Date::now()->subWeeks(3)));
1374
            }
1375
        );
1376
    }
1377
1378
    public function testDiffForHumansOtherAndFutureMonth()
1379
    {
1380
        $scope = $this;
1381
        $this->wrapWithTestNow(
1382
            function () use ($scope) {
1383
                $scope->assertSame('4 weeks after', Date::now()->diffForHumans(Date::now()->subWeeks(4)));
1384
                $scope->assertSame('1 month after', Date::now()->diffForHumans(Date::now()->subMonth()));
1385
            }
1386
        );
1387
    }
1388
1389
    public function testDiffForHumansOtherAndFutureMonths()
1390
    {
1391
        $scope = $this;
1392
        $this->wrapWithTestNow(
1393
            function () use ($scope) {
1394
                $scope->assertSame('2 months after', Date::now()->diffForHumans(Date::now()->subMonths(2)));
1395
            }
1396
        );
1397
    }
1398
1399
    public function testDiffForHumansOtherAndNearlyFutureYear()
1400
    {
1401
        $scope = $this;
1402
        $this->wrapWithTestNow(
1403
            function () use ($scope) {
1404
                $scope->assertSame('11 months after', Date::now()->diffForHumans(Date::now()->subMonths(11)));
1405
            }
1406
        );
1407
    }
1408
1409
    public function testDiffForHumansOtherAndFutureYear()
1410
    {
1411
        $scope = $this;
1412
        $this->wrapWithTestNow(
1413
            function () use ($scope) {
1414
                $scope->assertSame('1 year after', Date::now()->diffForHumans(Date::now()->subYear()));
1415
            }
1416
        );
1417
    }
1418
1419
    public function testDiffForHumansOtherAndFutureYears()
1420
    {
1421
        $scope = $this;
1422
        $this->wrapWithTestNow(
1423
            function () use ($scope) {
1424
                $scope->assertSame('2 years after', Date::now()->diffForHumans(Date::now()->subYears(2)));
1425
            }
1426
        );
1427
    }
1428
1429 View Code Duplication
    public function testDiffForHumansAbsoluteSeconds()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1430
    {
1431
        $scope = $this;
1432
        $this->wrapWithTestNow(
1433
            function () use ($scope) {
1434
                $scope->assertSame('59 seconds', Date::now()->diffForHumans(Date::now()->subSeconds(59), true));
1435
                $scope->assertSame('59 seconds', Date::now()->diffForHumans(Date::now()->addSeconds(59), true));
1436
            }
1437
        );
1438
    }
1439
1440 View Code Duplication
    public function testDiffForHumansAbsoluteMinutes()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1441
    {
1442
        $scope = $this;
1443
        $this->wrapWithTestNow(
1444
            function () use ($scope) {
1445
                $scope->assertSame('30 minutes', Date::now()->diffForHumans(Date::now()->subMinutes(30), true));
1446
                $scope->assertSame('30 minutes', Date::now()->diffForHumans(Date::now()->addMinutes(30), true));
1447
            }
1448
        );
1449
    }
1450
1451 View Code Duplication
    public function testDiffForHumansAbsoluteHours()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1452
    {
1453
        $scope = $this;
1454
        $this->wrapWithTestNow(
1455
            function () use ($scope) {
1456
                $scope->assertSame('3 hours', Date::now()->diffForHumans(Date::now()->subHours(3), true));
1457
                $scope->assertSame('3 hours', Date::now()->diffForHumans(Date::now()->addHours(3), true));
1458
            }
1459
        );
1460
    }
1461
1462 View Code Duplication
    public function testDiffForHumansAbsoluteDays()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1463
    {
1464
        $scope = $this;
1465
        $this->wrapWithTestNow(
1466
            function () use ($scope) {
1467
                $scope->assertSame('2 days', Date::now()->diffForHumans(Date::now()->subDays(2), true));
1468
                $scope->assertSame('2 days', Date::now()->diffForHumans(Date::now()->addDays(2), true));
1469
            }
1470
        );
1471
    }
1472
1473 View Code Duplication
    public function testDiffForHumansAbsoluteWeeks()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1474
    {
1475
        $scope = $this;
1476
        $this->wrapWithTestNow(
1477
            function () use ($scope) {
1478
                $scope->assertSame('2 weeks', Date::now()->diffForHumans(Date::now()->subWeeks(2), true));
1479
                $scope->assertSame('2 weeks', Date::now()->diffForHumans(Date::now()->addWeeks(2), true));
1480
            }
1481
        );
1482
    }
1483
1484 View Code Duplication
    public function testDiffForHumansAbsoluteMonths()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1485
    {
1486
        $scope = $this;
1487
        $this->wrapWithTestNow(
1488
            function () use ($scope) {
1489
                $scope->assertSame('2 months', Date::now()->diffForHumans(Date::now()->subMonths(2), true));
1490
                $scope->assertSame('2 months', Date::now()->diffForHumans(Date::now()->addMonths(2), true));
1491
            }
1492
        );
1493
    }
1494
1495 View Code Duplication
    public function testDiffForHumansAbsoluteYears()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1496
    {
1497
        $scope = $this;
1498
        $this->wrapWithTestNow(
1499
            function () use ($scope) {
1500
                $scope->assertSame('1 year', Date::now()->diffForHumans(Date::now()->subYears(1), true));
1501
                $scope->assertSame('1 year', Date::now()->diffForHumans(Date::now()->addYears(1), true));
1502
            }
1503
        );
1504
    }
1505
1506
    public function testDiffForHumansWithShorterMonthShouldStillBeAMonth()
1507
    {
1508
        $feb15 = Date::parse('2015-02-15');
1509
        $mar15 = Date::parse('2015-03-15');
1510
        $this->assertSame('1 month after', $mar15->diffForHumans($feb15));
1511
    }
1512
}
1513