[PP-1] Add ability to select a timezone for datetime field

Created on 9 December 2015, almost 9 years ago
Updated 31 January 2024, 8 months ago

Problem/Motivation

Imagine an organisation WidgetCo with editors and users in a variety of different time zones. They commonly face 2 problems trying to use the Date module. Support for some of this was present in D7's date but lost as it went to D8 core.

A. When creating session entities as part of their annual conference in New York, the times of the sessions as input by the editor are interpreted by Drupal in terms of the time zone of the editor who is creating or updating it, not New York. In this case their sitebuilder needs to be able to control the time zone used by the widget to interpret the times the editors input.

B. When creating meeting entities to describe meetings held at various locations across the world, the same problem happens. But in this case the intended time zone needs to specified for each meeting by the editor, and that preference needs to be stored with the date/time.

Proposed resolution

This effort has become too large to be accomplished in a single issue.

🌱 [META] Add timezone support to core date fields Active is the active plan issue to actually coordinate this effort in smaller pieces.

We should stop posting "composer-friendly" giant patches in here, too. It's important we have a place for folks to put the patches they're using on real sites while the dust settles on doing this properly, but we don't want those patches either in this issue, nor in the new meta. Those patches should now live at πŸ“Œ Composer friendly patches adding timezones to core date fields Needs work

Ideally, no one else should comment here until #3185747 is marked fixed and we can close this.

General commentary on the new plan should happen at #3185747
Comments about specific pieces of the plan should go in the appropriate child issue.
Comments about the monster patches, re-rolls, conflicts, etc, should happen in #3185750

Remaining tasks

  1. Complete the plan described in 🌱 [META] Add timezone support to core date fields Active
  2. Mark this issue fixed to notify everyone.

User interface changes

TBD, see child issues.

API changes

TBD, see child issues.

Data model changes

TBD, see child issues.

✨ Feature request
Status

Postponed

Version

11.0 πŸ”₯

Component
DatetimeΒ  β†’

Last updated about 7 hours ago

Created by

πŸ‡ΊπŸ‡ΈUnited States arknoll

Live updates comments and jobs are added and updated live.
  • Needs framework manager review

    It is used to alert the framework manager core committer(s) that an issue significantly impacts (or has the potential to impact) multiple subsystems or represents a significant change or addition in architecture or public APIs, and their signoff is needed (see the governance policy draft for more information). If an issue significantly impacts only one subsystem, use Needs subsystem maintainer review instead, and make sure the issue component is set to the correct subsystem.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¬πŸ‡§United Kingdom c_archer Cumbria

    Patch from #296 does not apply agains Drupal 9.5.7

  • πŸ‡¨πŸ‡¦Canada joseph.olstad

    I suggest simplifying this to allow contrib to handle this.

    Add a new hook to alter the list of time zones.

    This works quite well and has been in use for a while without telling anyone.

    Here in Canada for intranet sites we restrict the timezone selection down to 5 Canadian timezones.

    Using this hook invoke and an implements hook for example:

    /**
     *  Implements hook_timezone_list_alter($zones).
     */
    function mymodule_timezone_list_alter($zones) {
      // Don't modify in Views UI
      $route_match = \Drupal::routeMatch();
      if ($route_match->getRouteName() == 'views_ui.form_handler') {
        return $zones;
      }
    
      $keep = [
        'Rocky Mountain House' => t('Mountain time'),
        'Cape Breton' => t('Atlantic time') ,
        'St Johns' => t('Newfoundland time'),
        'Mississauga' => t('Eastern time'),
        'Salmon arm' => t('Pacific time'),
        'Brandon' => t('Central time'),
      ];
      foreach ($zones as $optgroup => &$group) {
        if ($optgroup != 'America') {
          unset($zones[$optgroup]);
        }
        else {
          foreach ($zones['America'] as $index => $option) {
            if (!in_array($option, array_keys($keep))) {
              unset($zones['America'][$index]);
            }
            else {
              $zones['America'][$index] .= ' (' . $keep[$option] . ')';
            }
          }
        }
      }
      return $zones;
    }
    
    

    I imagine someone is going to suggest extending the TimeZoneFormHelper class and overriding the getOptionsListByRegion method instead?

    Is there some Drupal 10 documentation for this sort of thing with examples if for say we wanted to adopt this approach in a contrib module?

    I think this should be a contrib solution.

  • πŸ‡¨πŸ‡¦Canada joseph.olstad

    This has been open 9 years, we should probably just leave this to contrib. With that said, given my example provided in comment #305, what is the highest performance /most practical way to handle this case?

  • last update 5 months ago
    Patch Failed to Apply
Production build 0.71.5 2024