A Word About Formatting
Instead, I decided to pass through the PHP date and time formatting strings that are used by Smart Date formats to render out parts of the final markup. This would allow the page to be rendered (and cached) using the default or event-specific timezone, but then have that converted when the page loads.
Consider this example, without the localization (saved with the Los Angeles timezone):
Tuesday, December 13th 2022, 4 - 5pm PST (Wednesday, December 14th 2022, 12 - 1am UTC)
Now, with the localization (accessed from the Toronto timezone):
Tuesday, December 13th 2022, 7 - 8pm EST (Wednesday, December 14th 2022, 12 - 1am UTC)
In French, without the localization:
Mardi 13 décembre 2022 à 16 h - 17 h PST (Mercredi 14 décembre 2022 à 00 h - 01 h UTC)
Also in French, but with the localization:
mardi 13 décembre 2022 à 19 h - 20 h UTC−5 (Mercredi 14 décembre 2022 à 00 h - 01 h UTC)
An Opt-In Configuration Option
I debated about implementing this new functionality as an entirely new field formatter, but ultimately decided that since the changes required were relatively minor, it could be added to the existing formatter as a configuration option.
Since the new localization relies on the time wrappers, existing sites using Smart Date won't see the new configuration option until the time wrappers option is enabled. I decided to leave the option as opt-in, so it won't impact existing sites unless site builders decided it's needed.
Based on initial testing, the new localization works seamlessly. On my (admittedly simple) test site, there was no visible lag on page load in order to see the localized times. I'm looking forward to hearing about how site owners find it works across a broader range of applications. Also, the Drupal community has consistently been an excellent source of inspiration on how projects can be even better, so I'm looking forward to hearing ideas about how this new client-side localization can be improved to meet even more use cases. This new functionality is included in a new release for Smart Date, so I hope you'll try it out and let me know how it work for you.