-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Open
Description
Twig/src/Extension/CoreExtension.php
Line 618 in 76c404e
| $date = new \DateTime($date); |
Is there a reason not to pass the timezone as the second argument in that case (unlike previous cases) ? Timezone is set a few lines later but it's not wat we could expect
Let see with an exemple :
Right now it's
- In Paris: 2026-01-22 it's 05:00 PM in Europe/Paris (+01:00)
- In London: 2026-01-22 04:00 PM UTC
- In Sydney: 2026-01-23 03:00 AM Australia/Sydney (+11:00) // Notice it's day +1
👉 php.ini timezone is set to UTC
Usage in Twig template
{{ "today"|date('Y-m-d', 'Australia/Sydney') }}Current version result :
$today = new \DateTime("today"); // 2026-01-22 00:00:00.0 UTC (+00:00)
$today->setTimezone(new \DateTimeZone('Australia/Sydney')); // 2026-01-22 11:00:00.0 Australia/Sydney (+11:00)
echo $today->format('Y-m-d');
// output 2025-01-22 💥 Expecting result
$today = new \DateTime("today", new \DateTimeZone('Australia/Sydney')); // 2026-01-23 00:00:00.0 Australia/Sydney (+11:00)
echo $today->format('Y-m-d');
// output 2025-01-23 👍 False positive case
{{ "today"|date('Y-m-d', 'Europe/Paris') }}$today = new \DateTime("today"); // today set time to 00:00:00 (https://www.php.net/manual/en/datetime.formats.php)
$today->setTimezone(new \DateTimeZone('Europe/Paris'));
echo $today->format('Y-m-d');
// output 2025-01-22Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels