Skip to content

Commit 62e6497

Browse files
committed
Test time.
1 parent 4bbf1da commit 62e6497

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

Cmfcmf/OpenWeatherMap/Util/Time.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function __construct($from, $to = null)
5353
$day = new \DateTime($from->format('Y-m-d'));
5454
} else {
5555
$from = ($from instanceof \DateTime) ? $from : new \DateTime((string)$from);
56-
$day = clone $from;
56+
$day = $from = new \DateTime($from->format('Y-m-d'));
5757
$to = clone $from;
5858
$to = $to->add(new \DateInterval('PT23H59M59S'));
5959
}

tests/Util/TimeTest.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
/**
3+
* Copyright Zikula Foundation 2014 - Zikula Application Framework
4+
*
5+
* This work is contributed to the Zikula Foundation under one or more
6+
* Contributor Agreements and licensed to You under the following license:
7+
*
8+
* @license GNU/LGPv3 (or at your option any later version).
9+
* @package OpenWeatherMap-PHP-Api
10+
*
11+
* Please see the NOTICE file distributed with this source code for further
12+
* information regarding copyright and licensing.
13+
*/
14+
15+
namespace Cmfcmf\OpenWeatherMap\Tests\Util;
16+
17+
use Cmfcmf\OpenWeatherMap\Util\Time;
18+
19+
class TimeTest extends \PHPUnit_Framework_TestCase
20+
{
21+
public function testFromTo()
22+
{
23+
$fromS = '2014-01-01 08:00:00';
24+
$toS = '2014-01-01 20:00:00';
25+
$from = new \DateTime($fromS);
26+
$to = new \DateTime($toS);
27+
$day = new \DateTime('2014-01-01');
28+
29+
$time = new Time($from, $to);
30+
$this->assertSame($from->format('c'), $time->from->format('c'));
31+
$this->assertSame($to->format('c'), $time->to->format('c'));
32+
$this->assertSame($day->format('c'), $time->day->format('c'));
33+
34+
$time = new Time($fromS, $toS);
35+
$this->assertSame($from->format('c'), $time->from->format('c'));
36+
$this->assertSame($to->format('c'), $time->to->format('c'));
37+
$this->assertSame($day->format('c'), $time->day->format('c'));
38+
}
39+
public function testFrom()
40+
{
41+
$fromS = '2014-01-01 00:00:00';
42+
$from = new \DateTime($fromS);
43+
$day = new \DateTime('2014-01-01');
44+
$to = new \DateTime('2014-01-01 23:59:59');
45+
46+
$time = new Time($from);
47+
$this->assertSame($from->format('c'), $time->from->format('c'));
48+
$this->assertSame($to->format('c'), $time->to->format('c'));
49+
$this->assertSame($day->format('c'), $time->day->format('c'));
50+
51+
$time = new Time($fromS);
52+
$this->assertSame($from->format('c'), $time->from->format('c'));
53+
$this->assertSame($to->format('c'), $time->to->format('c'));
54+
$this->assertSame($day->format('c'), $time->day->format('c'));
55+
}
56+
}

0 commit comments

Comments
 (0)