Skip to content

Commit

Permalink
Fix date interval
Browse files Browse the repository at this point in the history
  • Loading branch information
lennyrouanet committed Jun 20, 2024
1 parent ae4fdfd commit fc3475e
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 fc3475e

Please sign in to comment.