Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added normalization (fixes #9)

  • Loading branch information...
commit 9e09a39d9e3ddbb6c38dbc2811c56b1d003a9bae 1 parent 5dc0212
@jmalloc jmalloc authored
View
97 lib-typhoon/Icecave/Chrono/TypeCheck/Validator/Icecave/Chrono/DateTimeTypeCheck.php
@@ -79,4 +79,101 @@ public function validateConstruct(array $arguments)
}
}
+ public function year(array $arguments)
+ {
+ if (\count($arguments) > 0) {
+ throw new \Icecave\Chrono\TypeCheck\Exception\UnexpectedArgumentException(0, $arguments[0]);
+ }
+ }
+
+ public function month(array $arguments)
+ {
+ if (\count($arguments) > 0) {
+ throw new \Icecave\Chrono\TypeCheck\Exception\UnexpectedArgumentException(0, $arguments[0]);
+ }
+ }
+
+ public function day(array $arguments)
+ {
+ if (\count($arguments) > 0) {
+ throw new \Icecave\Chrono\TypeCheck\Exception\UnexpectedArgumentException(0, $arguments[0]);
+ }
+ }
+
+ public function hours(array $arguments)
+ {
+ if (\count($arguments) > 0) {
+ throw new \Icecave\Chrono\TypeCheck\Exception\UnexpectedArgumentException(0, $arguments[0]);
+ }
+ }
+
+ public function minutes(array $arguments)
+ {
+ if (\count($arguments) > 0) {
+ throw new \Icecave\Chrono\TypeCheck\Exception\UnexpectedArgumentException(0, $arguments[0]);
+ }
+ }
+
+ public function seconds(array $arguments)
+ {
+ if (\count($arguments) > 0) {
+ throw new \Icecave\Chrono\TypeCheck\Exception\UnexpectedArgumentException(0, $arguments[0]);
+ }
+ }
+
+ public function toTimeZone(array $arguments)
+ {
+ $argumentCount = \count($arguments);
+ if ($argumentCount < 1) {
+ throw new \Icecave\Chrono\TypeCheck\Exception\MissingArgumentException('timeZone', 0, 'Icecave\\Chrono\\TimeZone');
+ } elseif ($argumentCount > 1) {
+ throw new \Icecave\Chrono\TypeCheck\Exception\UnexpectedArgumentException(1, $arguments[1]);
+ }
+ }
+
+ public function toUtc(array $arguments)
+ {
+ if (\count($arguments) > 0) {
+ throw new \Icecave\Chrono\TypeCheck\Exception\UnexpectedArgumentException(0, $arguments[0]);
+ }
+ }
+
+ public function timeZone(array $arguments)
+ {
+ if (\count($arguments) > 0) {
+ throw new \Icecave\Chrono\TypeCheck\Exception\UnexpectedArgumentException(0, $arguments[0]);
+ }
+ }
+
+ public function compare(array $arguments)
+ {
+ $argumentCount = \count($arguments);
+ if ($argumentCount < 1) {
+ throw new \Icecave\Chrono\TypeCheck\Exception\MissingArgumentException('timePoint', 0, 'Icecave\\Chrono\\TimePointInterface');
+ } elseif ($argumentCount > 1) {
+ throw new \Icecave\Chrono\TypeCheck\Exception\UnexpectedArgumentException(1, $arguments[1]);
+ }
+ }
+
+ public function unixTime(array $arguments)
+ {
+ if (\count($arguments) > 0) {
+ throw new \Icecave\Chrono\TypeCheck\Exception\UnexpectedArgumentException(0, $arguments[0]);
+ }
+ }
+
+ public function isoString(array $arguments)
+ {
+ if (\count($arguments) > 0) {
+ throw new \Icecave\Chrono\TypeCheck\Exception\UnexpectedArgumentException(0, $arguments[0]);
+ }
+ }
+
+ public function validateToString(array $arguments)
+ {
+ if (\count($arguments) > 0) {
+ throw new \Icecave\Chrono\TypeCheck\Exception\UnexpectedArgumentException(0, $arguments[0]);
+ }
+ }
+
}
View
17 lib-typhoon/Icecave/Chrono/TypeCheck/Validator/Icecave/Chrono/DateTypeCheck.php
@@ -67,6 +67,23 @@ public function day(array $arguments)
}
}
+ public function toTimeZone(array $arguments)
+ {
+ $argumentCount = \count($arguments);
+ if ($argumentCount < 1) {
+ throw new \Icecave\Chrono\TypeCheck\Exception\MissingArgumentException('timeZone', 0, 'Icecave\\Chrono\\TimeZone');
+ } elseif ($argumentCount > 1) {
+ throw new \Icecave\Chrono\TypeCheck\Exception\UnexpectedArgumentException(1, $arguments[1]);
+ }
+ }
+
+ public function toUtc(array $arguments)
+ {
+ if (\count($arguments) > 0) {
+ throw new \Icecave\Chrono\TypeCheck\Exception\UnexpectedArgumentException(0, $arguments[0]);
+ }
+ }
+
public function timeZone(array $arguments)
{
if (\count($arguments) > 0) {
View
17 lib-typhoon/Icecave/Chrono/TypeCheck/Validator/Icecave/Chrono/TimeTypeCheck.php
@@ -65,6 +65,23 @@ public function seconds(array $arguments)
}
}
+ public function toTimeZone(array $arguments)
+ {
+ $argumentCount = \count($arguments);
+ if ($argumentCount < 1) {
+ throw new \Icecave\Chrono\TypeCheck\Exception\MissingArgumentException('timeZone', 0, 'Icecave\\Chrono\\TimeZone');
+ } elseif ($argumentCount > 1) {
+ throw new \Icecave\Chrono\TypeCheck\Exception\UnexpectedArgumentException(1, $arguments[1]);
+ }
+ }
+
+ public function toUtc(array $arguments)
+ {
+ if (\count($arguments) > 0) {
+ throw new \Icecave\Chrono\TypeCheck\Exception\UnexpectedArgumentException(0, $arguments[0]);
+ }
+ }
+
public function timeZone(array $arguments)
{
if (\count($arguments) > 0) {
View
4 lib/Icecave/Chrono/Date.php
@@ -1,7 +1,7 @@
<?php
namespace Icecave\Chrono;
-use Icecave\Chrono\Support\UnixTime;
+use Icecave\Chrono\Support\Normalizer;
use Icecave\Chrono\TypeCheck\TypeCheck;
/**
@@ -23,6 +23,8 @@ public function __construct(
) {
$this->typeCheck = TypeCheck::get(__CLASS__, func_get_args());
+ Normalizer::normalizeDate($year, $month, $day);
+
if ($timeZone === null) {
$timeZone = new TimeZone;
}
View
5 lib/Icecave/Chrono/DateTime.php
@@ -1,7 +1,7 @@
<?php
namespace Icecave\Chrono;
-use Icecave\Chrono\Support\UnixTime;
+use Icecave\Chrono\Support\Normalizer;
use Icecave\Chrono\TypeCheck\TypeCheck;
/**
@@ -29,6 +29,9 @@ public function __construct(
) {
$this->typeCheck = TypeCheck::get(__CLASS__, func_get_args());
+ Normalizer::normalizeTime($hours, $minutes, $seconds, $day);
+ Normalizer::normalizeDate($year, $month, $day);
+
if ($timeZone === null) {
$timeZone = new TimeZone;
}
View
5 lib/Icecave/Chrono/Time.php
@@ -1,6 +1,7 @@
<?php
namespace Icecave\Chrono;
+use Icecave\Chrono\Support\Normalizer;
use Icecave\Chrono\TypeCheck\TypeCheck;
class Time implements TimeInterface
@@ -19,6 +20,8 @@ public function __construct(
) {
$this->typeCheck = TypeCheck::get(__CLASS__, func_get_args());
+ Normalizer::normalizeTime($hours, $minutes, $seconds);
+
if ($timeZone === null) {
$timeZone = new TimeZone;
}
@@ -128,7 +131,7 @@ public function isoString()
$this->typeCheck->isoString(func_get_args());
return sprintf(
- '%$02d:%02d:%02d',
+ '%02d:%02d:%02d',
$this->hours(),
$this->minutes(),
$this->seconds(),
View
6 test/suite/Icecave/Chrono/DateTest.php
@@ -11,6 +11,12 @@ public function setUp()
$this->_date = new Date(2013, 2, 1);
}
+ public function testNormalization()
+ {
+ $date = new Date(2013, 1, 32);
+ $this->assertSame('2013-02-01', $date->isoString());
+ }
+
public function testYear()
{
$this->assertSame(2013, $this->_date->year());
View
19 test/suite/Icecave/Chrono/DateTimeTest.php
@@ -0,0 +1,19 @@
+<?php
+namespace Icecave\Chrono;
+
+use Phake;
+use PHPUnit_Framework_TestCase;
+
+class DateTimeTest extends PHPUnit_Framework_TestCase
+{
+ public function setUp()
+ {
+ $this->_dateTime = new DateTime(2013, 2, 1, 10, 20, 30);
+ }
+
+ public function testNormalization()
+ {
+ $time = new DateTime(2013, 1, 32, 10, 20, 70);
+ $this->assertSame('2013-02-01 10:21:10+00:00', $time->isoString());
+ }
+}
View
19 test/suite/Icecave/Chrono/TimeTest.php
@@ -0,0 +1,19 @@
+<?php
+namespace Icecave\Chrono;
+
+use Phake;
+use PHPUnit_Framework_TestCase;
+
+class TimeTest extends PHPUnit_Framework_TestCase
+{
+ public function setUp()
+ {
+ $this->_time = new Time(10, 20, 30);
+ }
+
+ public function testNormalization()
+ {
+ $time = new Time(10, 20, 70);
+ $this->assertSame('10:21:10', $time->isoString());
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.