Skip to content

Commit

Permalink
Implemented #9
Browse files Browse the repository at this point in the history
  • Loading branch information
olvlvl committed Aug 23, 2016
1 parent 111cf25 commit bf4f4b9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
22 changes: 22 additions & 0 deletions lib/DateTime/Readers.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace ICanBoogie\DateTime;

use ICanBoogie\DateTime;
use ICanBoogie\MutableDateTime;
use ICanBoogie\PropertyNotDefined;
use ICanBoogie\TimeZone;

Expand Down Expand Up @@ -69,6 +70,9 @@
* @property-read bool $is_utc `true` if the instance is in the UTC timezone.
* @property-read bool $is_local `true` if the instance is in the local timezone.
* @property-read bool $is_dst `true` if time occurs during Daylight Saving Time in its time zone.
*
* @property-read DateTime $immutable An immutable representation of the instance.
* @property-read MutableDateTime $mutable A mutable representation of the instance.
*/
trait Readers
{
Expand Down Expand Up @@ -148,6 +152,8 @@ public function __get($property)
case 'sunday':
case 'tomorrow':
case 'yesterday':
case 'mutable':
case 'immutable':
return $this->{ 'get_' . $property }();

case 'zone':
Expand Down Expand Up @@ -279,4 +285,20 @@ protected function get_yesterday()
->modify('-1 day')
->setTime(0, 0, 0);
}

/**
* @return MutableDateTime
*/
protected function get_mutable()
{
return MutableDateTime::from($this);
}

/**
* @return DateTime
*/
protected function get_immutable()
{
return DateTime::from($this);
}
}
18 changes: 17 additions & 1 deletion tests/AbstractDateTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,22 @@ public function provide_read_only_properties()

return [ $property ];

}, explode(' ', 'quarter week weekday year_day is_monday is_tuesday is_wednesday is_thursday is_friday is_saturday is_sunday is_today is_past is_future is_empty tomorrow yesterday monday tuesday wednesday thursday friday saturday sunday is_utc is_local is_dst as_atom as_cookie as_iso8601 as_rfc822 as_rfc850 as_rfc1036 as_rfc1123 as_rfc2822 as_rfc3339 as_rss as_w3c as_db as_number as_date as_time utc local'));
}, explode(' ', 'quarter week weekday year_day is_monday is_tuesday is_wednesday is_thursday is_friday is_saturday is_sunday is_today is_past is_future is_empty tomorrow yesterday monday tuesday wednesday thursday friday saturday sunday is_utc is_local is_dst as_atom as_cookie as_iso8601 as_rfc822 as_rfc850 as_rfc1036 as_rfc1123 as_rfc2822 as_rfc3339 as_rss as_w3c as_db as_number as_date as_time utc local mutable immutable'));
}

public function test_get_mutable()
{
$datetime = $this->create();
$mutable = $datetime->mutable;
$this->assertNotSame($datetime, $mutable);
$this->assertInstanceOf(MutableDateTime::class, $mutable);
}

public function test_get_immutable()
{
$datetime = $this->create();
$immutable = $datetime->immutable;
$this->assertNotSame($datetime, $immutable);
$this->assertInstanceOf(DateTime::class, $immutable);
}
}

0 comments on commit bf4f4b9

Please sign in to comment.