2 // vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4:
3 // +----------------------------------------------------------------------+
5 // +----------------------------------------------------------------------+
6 // | Copyright (c) 1997-2003 Marshall Roch |
7 // +----------------------------------------------------------------------+
8 // | This source file is subject to the New BSD license, That is bundled |
9 // | with this package in the file LICENSE, and is available through |
10 // | the world-wide-web at |
11 // | http://www.opensource.org/licenses/bsd-license.php |
12 // | If you did not receive a copy of the new BSDlicense and are unable |
13 // | to obtain it through the world-wide-web, please send a note to |
14 // | pear-dev@lists.php.net so we can mail you a copy immediately. |
15 // +----------------------------------------------------------------------+
16 // | Author: Marshall Roch <mroch@php.net> |
17 // +----------------------------------------------------------------------+
22 require_once 'Date.php';
23 require_once 'PHPUnit/Autoload.php';
25 class myDate extends Date
27 public function myDate($date)
37 * @author Marshall Roch <mroch@php.net>
39 class Date_Test extends PHPUnit_Framework_TestCase
43 public function setUp()
45 $this->time = new Date("2003-10-04 14:03:24Z");
48 public function tearDown()
53 public function testDateNull()
59 '%04d-%02d-%02d %02d:%02d:%02d',
70 public function testAbstraction()
74 $this->assertEquals($d->getDate(), $my->getDate());
77 public function testDateCopy()
79 $temp = new Date($this->time);
80 $this->assertEquals($temp, $this->time);
83 public function testDateISO()
85 $temp = new Date("2003-10-04 14:03:24");
87 '2003-10-04 14:03:24',
89 '%04d-%02d-%02d %02d:%02d:%02d',
100 public function testDateISOBasic()
102 $temp = new Date("20031004T140324");
104 '2003-10-04 14:03:24',
106 '%04d-%02d-%02d %02d:%02d:%02d',
117 public function testDateISOExtended()
119 $temp = new Date("2003-10-04T14:03:24");
121 '2003-10-04 14:03:24',
123 '%04d-%02d-%02d %02d:%02d:%02d',
134 public function testDateISOTimestamp()
136 $temp = new Date("20031004140324");
138 '2003-10-04 14:03:24',
140 '%04d-%02d-%02d %02d:%02d:%02d',
151 public function testDateUnixtime()
154 $temp->setTZbyID("UTC");
155 $temp->setDate(strtotime("2003-10-04 14:03:24Z"));
157 '2003-10-04 14:03:24',
159 '%04d-%02d-%02d %02d:%02d:%02d',
170 public function testDateUnixtime2()
173 $temp->setTZbyID("UTC-05:30");
174 $temp->setDate(strtotime("2003-10-04 14:03:24Z"));
175 $temp->convertTZbyID("UTC");
177 '2003-10-04 14:03:24',
179 '%04d-%02d-%02d %02d:%02d:%02d',
190 public function testDateUnixtime3()
193 $temp->setTZbyID("America/Chicago");
194 $temp->setDate(strtotime("2003-10-04 14:03:24Z"));
195 $temp->convertTZbyID("UTC");
197 '2003-10-04 14:03:24',
199 '%04d-%02d-%02d %02d:%02d:%02d',
210 public function testDateUnixtime4()
213 $temp->setTZbyID("Europe/London");
214 $temp->setDate(strtotime("2003-10-04 14:03:24Z")); // Summer time in London
215 $temp->setTZbyID("UTC");
217 '2003-10-04 15:03:24', // Preserves London local time (15.03)
219 '%04d-%02d-%02d %02d:%02d:%02d',
230 public function testSetDateISO()
232 $this->time->setDate("2003-10-04 14:03:24");
234 '2003-10-04 14:03:24',
236 '%04d-%02d-%02d %02d:%02d:%02d',
247 public function testSetDateISOBasic()
249 $this->time->setDate("20031004T140324");
251 '2003-10-04 14:03:24',
253 '%04d-%02d-%02d %02d:%02d:%02d',
264 public function testSetDateISOExtended()
266 $this->time->setDate("2003-10-04T14:03:24");
268 '2003-10-04 14:03:24',
270 '%04d-%02d-%02d %02d:%02d:%02d',
281 public function testSetDateTimestamp()
283 $this->time->setDate("20031004140324");
285 '2003-10-04 14:03:24',
287 '%04d-%02d-%02d %02d:%02d:%02d',
298 public function testSetDateUnixtime()
300 $this->time->setDate(strtotime("2003-10-04 14:03:24Z"));
302 '2003-10-04 14:03:24',
304 '%04d-%02d-%02d %02d:%02d:%02d',
315 public function testSetDateUnixtime2()
317 $hs_oldtz = $this->time->getTZID();
318 $this->time->setTZbyID("UTC-05:30");
319 $this->time->setDate(strtotime("2003-10-04 14:03:24Z"));
320 $this->time->convertTZbyID($hs_oldtz);
322 '2003-10-04 14:03:24',
324 '%04d-%02d-%02d %02d:%02d:%02d',
335 public function testSetDateUnixtime3()
337 $hs_oldtz = $this->time->getTZID();
338 $this->time->setTZbyID("America/Chicago");
339 $this->time->setDate(strtotime("2003-10-04 14:03:24Z"));
340 $this->time->convertTZbyID($hs_oldtz);
342 '2003-10-04 14:03:24',
344 '%04d-%02d-%02d %02d:%02d:%02d',
355 public function testGetDateISO()
357 $date = $this->time->getDate(DATE_FORMAT_ISO);
358 $this->assertEquals('2003-10-04 14:03:24', $date);
361 public function testGetDateISOBasic()
363 $date = $this->time->getDate(DATE_FORMAT_ISO_BASIC);
364 $this->assertEquals('20031004T140324Z', $date);
367 public function testGetDateISOExtended()
369 $date = $this->time->getDate(DATE_FORMAT_ISO_EXTENDED);
370 $this->assertEquals('2003-10-04T14:03:24Z', $date);
373 public function testGetDateTimestamp()
375 $date = $this->time->getDate(DATE_FORMAT_TIMESTAMP);
376 $this->assertEquals('20031004140324', $date);
379 public function testGetDateUnixtime()
381 $date = $this->time->getDate(DATE_FORMAT_UNIXTIME);
382 $this->assertEquals(strtotime('2003-10-04 14:03:24Z'), $date);
385 public function testGetDateUnixtime2()
387 $hs_oldtz = $this->time->getTZID();
388 $this->time->convertTZbyID("UTC-05:30");
389 $date = $this->time->getDate(DATE_FORMAT_UNIXTIME);
390 $this->assertEquals(strtotime('2003-10-04 14:03:24Z'), $date);
391 $this->time->convertTZbyID($hs_oldtz);
394 public function testGetDateUnixtime3()
396 $hs_oldtz = $this->time->getTZID();
397 $this->time->convertTZbyID("America/Chicago");
398 $date = $this->time->getDate(DATE_FORMAT_UNIXTIME);
399 $this->assertEquals(strtotime('2003-10-04 14:03:24Z'), $date);
400 $this->time->convertTZbyID($hs_oldtz);
403 public function testFormatLikeStrftime()
424 'r' => '02:03:24 PM',
436 foreach ($codes as $code => $expected) {
439 $this->time->formatLikeStrftime("$code: %$code")
444 public function testToUTCbyOffset()
446 $this->time->setTZbyID('EST');
447 $this->time->toUTC();
448 $temp = new Date("2003-10-04 14:03:24");
449 $temp->toUTCbyOffset("-05:00");
451 $this->assertEquals($temp, $this->time);