Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added CommonInterface and readded Date::timeZone() (fixes #6, #8).

  • Loading branch information...
commit 5820c64619abd30d989e8bd584fe6e007bb5f040 1 parent 373f328
@jmalloc jmalloc authored
View
18 lib-typhoon/Icecave/Chrono/TypeCheck/Validator/Icecave/Chrono/DateTypeCheck.php
@@ -14,8 +14,8 @@ public function validateConstruct(array $arguments)
throw new \Icecave\Chrono\TypeCheck\Exception\MissingArgumentException('month', 1, 'integer');
}
throw new \Icecave\Chrono\TypeCheck\Exception\MissingArgumentException('day', 2, 'integer');
- } elseif ($argumentCount > 3) {
- throw new \Icecave\Chrono\TypeCheck\Exception\UnexpectedArgumentException(3, $arguments[3]);
+ } elseif ($argumentCount > 4) {
+ throw new \Icecave\Chrono\TypeCheck\Exception\UnexpectedArgumentException(4, $arguments[4]);
}
$value = $arguments[0];
if (!\is_int($value)) {
@@ -67,6 +67,13 @@ public function day(array $arguments)
}
}
+ 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);
@@ -77,6 +84,13 @@ public function compare(array $arguments)
}
}
+ 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) {
View
2  lib/Icecave/Chrono/Clock/AbstractClock.php
@@ -55,7 +55,7 @@ public function localDate()
list($seconds, $minutes, $hours, $day, $month, $year) = $this->localTimeInfo();
- return new Date($year, $month, $day);
+ return new Date($year, $month, $day, $this->timeZone());
}
/**
View
25 lib/Icecave/Chrono/CommonInterface.php
@@ -0,0 +1,25 @@
+<?php
+namespace Icecave\Chrono;
+
+/**
+ * Base interface for all measures of dates and/or times.
+ */
+interface CommonInterface extends Iso8601Interface
+{
+ // /**
+ // * @param TimeZone $timeZone
+ // *
+ // * @return ComponentInterface
+ // */
+ // public function toTimeZone(TimeZone $timeZone);
+ //
+ // /**
+ // * @return ComponentInterface
+ // */
+ // public function toUtc();
+
+ /**
+ * @return TimeZone The time zone of the time point.
+ */
+ public function timeZone();
+}
View
31 lib/Icecave/Chrono/Date.php
@@ -10,17 +10,27 @@
class Date implements TimePointInterface
{
/**
- * @param integer $year The year component of the date.
- * @param integer $month The month component of the date.
- * @param integer $day The day component of the date.
+ * @param integer $year The year component of the date.
+ * @param integer $month The month component of the date.
+ * @param integer $day The day component of the date.
+ * @param TimeZone|null $timeZone The time zone of the time, or null to use UTC.
*/
- public function __construct($year, $month, $day)
- {
+ public function __construct(
+ $year,
+ $month,
+ $day,
+ TimeZone $timeZone = null
+ ) {
$this->typeCheck = TypeCheck::get(__CLASS__, func_get_args());
+ if ($timeZone === null) {
+ $timeZone = new TimeZone;
+ }
+
$this->year = $year;
$this->month = $month;
$this->day = $day;
+ $this->timeZone = $timeZone;
}
/**
@@ -54,6 +64,16 @@ public function day()
}
/**
+ * @return TimeZone The time zone of the time.
+ */
+ public function timeZone()
+ {
+ $this->typeCheck->timeZone(func_get_args());
+
+ return $this->timeZone;
+ }
+
+ /**
* Perform a {@see strcmp} style comparison with another time point.
*
* @param TimePointInterface $timePoint The time point to compare.
@@ -121,4 +141,5 @@ public function __toString()
private $year;
private $month;
private $day;
+ private $timeZone;
}
View
2  lib/Icecave/Chrono/DateInterface.php
@@ -4,7 +4,7 @@
/**
* Base interface for all measures that contain a date.
*/
-interface DateInterface extends Iso8601Interface
+interface DateInterface extends CommonInterface
{
/**
* @return integer The year component of the date.
View
19 lib/Icecave/Chrono/TimeInterface.php
@@ -4,7 +4,7 @@
/**
* Base interface for all measures that contain a time.
*/
-interface TimeInterface extends Iso8601Interface
+interface TimeInterface extends CommonInterface
{
/**
* @return integer The hours component of the time.
@@ -20,21 +20,4 @@ public function minutes();
* @return integer The seconds component of the time.
*/
public function seconds();
-
- // /**
- // * @param TimeZone $timeZone
- // *
- // * @return ComponentInterface
- // */
- // public function toTimeZone(TimeZone $timeZone);
- //
- // /**
- // * @return ComponentInterface
- // */
- // public function toUtc();
-
- /**
- * @return TimeZone The time zone of the time point.
- */
- public function timeZone();
}
View
2  test/suite/Icecave/Chrono/Clock/AbstractClockTest.php
@@ -66,7 +66,7 @@ public function testLocalDateTime()
public function testLocalDate()
{
$result = $this->_clock->localDate();
- $expected = new Date(2013, 11, 20);
+ $expected = new Date(2013, 11, 20, $this->_timeZone);
$this->assertEquals($expected, $result);
$this->verifyLocalClockSuspended();
View
9 test/suite/Icecave/Chrono/DateTest.php
@@ -26,6 +26,15 @@ public function testDay()
$this->assertSame(1, $this->_date->day());
}
+ public function testTimeZone()
+ {
+ $this->assertTrue($this->_date->timeZone()->isUtc());
+
+ $timeZone = new TimeZone(36000, true);
+ $date = new Date(2013, 2, 1, $timeZone);
+ $this->assertSame($timeZone, $date->timeZone());
+ }
+
public function testCompareSelf()
{
$this->assertSame(0, $this->_date->compare($this->_date));
Please sign in to comment.
Something went wrong with that request. Please try again.