Doesn't support timezones and other bugs.

Created on 21 September 2024, 7 months ago

Problem/Motivation

My use case is:
- all dates entered in Toronto time
- dates should be displayed on the page view with Toronto time
- i need to send emails with time showing in Toronto time (in both English and French versions of translated compact format).

There are many pieces of this which are not supported/broken in this module:

1. 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. 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.

2. As date (likely core issue) fields do not programmatically render translated values with the std $node->$field->view() method to render a field with a given view mode, i needed to use the formatDateRange service which comes with this module and trick it into doing the right thing by modifying the ConfigOverrideLanguage. But even then the service does not work correctly:

the service call i use is this:

$formatted_date = $this->dateRangeCompactFormatter->formatDateRange($start, $end, 'date_and_time_range_with_tz', 'America/Toronto', $langcode);

1. langcode is not used (need to set ConfigOverrideLanguage)
2. TZ value is not used
3. end date being optional is not supported: NULL throws an error and '' has it use some seemingly random end date

These are test results:
input: 8:41a (assumed to be Toronto time), no end date

view: 10:11p (Adelaide time, user's TZ), no end date
- this is using the Basic compact format which is used when no end date is given, which is correct other than no option to pick correct TZ

email (using format service): 12:41p to 12:37p (+3 days)
- no idea what TZ it used for this
- no idea where it got end date/time from

The TZ issue is likely easy to fix for the service; more work to have this support the core date format options i suspect. Odd that the view format does not appear to be using the module's own format service; so will try to track down what it is using.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

2.1

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada liquidcms

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @liquidcms
  • πŸ‡ΈπŸ‡ͺ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 of daterange_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 3

    For 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:40a

    all 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.

Production build 0.71.5 2024