Improved IntlExtension with additionnal DateTimeZone support #57

Merged
merged 1 commit into from Dec 15, 2012

Projects

None yet

3 participants

@blaugueux
Contributor

Example:

createdAt = 2012-08-15 15:30:00+00:00

Date: {{ createdAt | localizeddate('long', 'long', 'fr', 'Europe/Paris' }}

Date: 15 aout 2012 17:30:00 UTC+02:00

@stof stof and 1 other commented on an outdated diff May 25, 2012
lib/Twig/Extensions/Extension/Intl.php
{
+ if (!$timeZone || !in_array($timeZone, DateTimeZone::listIdentifiers())) {
+ $timeZone = new DateTimeZone(date_default_timezone_get());
@stof
stof May 25, 2012 Contributor

this should get the timezone from the CoreExtension to be consistent with the |date filter

@blaugueux
blaugueux May 25, 2012 Contributor

I can't do that, the timezone in the CoreExtension is null by default.

@blaugueux
blaugueux May 25, 2012 Contributor

I've made a pull request on Twig CoreExtension to fix the DateTimeZone support : https://github.com/fabpot/Twig/pull/736

@stof stof commented on an outdated diff May 25, 2012
lib/Twig/Extensions/Extension/Intl.php
);
if (!$date instanceof DateTime) {
if (ctype_digit((string) $date)) {
$date = new DateTime('@'.$date);
- $date->setTimezone(new DateTimeZone(date_default_timezone_get()));
@stof
stof May 25, 2012 Contributor

this code suffers form the same bug than Twig 1.7 and lower related to timezone changes. the best way to fix it would be to replace this duplicated call by a call to the function introduced in Twig 1.6 to parse dates

@stof stof commented on the diff May 25, 2012
lib/Twig/Extensions/Extension/Intl.php
@@ -41,8 +41,10 @@ public function getName()
}
}
-function twig_localized_date_filter($date, $dateFormat = 'medium', $timeFormat = 'medium', $locale = null)
+function twig_localized_date_filter(Twig_Environment $env, $date, $dateFormat = 'medium', $timeFormat = 'medium', $locale = null, $timezone = null)
@stof
stof May 25, 2012 Contributor

you don't seem to use the environment there

@blaugueux
blaugueux May 25, 2012 Contributor

Environment is required to call twig_date_converter on line 46.

@stof
stof May 25, 2012 Contributor

ah sorry, missed it

@blaugueux blaugueux Improved localizeddate extension with dynamic DateTimeZone.
Use CoreExtension to retrieve correct DateTime.
0a8496c
@blaugueux
Contributor

@fabpot Related to my recent pull request on DateTimeZone support in Twig Core, here is an evolution to the Intl localizeddate. Can you merge this PR ?

@fabpot
Contributor
fabpot commented May 30, 2012

which one?

@blaugueux
Contributor

@fabpot You merged the PR #736 on Twig yesterday (https://github.com/fabpot/Twig/pull/736).

@blaugueux
Contributor

@fabpot Up :) I think this would be useful for many people.

@blaugueux
Contributor

@fabpot Do i need to work on this PR or is it ok for you ?

@blaugueux
Contributor

@stof can you tell me if my PR is ok or not ?

@stof
Contributor
stof commented Dec 14, 2012

@blaugueux it looks OK, but you need @fabpot's merge. I cannot merge here

@fabpot fabpot merged commit 0a8496c into twigphp:master Dec 15, 2012
@blaugueux
Contributor

Thanks @stof :)
Thanks @fabpot :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment