Skip to content

Commit

Permalink
Fix default format in SimpleDateTimeIntervalFormatter
Browse files Browse the repository at this point in the history
  • Loading branch information
paranoiq committed May 31, 2023
1 parent 138dba2 commit a3e6315
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/Time/Interval/SimpleDateTimeIntervalFormatter.php
Expand Up @@ -9,8 +9,12 @@

namespace Dogma\Time\Interval;

use Dogma\ShouldNotHappenException;
use Dogma\StrictBehaviorMixin;
use Dogma\Time\Date;
use Dogma\Time\DateTime;
use Dogma\Time\InvalidFormattingStringException;
use Dogma\Time\Time;
use function count;
use function explode;

Expand All @@ -32,9 +36,17 @@ public function format(DateOrTimeInterval $interval, ?string $format = null): st
}
[$startFormat, $endFormat] = $parts;
$separator = '';
} else {
$startFormat = $endFormat = null;
} elseif ($interval instanceof TimeInterval) {
$startFormat = $endFormat = Time::DEFAULT_FORMAT;
$separator = ' - ';
} elseif ($interval instanceof DateTimeInterval) {
$startFormat = $endFormat = DateTime::DEFAULT_FORMAT;
$separator = ' - ';
} elseif ($interval instanceof DateInterval || $interval instanceof NightInterval) {
$startFormat = $endFormat = Date::DEFAULT_FORMAT;
$separator = ' - ';
} else {
throw new ShouldNotHappenException('Default format for ' . get_class($interval) . ' is not defined.');
}

if ($interval instanceof DateInterval) {
Expand Down

0 comments on commit a3e6315

Please sign in to comment.