- Issue created by @liquidcms
- π¨π¦Canada joseph.olstad
- πΈπͺSweden erik.erskine
Thanks for reporting this
Core allows date/date ranges to be entered (form display) in either user, site or fixed tz. I have set this to fixed with Toronto time.
I'm not aware of this option, where/how are you doing this? In any case, presumably the string in the database is UTC, right?
But core date/date range fields have the matching formatters for this: display with user, site or fixed TZ. This module displays in ONLY user TZ.
Again, I'm not familiar with this three way choice. Do you mean the timezone override setting? This is essentially the fixed TZ you mention. If so, I agree it would make sense to add that, to bring this module up to feature parity with core's formatters.
Regarding the second point, calling the formatter service directly:
$formatted_date = $this->dateRangeCompactFormatter->formatDateRange($start, $end, 'date_and_time_range_with_tz', 'America/Toronto', $langcode);
Firstly, what is the value of
$langcode
at this point?
Second, please can you paste the contents ofdaterange_compact.format.date_and_time_range_with_tz.yml
? - π¨π¦Canada liquidcms
There are 2 parts to this (core):
- the form config can state any of the 3 TZ options
- the field display formatter can also select any of the 3For my test case, both are set to fixed TZ: Toronto.
- on form i enter start time of: 8:40am
- in db i see: 12:40, America/Toronto (in other words it stores as UTC but sets TZ)
- field display on node shows as 8:40aall good.
with your MR from other issue i tried this code:
$node = Drupal\node\Entity\Node::load(2625); $dateService = \Drupal::service('daterange_compact.formatter'); $start = $node->field_when->value; $end = $node->field_when->end_value; $formatted_date = $dateService->formatDateRange($start, $end, 'date_and_time_range_with_tz', 'America/Toronto', 'en'); dpm($formatted_date);
output: From 12:41 PM (EDT) on Wednesday, September 4 to 1:41 PM (EDT) on Friday, November 1, 2024
So the TZ used in the formatter "T" placeholder is swapped in with the value from the service call; but the time is unchanged.