Commit d819f632 authored by git's avatar git Committed by Owen Bush
Browse files

Issue #3282568 by endless_wander, owenbush: If website is on timezone other...

Issue #3282568 by endless_wander, owenbush: If website is on timezone other than UTC, editing Event Series causes the "Confirm Date Changes" prompt to incorrectly appear
parent 97586553
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -247,14 +247,8 @@ class EventCreationService {

          $start_timestamp = $custom_date['value']->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT);
          $end_timestamp = $custom_date['end_value']->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT);

          $start_date = DrupalDateTime::createFromFormat(DateTimeItemInterface::DATETIME_STORAGE_FORMAT, $start_timestamp, $user_timezone);
          // Convert the DateTime object back to UTC timezone.
          $start_date->setTimezone($utc_timezone);

          $end_date = DrupalDateTime::createFromFormat(DateTimeItemInterface::DATETIME_STORAGE_FORMAT, $end_timestamp, $user_timezone);
          // Convert the DateTime object back to UTC timezone.
          $end_date->setTimezone($utc_timezone);
          $start_date = DrupalDateTime::createFromFormat(DateTimeItemInterface::DATETIME_STORAGE_FORMAT, $start_timestamp, $utc_timezone);
          $end_date = DrupalDateTime::createFromFormat(DateTimeItemInterface::DATETIME_STORAGE_FORMAT, $end_timestamp, $utc_timezone);

          $config['custom_dates'][] = [
            'start_date' => $start_date,
@@ -361,14 +355,20 @@ class EventCreationService {
        if ($entity_config['custom_dates'] !== $form_config['custom_dates']) {
          $stored_start_ends = $overridden_start_ends = [];

          $user_timezone = new \DateTimeZone(date_default_timezone_get());

          foreach ($entity_config['custom_dates'] as $date) {
            if (!empty($date['start_date']) && !empty($date['end_date'])) {
              $date['start_date']->setTimezone($user_timezone);
              $date['end_date']->setTimezone($user_timezone);
              $stored_start_ends[] = $date['start_date']->format('Y-m-d h:ia') . ' - ' . $date['end_date']->format('Y-m-d h:ia');
            }
          }

          foreach ($form_config['custom_dates'] as $date) {
            if (!empty($date['start_date']) && !empty($date['end_date'])) {
              $date['start_date']->setTimezone($user_timezone);
              $date['end_date']->setTimezone($user_timezone);
              $overridden_start_ends[] = $date['start_date']->format('Y-m-d h:ia') . ' - ' . $date['end_date']->format('Y-m-d h:ia');
            }
          }
+2 −0
Original line number Diff line number Diff line
@@ -157,10 +157,12 @@ class ConsecutiveRecurringDate extends DateRangeItem implements RecurringEventsF
    && !empty($user_input['consecutive_recurring_date'][0]['time'])) {
      $time_parts = static::convertTimeTo24hourFormat($time);
      $timestamp = implode(':', $time_parts);
      $user_input['consecutive_recurring_date'][0]['value']->setTimezone($user_timezone);
      $start_timestamp = $user_input['consecutive_recurring_date'][0]['value']->format('Y-m-d') . 'T' . $timestamp;
      $start_date = DrupalDateTime::createFromFormat(DateTimeItemInterface::DATETIME_STORAGE_FORMAT, $start_timestamp, $user_timezone);
      $start_date->setTime(0, 0, 0);

      $user_input['consecutive_recurring_date'][0]['end_value']->setTimezone($user_timezone);
      $end_timestamp = $user_input['consecutive_recurring_date'][0]['end_value']->format('Y-m-d') . 'T' . $timestamp;
      $end_date = DrupalDateTime::createFromFormat(DateTimeItemInterface::DATETIME_STORAGE_FORMAT, $end_timestamp, $user_timezone);
      $end_date->setTime(0, 0, 0);
+2 −0
Original line number Diff line number Diff line
@@ -125,6 +125,7 @@ class DailyRecurringDate extends DateRangeItem implements RecurringEventsFieldTy
    $time_parts = static::convertTimeTo24hourFormat($time);
    $timestamp = implode(':', $time_parts);

    $user_input['daily_recurring_date'][0]['value']->setTimezone($user_timezone);
    $start_timestamp = $user_input['daily_recurring_date'][0]['value']->format('Y-m-d') . 'T' . $timestamp;
    $start_date = DrupalDateTime::createFromFormat(DateTimeItemInterface::DATETIME_STORAGE_FORMAT, $start_timestamp, $user_timezone);
    $start_date->setTime(0, 0, 0);
@@ -137,6 +138,7 @@ class DailyRecurringDate extends DateRangeItem implements RecurringEventsFieldTy
    $end_time_parts = static::convertTimeTo24hourFormat($end_time);
    $end_timestamp = implode(':', $end_time_parts);

    $user_input['daily_recurring_date'][0]['end_value']->setTimezone($user_timezone);
    $end_timestamp = $user_input['daily_recurring_date'][0]['end_value']->format('Y-m-d') . 'T' . $end_timestamp;
    $end_date = DrupalDateTime::createFromFormat(DateTimeItemInterface::DATETIME_STORAGE_FORMAT, $end_timestamp, $user_timezone);
    $end_date->setTime(0, 0, 0);
+2 −0
Original line number Diff line number Diff line
@@ -128,6 +128,7 @@ class MonthlyRecurringDate extends WeeklyRecurringDate implements RecurringEvent
    $time_parts = static::convertTimeTo24hourFormat($time);
    $timestamp = implode(':', $time_parts);

    $user_input['monthly_recurring_date'][0]['value']->setTimezone($user_timezone);
    $start_timestamp = $user_input['monthly_recurring_date'][0]['value']->format('Y-m-d') . 'T' . $timestamp;
    $start_date = DrupalDateTime::createFromFormat(DateTimeItemInterface::DATETIME_STORAGE_FORMAT, $start_timestamp, $user_timezone);
    $start_date->setTime(0, 0, 0);
@@ -140,6 +141,7 @@ class MonthlyRecurringDate extends WeeklyRecurringDate implements RecurringEvent
    $end_time_parts = static::convertTimeTo24hourFormat($end_time);
    $end_timestamp = implode(':', $end_time_parts);

    $user_input['monthly_recurring_date'][0]['end_value']->setTimezone($user_timezone);
    $end_timestamp = $user_input['monthly_recurring_date'][0]['end_value']->format('Y-m-d') . 'T' . $end_timestamp;
    $end_date = DrupalDateTime::createFromFormat(DateTimeItemInterface::DATETIME_STORAGE_FORMAT, $end_timestamp, $user_timezone);
    $end_date->setTime(0, 0, 0);
+2 −0
Original line number Diff line number Diff line
@@ -93,6 +93,7 @@ class WeeklyRecurringDate extends DailyRecurringDate implements RecurringEventsF
    $time_parts = static::convertTimeTo24hourFormat($time);
    $timestamp = implode(':', $time_parts);

    $user_input['weekly_recurring_date'][0]['value']->setTimezone($user_timezone);
    $start_timestamp = $user_input['weekly_recurring_date'][0]['value']->format('Y-m-d') . 'T' . $timestamp;
    $start_date = DrupalDateTime::createFromFormat(DateTimeItemInterface::DATETIME_STORAGE_FORMAT, $start_timestamp, $user_timezone);
    $start_date->setTime(0, 0, 0);
@@ -105,6 +106,7 @@ class WeeklyRecurringDate extends DailyRecurringDate implements RecurringEventsF
    $end_time_parts = static::convertTimeTo24hourFormat($end_time);
    $end_timestamp = implode(':', $end_time_parts);

    $user_input['weekly_recurring_date'][0]['end_value']->setTimezone($user_timezone);
    $end_timestamp = $user_input['weekly_recurring_date'][0]['end_value']->format('Y-m-d') . 'T' . $end_timestamp;
    $end_date = DrupalDateTime::createFromFormat(DateTimeItemInterface::DATETIME_STORAGE_FORMAT, $end_timestamp, $user_timezone);
    $end_date->setTime(0, 0, 0);