Skip to content

Commit

Permalink
Fix date interval duration
Browse files Browse the repository at this point in the history
  • Loading branch information
lennyrouanet committed Jul 23, 2024
1 parent 99aa932 commit e9f5718
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion component/Time/DateInterval.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function isAfter(

private function calculateDuration(): void
{
$this->duration = ($this->from && $this->to) ? new Duration($this->to->time - $this->from->time) : null;
$this->duration = ($this->from && $this->to) ? new Duration(($this->to->time + Duration::DAY - 1) - $this->from->time) : null;
}

public static function make(
Expand Down
6 changes: 5 additions & 1 deletion test/Time/DateIntervalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Test\Time;

use Phant\DataStructure\Time\DateInterval;
use Phant\DataStructure\Time\Duration;

use Phant\Error\NotCompliant;

Expand Down Expand Up @@ -39,7 +40,10 @@ public function testInterface(): void
$this->assertEquals('1970-01-01', (string)$this->fixture->to);

$this->assertIsObject($this->fixture->duration);
$this->assertEquals('15 years, 6 months, 29 days, 12 h', (string)$this->fixture->duration);
$this->assertInstanceOf(Duration::class, $this->fixture->duration);
$this->assertEquals(new Duration(
strtotime('1970-01-01 23:59:59') - strtotime('1954-06-07 00:00:00')
), $this->fixture->duration);
}

public function testIsBefore(): void
Expand Down

0 comments on commit e9f5718

Please sign in to comment.