Problem/Motivation
Currently, if you render tokens for message, all timestamps are rendered by using current user. With multilingual (and multi-timezoned) this becomes a bit tricky.
In scenario, where there's mail including datetime token being sent to recipient from queue, and the queue is ran in cron, the current user is anonymous, which does not have timezone. This leads in situation where the datetime is default timezone.
The solution for above is to use `account_switcher` service when handling the queue to set current user to be the recipient.
However, if you like to let the user know what timezone was actually used for the timestamps, you would probably add something like
All times are shown as timezone of [current-user:timezone]
And for some reason, this isn't yet possible.

Proposed resolution
Adds a "timezone" user token, which gets either the user's timezone or the default time zone.

Remaining tasks
- Edit the change record for language and code examples following other change records
User interface changes
Adds a new token.
Adds a new translatable string: "The timezone of the user account."
API changes
N/A
Data model changes
N/A
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #34 | 2889688-34.patch | 4.37 KB | nikhil_110 |
| #34 | interdiff_28-34.txt | 391 bytes | nikhil_110 |
| #28 | interdiff_2889688_25-28.txt | 452 bytes | karishmaamin |
| #28 | 2889688-28.patch | 4.37 KB | karishmaamin |
| #27 | After--patch--timezone.png | 61.41 KB | vikashsoni |
Issue fork drupal-2889688
Show commands
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 #2
dropa commentedMade timezone available as a token and added test of it to UserTokenReplaceTest
Comment #3
dropa commentedComment #6
dropa commentedComment #8
socialnicheguru commentedwhy is this being done in the patch?
+ $account->set('timezone', 'America/Santiago');If you are using the $user->id, should that user's timezone be used first, then the default of the site be the fallback?
Comment #9
dropa commentedThe timezone is set for test, I assume you missed that part? The affecting code is at the bottom of patch.
Comment #10
dropa commentedDidn't notice the patch wont apply anymore.
Comment #12
olofbokedal commentedRe-rolled against 8.7. Not sure if this will work for 8.8 but I figured I still upload the patch since we need it for a project running 8.7.
Comment #13
yogeshmpawarSetting back to Needs Review & Triggering bots. Verified that above patch still applies to 8.8.x branch.
Comment #14
john cook commentedThank you for working on this everyone.
While testing I've used the Token Filter module.
After setting up the text formatter to use tokens, I created a new basic page and the following:
Before patching:

After patching:

And the timezone is updated when the user changes their locale settings.
Unfortunately the new token does not appear in the token list:

To do this, the
user_token_info()function needs to be updated to include the new token.A change record needs to be drafted as well.
Both these tasks can be novice task, so I've set that tag, and returned the issue to needs work.
Comment #15
fabienlyHi, I will try to finish the patch and write the API change record.
Comment #16
fabienlyI take the pacth 12 and I add to user_token_info() the information about the new token as requested in comment #14.

This is a screenshot of the result in the help page (admin/help/token).
I will write the API change record draft now.
Comment #17
fabienlyI have created the change record draft.
link here
Comment #22
darvanenNeeds patch (or MR) against 9.3.x
Comment #23
suresh prabhu parkala commentedA re-rolled patch against 9.3.x. Please review.
Comment #24
darvanenTry 'localized'. Drupal's code standards specify "American English" is to be used in the codebase (CSpell custom command error).
Comment #25
akshay_dCommand failures have been fixed in the updated patch i.e point 1.
Also please elaborate more if point 2 need to have any update to the codebase.
Comment #26
mradcliffe@akshay_d, a change record doesn't need to have an update the codebase itself. See Write a change record for a Drupal core issue.
I edited the issue summary so next steps are clear.
I briefly reviewed the patch above.
We should use single quotes here.
After that is fixed, I think that you can add the "Needs manual testing" and "Needs issue s
Comment #27
vikashsoni commentedApplied #25 patch working fine and looks good for me
After patch user time zone field is added in token
Thanks for the patch
For ref sharing screenshots .....
Comment #28
karishmaamin commentedUpdated patch #25 as per mentioned in #27
Comment #29
mradcliffeThank you for manually testing and uploading the screenshots, @vikashsoni! The final step for completing a manual testing task is to add the before and after screenshots to the issue summary replacing any old screenshots. I modified the issue summary in order to complete that last step.
Thank you for the patch, @karishmaamin! The minor code standard fix looks good to me.
I noticed that this introduces a new translatable string. I looked on localize.drupal.org and found "The timezone of this user.", but I don't think that fits with the other token descriptions which call out "user account" rather than "user". Also, the word "current" isn't used for most of the user token descriptions. I think the we can drop the word "current" as it might be confusing when compared to the other strings. I'm going to bump it back to Needs work for that change. I'm sorry I didn't think about the wording in my previous review.
We still need to modify the draft change record per @darvanen's review in comment #24.
Comment #30
guilhermevp commentedComment #34
nikhil_110 commentedAddresses #29 && Attached patch against Drupal 10.1.x
Comment #35
nikhil_110 commentedComment #36
nikhil_110 commentedComment #37
smustgrave commentedPer #24
Comment #39
rachel_norfolkRemoving Novice tag until some of the specific reviews are complete.
Comment #41
bob.hinrichs commentedWhat is the current status of this issue? The patch no longer applies for D11.
Comment #42
darvanen@bob.hinrichs you can usually figure that out by working back through the comments. In this case the latest status change is at #37, referencing #24 which hasn't been addressed. We'll need to add rebasing the MR to the list of tasks too.