2 /* vim: set expandtab tabstop=4 shiftwidth=4: */
3 // +----------------------------------------------------------------------+
5 // +----------------------------------------------------------------------+
6 // | Copyright (c) 1997-2003 Leandro Lucarella |
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: Leandro Lucarella <llucax@php.net> |
17 // +----------------------------------------------------------------------+
22 require_once 'Date.php';
23 require_once 'Date/Span.php';
24 require_once 'PHPUnit/Autoload.php';
27 * Test case for Date_Span
30 * @author Leandro Lucarella <llucax@php.net>
32 class Date_SpanTest extends PHPUnit_Framework_TestCase
36 public function setUp()
38 $this->time = new Date_Span(97531);
41 public function tearDown()
46 public function testSetFromArray()
48 $this->time->setFromArray(array(5, 48.5, 28.5, 31));
61 public function testSetFromString()
63 $this->time->setFromString('5:00:59:31');
76 public function testSetFromSeconds()
78 $this->time->setFromSeconds(434344);
91 public function testSetFromMinutes()
93 $this->time->setFromMinutes(7860.0166666666);
106 public function testSetFromHours()
108 $this->time->setFromHours(50.12345);
121 public function testSetFromDays()
123 $this->time->setFromDays(pi());
136 public function testSetFromDateDiff()
138 $this->time->setFromDateDiff(
139 new Date('2004-03-10 01:15:59'),
140 new Date('2003-03-10 00:10:50')
154 public function testCopy()
156 $time = new Date_Span();
157 $time->copy($this->time);
176 public function testFormat()
179 'C' => '1, 03:05:31',
180 'd' => '1.1288310185185',
182 'e' => '27.091944444444',
183 'f' => '1625.5166666667',
194 'r' => '03:05:31 am',
202 foreach ($codes as $code => $expected) {
205 $this->time->format("$code: %$code")
210 public function testAdd()
212 $this->time->add(new Date_Span(6000));
213 $result = $this->time->toSeconds();
215 $this->assertEquals($expected, $result);
218 public function testSubtract()
220 $this->time->subtract(new Date_Span(6000));
221 $result = $this->time->toSeconds();
223 $this->assertEquals($expected, $result);