twigphp / twigphp/Twig

The timezone argument is missing when instantiating from strings other than "now".

Open Beginner friendly
#4,746 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
8.4k
Forks
1.3k
Avg merge
1d 13h
Merged PRs (30d)
37

Description

https://github.com/twigphp/Twig/blob/76c404ec67a6c8dcbb68e82b38a2dc6074c503de/src/Extension/CoreExtension.php#L618

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-22

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/Extension/CoreExtension.php around line 618 and reproduce the Twig date filter examples using the "today" string with Europe/Paris and Australia/Sydney timezones. Compare construction-time timezone handling with the current output; done means the timezone-aware result preserves the expected calendar date for both examples.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.