-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGrapeTest.php
109 lines (105 loc) · 3.58 KB
/
GrapeTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
declare(strict_types=1);
namespace Coswat\Grapes\Test;
use PHPUnit\Framework\TestCase;
use Coswat\Grapes\Grape;
class GrapeTest extends TestCase
{
public function test_toYear_function(): void
{
$year = Grape::time(1687350065)->toYear();
$expected = 2023;
$this->assertEquals($expected, $year);
}
public function test_toMonth_function(): void
{
$month = Grape::time(1687350065)->toMonth();
$expected = "June";
$this->assertEquals($expected, $month);
}
public function test_toDay_function(): void
{
$day = Grape::time(1687350065)->toDay();
$expected = "Wednesday";
$this->assertEquals($expected, $day);
}
public function test_getTimezone_function(): void
{
$ip = "8.8.8.8";
$timeZone = Grape::getTimezone($ip);
$expected = "America/New_York";
$this->assertEquals($expected, $timeZone);
}
public function test_toTime_function(): void
{
$time = Grape::time(1687350065)->toTime();
$expected = '12:21:05';
$this->assertEquals($expected, $time);
}
public function test_toRaw_function(): void
{
$time = Grape::time(1687350065)->toRaw();
$expected = '2023-06-21 12:21:05';
$this->assertEquals($expected, $time);
}
public function test_nextDay_function(): void
{
$time = Grape::time(1687350065)->nextDay();
$expected = '2023-06-22 12:21:05';
$this->assertEquals($expected, $time);
// check with unix timestamp also
$time = Grape::time(1687350065)->nextDay(true);
$expected = '1687436465';
$this->assertEquals($expected, $time);
}
public function test_nextWeek_function(): void
{
$time = Grape::time(1687350065)->nextWeek();
$expected = '2023-06-28 12:21:05';
$this->assertEquals($expected, $time);
// check with unix timestamp also
$time = Grape::time(1687350065)->nextWeek(true);
$expected = '1687954865';
$this->assertEquals($expected, $time);
}
public function test_nextMonth_function(): void
{
$time = Grape::time(1687350065)->nextMonth();
$expected = '2023-07-21 12:21:05';
$this->assertEquals($expected, $time);
// check with unix timestamp also
$time = Grape::time(1687350065)->nextMonth(true);
$expected = '1689942065';
$this->assertEquals($expected, $time);
}
public function test_addDays_function(): void
{
$time = Grape::time(1687350065)->addDays(17);
$expected = '2023-07-08 12:21:05';
$this->assertEquals($expected, $time);
// check with unix timestamp also
$time = Grape::time(1687350065)->addDays(17, true);
$expected = '1688818865';
$this->assertEquals($expected, $time);
}
public function test_addWeeks_function(): void
{
$time = Grape::time(1687350065)->addWeeks(7);
$expected = '2023-08-09 12:21:05';
$this->assertEquals($expected, $time);
// check with unix timestamp also
$time = Grape::time(1687350065)->addWeeks(7, true);
$expected = '1691583665';
$this->assertEquals($expected, $time);
}
public function test_addMonths_function(): void
{
$time = Grape::time(1687350065)->addMonths(8);
$expected = '2024-02-21 12:21:05';
$this->assertEquals($expected, $time);
// check with unix timestamp also
$time = Grape::time(1687350065)->addMonths(8, true);
$expected = '1708518065';
$this->assertEquals($expected, $time);
}
}