Eric Barnes | 5d1e32b | 2011-05-03 22:28:59 -0400 | [diff] [blame] | 1 | <?php |
| 2 | require_once BASEPATH.'helpers/date_helper.php'; |
| 3 | |
| 4 | class 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'; |
Eric Barnes | 71644d6 | 2011-07-12 21:45:40 -0400 | [diff] [blame] | 29 | $expected = date("D, d M y H:i:s O", $time); |
Eric Barnes | 5d1e32b | 2011-05-03 22:28:59 -0400 | [diff] [blame] | 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 | { |
Greg Aker | 2e0f825 | 2011-08-21 16:19:16 -0500 | [diff] [blame^] | 161 | $time = time(); |
| 162 | $this->assertEquals($time, |
| 163 | mysql_to_unix(date("Y-m-d H:i:s", $time))); |
Eric Barnes | 5d1e32b | 2011-05-03 22:28:59 -0400 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | // ------------------------------------------------------------------------ |
| 167 | |
| 168 | public function test_unix_to_human() |
| 169 | { |
| 170 | $time = time(); |
Greg Aker | 2e0f825 | 2011-08-21 16:19:16 -0500 | [diff] [blame^] | 171 | $this->assertEquals(date("Y-m-d h:i A", $time), unix_to_human($time)); |
| 172 | $this->assertEquals(date("Y-m-d h:i:s A", $time), unix_to_human($time, TRUE, 'us')); |
| 173 | $this->assertEquals(date("Y-m-d H:i:s", $time), unix_to_human($time, TRUE, 'eu')); |
Eric Barnes | 5d1e32b | 2011-05-03 22:28:59 -0400 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | // ------------------------------------------------------------------------ |
| 177 | |
| 178 | public function test_human_to_unix() |
| 179 | { |
| 180 | $time = time(); |
| 181 | $this->markTestIncomplete('Failed Test'); |
| 182 | // $this->assertEquals($time, human_to_unix(unix_to_human($time))); |
| 183 | } |
| 184 | |
| 185 | // ------------------------------------------------------------------------ |
| 186 | |
| 187 | public function test_timezones() |
| 188 | { |
| 189 | $zones = array( |
| 190 | 'UM12' => -12, |
| 191 | 'UM11' => -11, |
| 192 | 'UM10' => -10, |
| 193 | 'UM95' => -9.5, |
| 194 | 'UM9' => -9, |
| 195 | 'UM8' => -8, |
| 196 | 'UM7' => -7, |
| 197 | 'UM6' => -6, |
| 198 | 'UM5' => -5, |
| 199 | 'UM45' => -4.5, |
| 200 | 'UM4' => -4, |
| 201 | 'UM35' => -3.5, |
| 202 | 'UM3' => -3, |
| 203 | 'UM2' => -2, |
| 204 | 'UM1' => -1, |
| 205 | 'UTC' => 0, |
| 206 | 'UP1' => +1, |
| 207 | 'UP2' => +2, |
| 208 | 'UP3' => +3, |
| 209 | 'UP35' => +3.5, |
| 210 | 'UP4' => +4, |
| 211 | 'UP45' => +4.5, |
| 212 | 'UP5' => +5, |
| 213 | 'UP55' => +5.5, |
| 214 | 'UP575' => +5.75, |
| 215 | 'UP6' => +6, |
| 216 | 'UP65' => +6.5, |
| 217 | 'UP7' => +7, |
| 218 | 'UP8' => +8, |
| 219 | 'UP875' => +8.75, |
| 220 | 'UP9' => +9, |
| 221 | 'UP95' => +9.5, |
| 222 | 'UP10' => +10, |
| 223 | 'UP105' => +10.5, |
| 224 | 'UP11' => +11, |
| 225 | 'UP115' => +11.5, |
| 226 | 'UP12' => +12, |
| 227 | 'UP1275' => +12.75, |
| 228 | 'UP13' => +13, |
| 229 | 'UP14' => +14 |
| 230 | ); |
| 231 | |
| 232 | foreach ($zones AS $test => $expected) |
| 233 | { |
| 234 | $this->assertEquals($expected, timezones($test)); |
| 235 | } |
| 236 | |
| 237 | $this->assertArrayHasKey('UP3', timezones()); |
| 238 | $this->assertEquals(0, timezones('non_existant')); |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | /* End of file date_helper_test.php */ |