blob: f6048c32436c5ed10f73e366e1799792be840104 [file] [log] [blame]
Eric Barnes5d1e32b2011-05-03 22:28:59 -04001<?php
2require_once BASEPATH.'helpers/date_helper.php';
3
4class Date_helper_test extends CI_TestCase
5{
6 // ------------------------------------------------------------------------
7
8 public function test_now()
9 {
10 $this->markTestIncomplete('not implemented yet');
11 }
12
13 // ------------------------------------------------------------------------
14
15 public function test_mdate()
16 {
17 $time = time();
18 $expected = date("Y-m-d - h:i a", $time);
19 $test = mdate("%Y-%m-%d - %h:%i %a", $time);
20 $this->assertEquals($expected, $test);
21 }
22
23 // ------------------------------------------------------------------------
24
25 public function test_standard_date_rfc822()
26 {
27 $time = time();
28 $format = 'DATE_RFC822';
29 $expected = date("D, d F y G:i:s O", $time);
30 $this->assertEquals($expected, standard_date($format, $time));
31 }
32
33 // ------------------------------------------------------------------------
34
35 public function test_standard_date_atom()
36 {
37 $time = time();
38 $format = 'DATE_ATOM';
39 $expected = date("Y-m-d\TH:i:sO", $time);
40 $this->assertEquals($expected, standard_date($format, $time));
41 }
42
43 // ------------------------------------------------------------------------
44
45 public function test_standard_date_cookie()
46 {
47 $time = time();
48 $format = 'DATE_COOKIE';
49 $expected = date("l, d-M-y H:i:s \U\T\C", $time);
50 $this->assertEquals($expected, standard_date($format, $time));
51 }
52
53 // ------------------------------------------------------------------------
54
55 public function test_standard_date_iso8601()
56 {
57 $time = time();
58 $format = 'DATE_ISO8601';
59 $expected = date("Y-m-d\TH:i:sO", $time);
60 $this->assertEquals($expected, standard_date($format, $time));
61 }
62
63 // ------------------------------------------------------------------------
64
65 public function test_standard_date_rfc850()
66 {
67 $time = time();
68 $format = 'DATE_RFC850';
69 $expected = date("l, d-M-y H:i:s \U\T\C", $time);
70 $this->assertEquals($expected, standard_date($format, $time));
71 }
72
73 // ------------------------------------------------------------------------
74
75 public function test_standard_date_rfc1036()
76 {
77 $time = time();
78 $format = 'DATE_RFC1036';
79 $expected = date("D, d M y H:i:s O", $time);
80 $this->assertEquals($expected, standard_date($format, $time));
81 }
82
83 // ------------------------------------------------------------------------
84
85 public function test_standard_date_rfc1123()
86 {
87 $time = time();
88 $format = 'DATE_RFC1123';
89 $expected = date("D, d M Y H:i:s O", $time);
90 $this->assertEquals($expected, standard_date($format, $time));
91 }
92
93 // ------------------------------------------------------------------------
94
95 public function test_standard_date_rfc2822()
96 {
97 $time = time();
98 $format = 'DATE_RFC2822';
99 $expected = date("D, d M Y H:i:s O", $time);
100 $this->assertEquals($expected, standard_date($format, $time));
101 }
102
103 // ------------------------------------------------------------------------
104
105 public function test_standard_date_rss()
106 {
107 $time = time();
108 $format = 'DATE_RSS';
109 $expected = date("D, d M Y H:i:s O", $time);
110 $this->assertEquals($expected, standard_date($format, $time));
111 }
112
113 // ------------------------------------------------------------------------
114
115 public function test_standard_date_w3c()
116 {
117 $time = time();
118 $format = 'DATE_W3C';
119 $expected = date("Y-m-d\TH:i:sO", $time);
120 $this->assertEquals($expected, standard_date($format, $time));
121 }
122
123 // ------------------------------------------------------------------------
124
125 public function test_timespan()
126 {
127 $this->markTestIncomplete('not implemented yet');
128 }
129
130 // ------------------------------------------------------------------------
131
132 public function test_days_in_month()
133 {
134 $this->assertEquals(30, days_in_month(06, 2005));
135 $this->assertEquals(28, days_in_month(02, 2011));
136 $this->assertEquals(29, days_in_month(02, 2012));
137 }
138
139 // ------------------------------------------------------------------------
140
141 public function test_local_to_gmt()
142 {
143 $this->markTestIncomplete('not implemented yet');
144 }
145
146 // ------------------------------------------------------------------------
147
148 public function test_gmt_to_local()
149 {
150 $timestamp = '1140153693';
151 $timezone = 'UM8';
152 $daylight_saving = TRUE;
153
154 $this->assertEquals(1140128493, gmt_to_local($timestamp, $timezone, $daylight_saving));
155 }
156
157 // ------------------------------------------------------------------------
158
159 public function test_mysql_to_unix()
160 {
161 $this->assertEquals(1164378225, mysql_to_unix(20061124092345));
162 }
163
164 // ------------------------------------------------------------------------
165
166 public function test_unix_to_human()
167 {
168 $time = time();
169 $this->assertEquals(date("Y-m-d h:i A"), unix_to_human($time));
170 $this->assertEquals(date("Y-m-d h:i:s A"), unix_to_human($time, TRUE, 'us'));
171 $this->assertEquals(date("Y-m-d H:i:s"), unix_to_human($time, TRUE, 'eu'));
172 }
173
174 // ------------------------------------------------------------------------
175
176 public function test_human_to_unix()
177 {
178 $time = time();
179 $this->markTestIncomplete('Failed Test');
180 // $this->assertEquals($time, human_to_unix(unix_to_human($time)));
181 }
182
183 // ------------------------------------------------------------------------
184
185 public function test_timezones()
186 {
187 $zones = array(
188 'UM12' => -12,
189 'UM11' => -11,
190 'UM10' => -10,
191 'UM95' => -9.5,
192 'UM9' => -9,
193 'UM8' => -8,
194 'UM7' => -7,
195 'UM6' => -6,
196 'UM5' => -5,
197 'UM45' => -4.5,
198 'UM4' => -4,
199 'UM35' => -3.5,
200 'UM3' => -3,
201 'UM2' => -2,
202 'UM1' => -1,
203 'UTC' => 0,
204 'UP1' => +1,
205 'UP2' => +2,
206 'UP3' => +3,
207 'UP35' => +3.5,
208 'UP4' => +4,
209 'UP45' => +4.5,
210 'UP5' => +5,
211 'UP55' => +5.5,
212 'UP575' => +5.75,
213 'UP6' => +6,
214 'UP65' => +6.5,
215 'UP7' => +7,
216 'UP8' => +8,
217 'UP875' => +8.75,
218 'UP9' => +9,
219 'UP95' => +9.5,
220 'UP10' => +10,
221 'UP105' => +10.5,
222 'UP11' => +11,
223 'UP115' => +11.5,
224 'UP12' => +12,
225 'UP1275' => +12.75,
226 'UP13' => +13,
227 'UP14' => +14
228 );
229
230 foreach ($zones AS $test => $expected)
231 {
232 $this->assertEquals($expected, timezones($test));
233 }
234
235 $this->assertArrayHasKey('UP3', timezones());
236 $this->assertEquals(0, timezones('non_existant'));
237 }
238}
239
240/* End of file date_helper_test.php */