Needs work
Project:
Token
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
27 Oct 2022 at 01:12 UTC
Updated:
13 Jan 2026 at 20:32 UTC
Jump to comment: Most recent
When in a UTC+13 timezone (like New Zealand during daylight savings time) tokens for date-only fields show incorrectly.
This may also apply to UTC+12 timezones although I have not tested those.
field_issue_date[node:field_issue_date:date:html_date]/[node:title]2022-10-27) as the value of the date-only field. Save the node to create it./2022-10-28/node-title) while Drupal correctly renders the date field as today.Why does this happen?
2022-10-27 in the database which is in UTC time (but the actual timezone is not relevant as the day is not a true date).2022-10-27 12:00:00 UTC.2022-10-28 01:00:00 NZDT.Token should always render date-only fields in UTC since they are not intended to be true date objects with timezones.
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
ericgsmith commentedBitten by this bug today.
Good summary of the issue.
If we look at what core is doing it adds a check for the type when setting the timezone https://git.drupalcode.org/project/drupal/-/blob/11.2.8/core/modules/dat...
I believe around here https://git.drupalcode.org/project/token/-/blob/8.x-1.16/token.tokens.in... we should add a check for the type on the field definition - and if it is date we could add an additional timezone - perhaps as an additional option? I'm not familiar with the token module enough, but some way of passing this along to the generate method would be needed.
Then we should just need to use it here https://git.drupalcode.org/project/token/-/blob/8.x-1.16/token.tokens.in... instead of passing
NULLas the timezone.Will do a bit of hacking around see if I can get something working
Comment #5
ericgsmith commentedCool - test added to show the issue fails as expected: https://git.drupalcode.org/issue/token-3317688/-/jobs/7344007#L263
Comment #6
ericgsmith commentedSetting this to needs review although I'm really not sure if we should be passing timezone as an option or data - maybe a token expert can weigh in here.
Either way - I think this demonstrates the issue well and hopefully not too far away from a fix - happy to keep pushing this forward if somebody can please review.
Pipeline with test + fix passing: https://git.drupalcode.org/issue/token-3317688/-/jobs/7344220
Test only changes failing demonstrate the issue: https://git.drupalcode.org/issue/token-3317688/-/jobs/7344224
Comment #7
berdirPosted a review of how I think we can simplify this a bit.
Comment #8
ericgsmith commentedThanks @berdir - replied on the MR
Comment #9
berdirReplied again, see #2739290: UTC+12 is broken on date only fields
Comment #10
ericgsmith commentedThanks @berdir - I've added a bit more explanation to what I'm seeing locally.
The commit you referenced does show that core supplies a timezone to the formatter, so I don't think we can get this to format correctly without passing the correct timezone somehow.
I'm not saying an additional option is the best way - if we passed the original datetime object around instead of a timestamp that would also give us the ability to provide the original timezone to the formatter, but I'm not sure how much refactoring / knock on effects that would have.