Skip to content

Commit

Permalink
Merge pull request #35 from PhantPHP/fix-dateinterval
Browse files Browse the repository at this point in the history
Fix date interval
  • Loading branch information
lennyrouanet authored Jun 20, 2024
2 parents ae4fdfd + fc3475e commit 99aa932
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions component/Time/DateInterval.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public function __construct(
if (!$from && !$to) {
throw new NotCompliant('Date intervals: from ' . $from . ' to' . $to);
}
if ($from && $to && $from->time > $to->time) {
throw new NotCompliant('From can be after To : ' . $from . '/' . $to);
}

$this->calculateDuration();
}
Expand Down
3 changes: 3 additions & 0 deletions component/Time/DateTimeInterval.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public function __construct(
if (!$from && !$to) {
throw new NotCompliant('Date time intervals: from ' . $from . ' to' . $to);
}
if ($from && $to && $from->time > $to->time) {
throw new NotCompliant('From can be after To : ' . $from . '/' . $to);
}

$this->calculateDuration();
}
Expand Down
10 changes: 10 additions & 0 deletions test/Time/DateIntervalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,14 @@ public function testNotCompliant(): void

new DateInterval(null, null);
}

public function testNotCompliantDateInvert(): void
{
$this->expectException(NotCompliant::class);

DateInterval::make(
'1970-01-01',
'1954-06-07'
);
}
}
10 changes: 10 additions & 0 deletions test/Time/DateTimeIntervalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,14 @@ public function testNotCompliant(): void

new DateTimeInterval(null, null);
}

public function testNotCompliantDateInvert(): void
{
$this->expectException(NotCompliant::class);

DateTimeInterval::make(
'1970-01-01 00:00:00',
'1954-06-07 12:34:56'
);
}
}

0 comments on commit 99aa932

Please sign in to comment.