Skip to content

Commit a3e6315

Browse files
committed
Fix default format in SimpleDateTimeIntervalFormatter
1 parent 138dba2 commit a3e6315

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/Time/Interval/SimpleDateTimeIntervalFormatter.php

+14-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@
99

1010
namespace Dogma\Time\Interval;
1111

12+
use Dogma\ShouldNotHappenException;
1213
use Dogma\StrictBehaviorMixin;
14+
use Dogma\Time\Date;
15+
use Dogma\Time\DateTime;
1316
use Dogma\Time\InvalidFormattingStringException;
17+
use Dogma\Time\Time;
1418
use function count;
1519
use function explode;
1620

@@ -32,9 +36,17 @@ public function format(DateOrTimeInterval $interval, ?string $format = null): st
3236
}
3337
[$startFormat, $endFormat] = $parts;
3438
$separator = '';
35-
} else {
36-
$startFormat = $endFormat = null;
39+
} elseif ($interval instanceof TimeInterval) {
40+
$startFormat = $endFormat = Time::DEFAULT_FORMAT;
41+
$separator = ' - ';
42+
} elseif ($interval instanceof DateTimeInterval) {
43+
$startFormat = $endFormat = DateTime::DEFAULT_FORMAT;
3744
$separator = ' - ';
45+
} elseif ($interval instanceof DateInterval || $interval instanceof NightInterval) {
46+
$startFormat = $endFormat = Date::DEFAULT_FORMAT;
47+
$separator = ' - ';
48+
} else {
49+
throw new ShouldNotHappenException('Default format for ' . get_class($interval) . ' is not defined.');
3850
}
3951

4052
if ($interval instanceof DateInterval) {

0 commit comments

Comments
 (0)