Skip to content

Commit

Permalink
Make sure virtual separator is remove in middle part, too
Browse files Browse the repository at this point in the history
  • Loading branch information
flack committed Mar 5, 2024
1 parent 0f011c4 commit 6896106
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Ranger.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,12 @@ public function format($start, $end) : string
$left_middle = '';
$right_middle = '';
for ($k = $i; $k <= $j; $k++) {
$left_middle .= $start_tokens[$k]['content'];
$right_middle .= $end_tokens[$k]['content'];
if ($start_tokens[$k]['content'] !== $this->virtual_separator) {
$left_middle .= $start_tokens[$k]['content'];
}
if ($end_tokens[$k]['content'] !== $this->virtual_separator) {
$right_middle .= $end_tokens[$k]['content'];
}
}

return $left . $left_middle . $this->get_range_separator($best_match) . $right_middle . $right;
Expand Down
15 changes: 15 additions & 0 deletions test/RangerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,4 +291,19 @@ public function testIssue14()
}
$this->assertEquals('2024年3月29日, ' . $day_period . '7:00', $r->format(1711738800, 1711738800));
}

public function testIssue15()
{
$r = new Ranger('zh_TW');
$r
->setDateType(IntlDateFormatter::MEDIUM)
->setTimeType(IntlDateFormatter::SHORT);

if (version_compare(INTL_ICU_VERSION, '70.1', '<')) {
$day_period = '下午';
} else {
$day_period = '晚上';
}
$this->assertEquals('2024年3月29日, ' . $day_period . '7:00 – 2024年3月30日, ' . $day_period . '8:00', $r->format(1711738800, 1711828800));
}
}

0 comments on commit 6896106

Please sign in to comment.