Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Fixes DateTime formatter for different timezones #116

Merged
merged 1 commit into from
Sep 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/View/Helper/DateFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function __invoke(
}

$timezone = $this->getTimezone();
$formatterId = md5($dateType . "\0" . $timeType . "\0" . $locale ."\0" . $pattern);
$formatterId = md5($dateType . "\0" . $timeType . "\0" . $locale . "\0" . $pattern . "\0" . $timezone);

if (! isset($this->formatters[$formatterId])) {
$this->formatters[$formatterId] = new IntlDateFormatter(
Expand Down
15 changes: 15 additions & 0 deletions test/View/Helper/DateFormatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,4 +286,19 @@ public function getIntlDateFormatter($locale, $dateType, $timeType, $timezone, $
{
return new IntlDateFormatter($locale, $dateType, $timeType, $timezone, null, $pattern);
}

public function testDifferentTimezone()
{
$helper = $this->helper;

date_default_timezone_set('America/Chicago');
$date = new DateTime('2018-01-01');

self::assertSame('Jan 1, 2018', $helper($date, IntlDateFormatter::MEDIUM));

date_default_timezone_set('America/New_York');
$date = new DateTime('2018-01-01');

self::assertSame('Jan 1, 2018', $helper($date, IntlDateFormatter::MEDIUM));
}
}