Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix: IntlExtension used dateFormatterPrototype's time type instead of zone #6

Closed
wants to merge 3 commits into from

Conversation

drjayvee
Copy link
Contributor

Looks like a copy-paste bug (the previous line uses getTimeType() correctly.

…th its time type

Looks like a copy-paste bug (the previous line uses `getTimeType()` correctly.
@drjayvee
Copy link
Contributor Author

drjayvee commented Sep 30, 2021

Actually, more work needs to be done here!

First, as I point out in twigphp/Twig#3568, $timezone is never falsy.

What's more, IntlDateFormatter::getTimeZone() returns IntlTimeZone, which doesn't have getName() (it does have getId(): string), which is assumed on line 337.

@@ -307,7 +314,7 @@ public function formatTime(Environment $env, $date, ?string $timeFormat = 'mediu
return $this->formatDateTime($env, $date, 'none', $timeFormat, $pattern, $timezone, $calendar, $locale);
}

private function createDateFormatter(?string $locale, ?string $dateFormat, ?string $timeFormat, string $pattern, \DateTimeZone $timezone, string $calendar): \IntlDateFormatter
private function createDateFormatter(?string $locale, ?string $dateFormat, ?string $timeFormat, string $pattern, ?\DateTimeZone $timezone, string $calendar): \IntlDateFormatter
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change breaks the computation of $hash without a dateFormatterPrototype as it calls getName() on null

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I overlooked that.

if ($this->dateFormatterPrototype), then that case is already handled.
How about calculating the hash with '...' . ($timezone ?: '') . '...' to handle the last case?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, the issue is also that you won't pass a $timezone to the IntlDateFormatter constructor right now, which changes the behavior compared to today (and may break things for the vast majority of users not using the prototype, in an effort to make the prototype respect its timezone)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I force-pushed a fix for this

@fabpot
Copy link
Collaborator

fabpot commented Jun 3, 2023

I've just stumbled upon this PR as this repository is not monitored (it's a read-only subtree split of the main twigphp/twig repository) which is where development happens. Feel free to reopen there. Thank you.

@fabpot fabpot closed this Jun 3, 2023
drjayvee added a commit to alisqi/Twig that referenced this pull request Jun 5, 2023
fabpot added a commit to twigphp/Twig that referenced this pull request Oct 27, 2023
…totype (drjayvee)

This PR was squashed before being merged into the 3.x branch.

Discussion
----------

Fix IntlExtension::formatDateTime use of date formatter prototype

See twigphp/intl-extra#6 for more details

Commits
-------

c75762c Fix IntlExtension::formatDateTime use of date formatter prototype
symfony-splitter pushed a commit that referenced this pull request Oct 27, 2023
…totype (drjayvee)

This PR was squashed before being merged into the 3.x branch.

Discussion
----------

Fix IntlExtension::formatDateTime use of date formatter prototype

See #6 for more details

Commits
-------

c75762c3 Fix IntlExtension::formatDateTime use of date formatter prototype
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants