Skip to content

Commit 99aa932

Browse files
authored
Merge pull request #35 from PhantPHP/fix-dateinterval
Fix date interval
2 parents ae4fdfd + fc3475e commit 99aa932

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

component/Time/DateInterval.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ public function __construct(
2222
if (!$from && !$to) {
2323
throw new NotCompliant('Date intervals: from ' . $from . ' to' . $to);
2424
}
25+
if ($from && $to && $from->time > $to->time) {
26+
throw new NotCompliant('From can be after To : ' . $from . '/' . $to);
27+
}
2528

2629
$this->calculateDuration();
2730
}

component/Time/DateTimeInterval.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ public function __construct(
2222
if (!$from && !$to) {
2323
throw new NotCompliant('Date time intervals: from ' . $from . ' to' . $to);
2424
}
25+
if ($from && $to && $from->time > $to->time) {
26+
throw new NotCompliant('From can be after To : ' . $from . '/' . $to);
27+
}
2528

2629
$this->calculateDuration();
2730
}

test/Time/DateIntervalTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,4 +252,14 @@ public function testNotCompliant(): void
252252

253253
new DateInterval(null, null);
254254
}
255+
256+
public function testNotCompliantDateInvert(): void
257+
{
258+
$this->expectException(NotCompliant::class);
259+
260+
DateInterval::make(
261+
'1970-01-01',
262+
'1954-06-07'
263+
);
264+
}
255265
}

test/Time/DateTimeIntervalTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,4 +252,14 @@ public function testNotCompliant(): void
252252

253253
new DateTimeInterval(null, null);
254254
}
255+
256+
public function testNotCompliantDateInvert(): void
257+
{
258+
$this->expectException(NotCompliant::class);
259+
260+
DateTimeInterval::make(
261+
'1970-01-01 00:00:00',
262+
'1954-06-07 12:34:56'
263+
);
264+
}
255265
}

0 commit comments

Comments
 (0)