Hi,

in Drupal 6 timezones were shown as a UTC+OFFSET in admin/settings/date-time, like:

Monday, 27 November, 2017 - 13:37 +0200

AFAIK these time zones did not support Daylight Saving Time.

When migrating a D6 site to D8 some users may want to keep such DST-less timezones.

In particular, my use case is a site that generates URL aliases and file paths using the node creation date in them, and DST can mess up the migration for content created around midnight, breaking links.

Automatic migration does not allow to control whether DST is desired or not because core/modules/system/src/Plugin/migrate/process/d6/TimeZone.php, called by the d6_system_date.yml migration, uses timezone_name_from_abbr and the $isdst parameter there refers only to the specific offset passed as an argument, and not to whether the timezone itself uses DST.

So my solution would be to skip the d6_system_date.yml migration and set the desired destination timezone in the installation profile instead.

However currently Drupal does not allow to avoid DST in a clear way, in some cases the user can cheat, for instance I could select Africa/Maputo as a timezone because I know from https://en.wikipedia.org/wiki/List_of_tz_database_time_zones and https://en.wikipedia.org/wiki/Daylight_saving_time_by_country that it is GMT+0200 and it does not use DST, but that's not ideal.

So I propose to show the "Backward compatible" timezones too in the timezone selector form at admin/config/regional/settings in D8.

For my site I would select Etc/GMT-2 which is more explicit and self documenting than picking up Africa/Maputo arbitrarily.

Any comments?

A tentative patch is on its way.

Ciao,
Antonio

P.S. I did think about changing the original D6 dates in a custom migration process plugin to become consistent with a DST timezone, but that doesn't seem right.

Comments

ao2 created an issue. See original summary.

ao2’s picture

Issue summary: View changes
ao2’s picture

Status: Active » Needs review
StatusFileSize
new1.93 KB

Status: Needs review » Needs work
ao2’s picture

Status: Needs work » Needs review
StatusFileSize
new1.95 KB

The previous patch failed because it was created in a split-core setup and I forgot to pass --src-prefix=a/core/ --dst-prefix=b/core/ to git.

Attaching another patch, the only change is the diff prefixes, no code changes.

Status: Needs review » Needs work
ao2’s picture

Testing fails because one of the assert is forbidding America/Indianapolis which shows up in the Backward Compatible timezones.

If the general idea of the patch seems fine I will spend time fixing the tests.

ao2’s picture

Status: Needs work » Closed (outdated)

Eventually I decided to use a proper timezone instead of the backward compatible one and I fixed the dates from Drupal 6 with a migrate process plugin.

I am closing this issue as outdated. If anyone needs the old DST-less timezone, feel free to reopen it.

JFTR this is the process plugin I used, in case someone else needed it.

<?php

namespace Drupal\ao2_it_custom_migration\Plugin\migrate\process;

use Drupal\migrate\MigrateException;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;

/**
 * Provides a 'FixDate' migrate process plugin.
 *
 * @MigrateProcessPlugin(
 *  id = "ao2_it_fix_date"
 * )
 */
class Ao2ItFixDate extends ProcessPluginBase {

  /**
   * {@inheritdoc}
   */
  public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
    if (filter_var($value, FILTER_VALIDATE_INT) === FALSE) {
      throw new MigrateException('The input value must be an integer.');
    }

    $time = (int) $value;

    /*
     * Drupal 6 interprets dates as a time plus an offset relative to GMT,
     * without considering Daylight Saving Time, while timezones used by
     * Drupal 8 do consider DST.
     *
     * This difference could result in dates interpreted differently by D6 and
     * D8 depending on the time of the year. The same time could be
     * interpreted as being in different days. This could be a problem if the
     * day is used in URL aliases or in file paths, breaking links when
     * migrating from D6 to D8.
     *
     * As a workaround, adjust of an offset all the problematic times.
     */
    $default_timezone = date_default_timezone_get();

    $d6_timezone = 'Etc/GMT-2';
    $d8_timezone = 'Europe/Rome';

    date_default_timezone_set($d6_timezone);
    $d6_date = date('Y-m-d H:i:s', $time);

    date_default_timezone_set($d8_timezone);
    $d8_date = date('Y-m-d H:i:s', $time);

    /*
     * It doesn't really matter in which timezone these are calculated as long
     * as they are in the same one, but using UTC looks a little more
     * symmetric.
     */
    date_default_timezone_set('UTC');
    $d6_time = strtotime($d6_date);
    $d8_time = strtotime($d8_date);

    // The offset will be 0 if the date is the same.
    $offset = $d6_time - $d8_time;
    $time += $offset;

    date_default_timezone_set($default_timezone);
    return (string) $time;
  }

}
ao2’s picture

Title: Add backward compatible timezones to the timezones selector » Handle dates incosistencies between D6 and D8
Component: system.module » migration system

Use a more generic title and reassign to the migration system, as this is now more useful as a reference for migrations.

benjifisher’s picture

Title: Handle dates incosistencies between D6 and D8 » Handle date inconsistencies between D6 and D8