TimeTest.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. namespace Cmfcmf\OpenWeatherMap\Tests\Util;
  15. use Cmfcmf\OpenWeatherMap\Util\Time;
  16. class TimeTest extends \PHPUnit_Framework_TestCase
  17. {
  18. private function createDateTime($time)
  19. {
  20. return new \DateTime($time, new \DateTimeZone('UTC'));
  21. }
  22. public function testFromTo()
  23. {
  24. $fromS = '2014-01-01 08:00:00';
  25. $toS = '2014-01-01 20:00:00';
  26. $from = $this->createDateTime($fromS);
  27. $to = $this->createDateTime($toS);
  28. $day = $this->createDateTime('2014-01-01');
  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. $time = new Time($fromS, $toS);
  34. $this->assertSame($from->format('c'), $time->from->format('c'));
  35. $this->assertSame($to->format('c'), $time->to->format('c'));
  36. $this->assertSame($day->format('c'), $time->day->format('c'));
  37. }
  38. public function testFrom()
  39. {
  40. $fromS = '2014-01-01 00:00:00';
  41. $from = $this->createDateTime($fromS);
  42. $day = $this->createDateTime('2014-01-01');
  43. $to = $this->createDateTime('2014-01-01 23:59:59');
  44. $time = new Time($from);
  45. $this->assertSame($from->format('c'), $time->from->format('c'));
  46. $this->assertSame($to->format('c'), $time->to->format('c'));
  47. $this->assertSame($day->format('c'), $time->day->format('c'));
  48. $time = new Time($fromS);
  49. $this->assertSame($from->format('c'), $time->from->format('c'));
  50. $this->assertSame($to->format('c'), $time->to->format('c'));
  51. $this->assertSame($day->format('c'), $time->day->format('c'));
  52. }
  53. }