Skip to content

Commit

Permalink
Merge b8bca22 into b9a47e2
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed Oct 12, 2015
2 parents b9a47e2 + b8bca22 commit 44a8fc0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/ChronosInterval.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ public function __construct($years = 1, $months = null, $weeks = null, $days = n

$spec .= ($specDays > 0) ? $specDays . static::PERIOD_DAYS : '';

if ($spec === static::PERIOD_PREFIX) {
$spec .= '0' . static::PERIOD_YEARS;
}

if ($hours > 0 || $minutes > 0 || $seconds > 0) {
$spec .= static::PERIOD_TIME_PREFIX;
$spec .= $hours > 0 ? $hours . static::PERIOD_HOURS : '';
Expand Down
23 changes: 17 additions & 6 deletions tests/Interval/IntervalConstructTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,31 @@ public function testDefaults()
$this->assertDateTimeInterval($ci, 1, 0, 0, 0, 0, 0);
}

/**
* @expectedException Exception
*/
public function testNulls()
{
$ci = new ChronosInterval(null, null, null, null, null, null);
$this->assertDateTimeInterval($ci, 0, 0, 0, 0, 0, 0);

$ci = ChronosInterval::days(null);
$this->assertInstanceOf(ChronosInterval::class, $ci);
$this->assertDateTimeInterval($ci, 0, 0, 0, 0, 0, 0);
}

/**
* @expectedException Exception
*/
public function testZeroes()
{
$ci = new ChronosInterval(0, 0, 0, 0, 0, 0);
$this->assertDateTimeInterval($ci, 0, 0, 0, 0, 0, 0);

$ci = ChronosInterval::days(0);
$this->assertInstanceOf(ChronosInterval::class, $ci);
$this->assertDateTimeInterval($ci, 0, 0, 0, 0, 0, 0);
}

public function testZeroesChained()
{
$ci = ChronosInterval::days(0)->week(0)->minutes(0);
$this->assertInstanceOf(ChronosInterval::class, $ci);
$this->assertDateTimeInterval($ci, 0, 0, 0, 0, 0, 0);
}

public function testYears()
Expand Down

0 comments on commit 44a8fc0

Please sign in to comment.