|
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
|
|
|
use HMLB\Date\Tests\Date\Fixtures\MyDate; |
|
17
|
|
|
|
|
18
|
|
|
class StringsTest extends AbstractTestCase |
|
19
|
|
|
{ |
|
20
|
|
|
public function testToString() |
|
21
|
|
|
{ |
|
22
|
|
|
$d = Date::now(); |
|
23
|
|
|
$this->assertSame(Date::now()->toDateTimeString(), ''.$d); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function testSetToStringFormat() |
|
27
|
|
|
{ |
|
28
|
|
|
Date::setToStringFormat('jS \o\f F, Y g:i:s a'); |
|
29
|
|
|
$d = Date::create(1975, 12, 25, 14, 15, 16); |
|
30
|
|
|
$this->assertSame('25th of December, 1975 2:15:16 pm', ''.$d); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function testResetToStringFormat() |
|
34
|
|
|
{ |
|
35
|
|
|
$d = Date::now(); |
|
36
|
|
|
Date::setToStringFormat('123'); |
|
37
|
|
|
Date::resetToStringFormat(); |
|
38
|
|
|
$this->assertSame($d->toDateTimeString(), ''.$d); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function testExtendedClassToString() |
|
42
|
|
|
{ |
|
43
|
|
|
$d = MyDate::now(); |
|
44
|
|
|
$this->assertSame($d->toDateTimeString(), ''.$d); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function testToDateString() |
|
48
|
|
|
{ |
|
49
|
|
|
$d = Date::create(1975, 12, 25, 14, 15, 16); |
|
50
|
|
|
$this->assertSame('1975-12-25', $d->toDateString()); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function testToFormattedDateString() |
|
54
|
|
|
{ |
|
55
|
|
|
$d = Date::create(1975, 12, 25, 14, 15, 16); |
|
56
|
|
|
$this->assertSame('Dec 25, 1975', $d->toFormattedDateString()); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function testToLocalizedFormattedTimezonedDateString() |
|
60
|
|
|
{ |
|
61
|
|
|
$d = Date::create(1975, 12, 25, 14, 15, 16, 'Europe/London'); |
|
62
|
|
|
$this->assertSame('Thursday 25 December 1975 14:15', $d->formatLocalized('%A %d %B %Y %H:%M')); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function testToTimeString() |
|
66
|
|
|
{ |
|
67
|
|
|
$d = Date::create(1975, 12, 25, 14, 15, 16); |
|
68
|
|
|
$this->assertSame('14:15:16', $d->toTimeString()); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function testToDateTimeString() |
|
72
|
|
|
{ |
|
73
|
|
|
$d = Date::create(1975, 12, 25, 14, 15, 16); |
|
74
|
|
|
$this->assertSame('1975-12-25 14:15:16', $d->toDateTimeString()); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function testToDateTimeStringWithPaddedZeroes() |
|
78
|
|
|
{ |
|
79
|
|
|
$d = Date::create(2000, 5, 2, 4, 3, 4); |
|
80
|
|
|
$this->assertSame('2000-05-02 04:03:04', $d->toDateTimeString()); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function testToDayDateTimeString() |
|
84
|
|
|
{ |
|
85
|
|
|
$d = Date::create(1975, 12, 25, 14, 15, 16); |
|
86
|
|
|
$this->assertSame('Thu, Dec 25, 1975 2:15 PM', $d->toDayDateTimeString()); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function testToAtomString() |
|
90
|
|
|
{ |
|
91
|
|
|
$d = Date::create(1975, 12, 25, 14, 15, 16); |
|
92
|
|
|
$this->assertSame('1975-12-25T14:15:16-05:00', $d->toAtomString()); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public function testToCOOKIEString() |
|
96
|
|
|
{ |
|
97
|
|
|
$d = Date::create(1975, 12, 25, 14, 15, 16); |
|
98
|
|
|
if (Date::COOKIE === 'l, d-M-y H:i:s T') { |
|
99
|
|
|
$cookieString = 'Thursday, 25-Dec-75 14:15:16 EST'; |
|
100
|
|
|
} else { |
|
101
|
|
|
$cookieString = 'Thursday, 25-Dec-1975 14:15:16 EST'; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
$this->assertSame($cookieString, $d->toCOOKIEString()); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
public function testToIso8601String() |
|
108
|
|
|
{ |
|
109
|
|
|
$d = Date::create(1975, 12, 25, 14, 15, 16); |
|
110
|
|
|
$this->assertSame('1975-12-25T14:15:16-0500', $d->toIso8601String()); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
public function testToRC822String() |
|
114
|
|
|
{ |
|
115
|
|
|
$d = Date::create(1975, 12, 25, 14, 15, 16); |
|
116
|
|
|
$this->assertSame('Thu, 25 Dec 75 14:15:16 -0500', $d->toRfc822String()); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
public function testToRfc850String() |
|
120
|
|
|
{ |
|
121
|
|
|
$d = Date::create(1975, 12, 25, 14, 15, 16); |
|
122
|
|
|
$this->assertSame('Thursday, 25-Dec-75 14:15:16 EST', $d->toRfc850String()); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
public function testToRfc1036String() |
|
126
|
|
|
{ |
|
127
|
|
|
$d = Date::create(1975, 12, 25, 14, 15, 16); |
|
128
|
|
|
$this->assertSame('Thu, 25 Dec 75 14:15:16 -0500', $d->toRfc1036String()); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
public function testToRfc1123String() |
|
132
|
|
|
{ |
|
133
|
|
|
$d = Date::create(1975, 12, 25, 14, 15, 16); |
|
134
|
|
|
$this->assertSame('Thu, 25 Dec 1975 14:15:16 -0500', $d->toRfc1123String()); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
public function testToRfc2822String() |
|
138
|
|
|
{ |
|
139
|
|
|
$d = Date::create(1975, 12, 25, 14, 15, 16); |
|
140
|
|
|
$this->assertSame('Thu, 25 Dec 1975 14:15:16 -0500', $d->toRfc2822String()); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
public function testToRfc3339String() |
|
144
|
|
|
{ |
|
145
|
|
|
$d = Date::create(1975, 12, 25, 14, 15, 16); |
|
146
|
|
|
$this->assertSame('1975-12-25T14:15:16-05:00', $d->toRfc3339String()); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
public function testToRssString() |
|
150
|
|
|
{ |
|
151
|
|
|
$d = Date::create(1975, 12, 25, 14, 15, 16); |
|
152
|
|
|
$this->assertSame('Thu, 25 Dec 1975 14:15:16 -0500', $d->toRssString()); |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
public function testToW3cString() |
|
156
|
|
|
{ |
|
157
|
|
|
$d = Date::create(1975, 12, 25, 14, 15, 16); |
|
158
|
|
|
$this->assertSame('1975-12-25T14:15:16-05:00', $d->toW3cString()); |
|
159
|
|
|
} |
|
160
|
|
|
} |
|
161
|
|
|
|