diff --git a/modules/oe_theme_content_event/oe_theme_content_event.post_update.php b/modules/oe_theme_content_event/oe_theme_content_event.post_update.php index e5e936844..450c82a76 100644 --- a/modules/oe_theme_content_event/oe_theme_content_event.post_update.php +++ b/modules/oe_theme_content_event/oe_theme_content_event.post_update.php @@ -151,6 +151,11 @@ function oe_theme_content_event_post_update_30004(): void { ]; foreach ($date_formats as $date_format_name) { $config = $storage->read($date_format_name); + $date_format = DateFormat::load($config['id']); + // If the date format already exists, we skip it. + if ($date_format) { + continue; + } $config['_core']['default_config_hash'] = Crypt::hashBase64(serialize($config)); $date_format = DateFormat::create($config); $date_format->save(); diff --git a/modules/oe_theme_content_event/src/Plugin/ExtraField/Display/InfoDisclosureExtraFieldBase.php b/modules/oe_theme_content_event/src/Plugin/ExtraField/Display/InfoDisclosureExtraFieldBase.php index b1e3005a8..c81d87642 100644 --- a/modules/oe_theme_content_event/src/Plugin/ExtraField/Display/InfoDisclosureExtraFieldBase.php +++ b/modules/oe_theme_content_event/src/Plugin/ExtraField/Display/InfoDisclosureExtraFieldBase.php @@ -65,13 +65,15 @@ public static function create(ContainerInterface $container, array $configuratio * * @param int $timestamp * The timestamp of start date. + * @param string|null $timezone + * The timezone id. * * @return bool * True if timestamp is within current day. */ - protected function isCurrentDay(int $timestamp): bool { - $current_date = $this->dateFormatter->format($this->requestDateTime->getTimestamp(), 'custom', 'Ymd'); - $start_day = $this->dateFormatter->format($timestamp, 'custom', 'Ymd'); + protected function isCurrentDay(int $timestamp, string $timezone = NULL): bool { + $current_date = $this->dateFormatter->format($this->requestDateTime->getTimestamp(), 'custom', 'Ymd', $timezone); + $start_day = $this->dateFormatter->format($timestamp, 'custom', 'Ymd', $timezone); return $current_date === $start_day; } diff --git a/modules/oe_theme_content_event/src/Plugin/ExtraField/Display/LivestreamExtraField.php b/modules/oe_theme_content_event/src/Plugin/ExtraField/Display/LivestreamExtraField.php index ce4d24b9c..942a93a40 100644 --- a/modules/oe_theme_content_event/src/Plugin/ExtraField/Display/LivestreamExtraField.php +++ b/modules/oe_theme_content_event/src/Plugin/ExtraField/Display/LivestreamExtraField.php @@ -55,7 +55,7 @@ public function viewElements(ContentEntityInterface $entity) { // render the date only. if ($event->isOnlinePeriodYetToCome($this->requestDateTime)) { $this->applyHourTag($build, $event->getOnlineStartDate()); - if ($this->isCurrentDay($event->getOnlineStartDate()->getTimestamp())) { + if ($this->isCurrentDay($event->getOnlineStartDate()->getTimestamp(), $event->getOnlineTimezone())) { $build += $link; $build['#hide_link'] = TRUE; $this->attachDisclosureScript($build, $event->getOnlineStartDate()->getTimestamp()); diff --git a/modules/oe_theme_content_event/src/Plugin/ExtraField/Display/OnlineDescriptionExtraField.php b/modules/oe_theme_content_event/src/Plugin/ExtraField/Display/OnlineDescriptionExtraField.php index aab91e0cc..160dba47c 100644 --- a/modules/oe_theme_content_event/src/Plugin/ExtraField/Display/OnlineDescriptionExtraField.php +++ b/modules/oe_theme_content_event/src/Plugin/ExtraField/Display/OnlineDescriptionExtraField.php @@ -45,7 +45,7 @@ public function viewElements(ContentEntityInterface $entity) { $this->applyHourTag($build, $event->getOnlineStartDate()); // Do not send field value to browser if it is not yet day online // livestreaming should be started. - if (!$this->isCurrentDay($event->getOnlineStartDate()->getTimestamp())) { + if (!$this->isCurrentDay($event->getOnlineStartDate()->getTimestamp(), $event->getOnlineTimezone())) { $this->isEmpty = TRUE; return $build; } diff --git a/modules/oe_theme_content_event/src/Plugin/ExtraField/Display/RegistrationButtonExtraField.php b/modules/oe_theme_content_event/src/Plugin/ExtraField/Display/RegistrationButtonExtraField.php index a97e3d924..a167f286e 100644 --- a/modules/oe_theme_content_event/src/Plugin/ExtraField/Display/RegistrationButtonExtraField.php +++ b/modules/oe_theme_content_event/src/Plugin/ExtraField/Display/RegistrationButtonExtraField.php @@ -73,7 +73,7 @@ public function viewElements(ContentEntityInterface $entity) { // If the request time is on the same day as the start day we need to // show different message. - if ($this->isCurrentDay($datetime_start->getTimestamp())) { + if ($this->isCurrentDay($datetime_start->getTimestamp(), $event->getRegistrationTimezone())) { $build['#registration_day_description'] = $this->t('Registration will open today, @start_date.', [ '@start_date' => $this->dateFormatter->format($datetime_start->getTimestamp(), 'oe_event_date_hour_timezone', '', $event->getRegistrationTimezone()), ]); @@ -103,7 +103,7 @@ public function viewElements(ContentEntityInterface $entity) { if ($event->hasRegistrationDates()) { // If the request time is on the same day as the end day we need to // show different message. - if ($this->isCurrentDay($datetime_end->getTimestamp())) { + if ($this->isCurrentDay($datetime_end->getTimestamp(), $event->getRegistrationTimezone())) { $build['#description'] = $this->t('Book your seat, the registration will end today, @end_date', [ '@end_date' => $this->dateFormatter->format($datetime_end->getTimestamp(), 'oe_event_date_hour_timezone', '', $event->getRegistrationTimezone()), ]); diff --git a/modules/oe_theme_content_event/tests/src/FunctionalJavascript/InfoDisclosureExtraFieldTest.php b/modules/oe_theme_content_event/tests/src/FunctionalJavascript/InfoDisclosureExtraFieldTest.php index f835b4a3a..6e9f3b6e5 100644 --- a/modules/oe_theme_content_event/tests/src/FunctionalJavascript/InfoDisclosureExtraFieldTest.php +++ b/modules/oe_theme_content_event/tests/src/FunctionalJavascript/InfoDisclosureExtraFieldTest.php @@ -127,10 +127,12 @@ public function testTimeSensitiveFieldsDisplay(): void { $node->set('oe_event_online_dates', [ 'value' => $start_date->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT), 'end_value' => (clone $start_date)->modify('+3 hours')->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT), + 'timezone' => 'Europe/Brussels', ]); $node->set('oe_event_registration_dates', [ 'value' => $start_date->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT), 'end_value' => (clone $start_date)->modify('+3 hours')->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT), + 'timezone' => 'Europe/Brussels', ]); $node->save(); $this->drupalGet($node->toUrl()); @@ -159,10 +161,12 @@ public function testTimeSensitiveFieldsDisplay(): void { $node->set('oe_event_online_dates', [ 'value' => $start_date->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT), 'end_value' => (clone $start_date)->modify('+3 hours')->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT), + 'timezone' => 'Europe/Brussels', ]); $node->set('oe_event_registration_dates', [ 'value' => $start_date->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT), 'end_value' => (clone $start_date)->modify('+3 hours')->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT), + 'timezone' => 'Europe/Brussels', ]); $node->save(); $this->drupalGet($node->toUrl()); @@ -203,10 +207,12 @@ public function testTimeSensitiveFieldsDisplay(): void { $node->set('oe_event_online_dates', [ 'value' => (clone $static_time)->modify('-1 hour')->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT), 'end_value' => (clone $static_time)->modify('+3 hours')->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT), + 'timezone' => 'Europe/Brussels', ]); $node->set('oe_event_registration_dates', [ 'value' => (clone $static_time)->modify('-1 hour')->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT), 'end_value' => (clone $static_time)->modify('+3 hours')->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT), + 'timezone' => 'Europe/Brussels', ]); $node->save(); $this->drupalGet($node->toUrl()); @@ -230,10 +236,12 @@ public function testTimeSensitiveFieldsDisplay(): void { $node->set('oe_event_online_dates', [ 'value' => (clone $static_time)->modify('-4 hours')->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT), 'end_value' => (clone $static_time)->modify('-1 hour')->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT), + 'timezone' => 'Europe/Brussels', ]); $node->set('oe_event_registration_dates', [ 'value' => (clone $static_time)->modify('-4 hours')->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT), 'end_value' => (clone $static_time)->modify('-1 hour')->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT), + 'timezone' => 'Europe/Brussels', ]); $node->save(); $this->drupalGet($node->toUrl()); diff --git a/tests/src/Functional/ContentEventRenderTest.php b/tests/src/Functional/ContentEventRenderTest.php index d00448918..44a7c5692 100644 --- a/tests/src/Functional/ContentEventRenderTest.php +++ b/tests/src/Functional/ContentEventRenderTest.php @@ -175,7 +175,7 @@ public function testEventFeaturedMediaTranslation(): void { */ public function testEventRendering(): void { // Freeze the time at a specific point. - $static_time = new DrupalDateTime('2020-02-17 14:00:00', DateTimeItemInterface::STORAGE_TIMEZONE); + $static_time = new DrupalDateTime('2020-02-17 14:00:00', 'Europe/Brussels'); $this->freezeTime($static_time); $start_date = (clone $static_time)->modify('+ 10 days'); @@ -190,7 +190,7 @@ public function testEventRendering(): void { 'oe_event_dates' => [ 'value' => $start_date->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT), 'end_value' => $start_date->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT), - 'timezone' => DateTimeItemInterface::STORAGE_TIMEZONE, + 'timezone' => 'Europe/Brussels', ], 'oe_event_languages' => [ ['target_id' => 'http://publications.europa.eu/resource/authority/language/EST'], @@ -230,7 +230,7 @@ public function testEventRendering(): void { 'size' => 'm', ], [ 'icon' => 'calendar', - 'text' => '27 February 2020, 14:00 UTC', + 'text' => '27 February 2020, 15:00 CET', 'size' => 'm', ], ], @@ -247,7 +247,7 @@ public function testEventRendering(): void { 'items' => [ [ 'label' => 'When', - 'body' => 'Thursday 27 February 2020, 14:00 UTC', + 'body' => 'Thursday 27 February 2020, 15:00 CET', ], [ 'label' => 'Languages', 'body' => 'Estonian, French', @@ -542,7 +542,7 @@ public function testEventRendering(): void { // Assert "Registration date" field when registration will start today in // one hour. - $static_time = new DrupalDateTime('2020-02-18 13:00:00', DateTimeItemInterface::STORAGE_TIMEZONE); + $static_time = new DrupalDateTime('2020-02-18 14:00:00', 'Europe/Brussels'); $this->freezeTime($static_time); $this->cronRun(); $this->drupalGet($node->toUrl()); @@ -551,7 +551,7 @@ public function testEventRendering(): void { $this->assertEquals('Registration will open today, 18 February 2020, 15:00 CET.', $registration_info_content->getText()); // Assert "Registration date" field when registration is in progress. - $static_time = new DrupalDateTime('2020-02-20 14:00:00', DateTimeItemInterface::STORAGE_TIMEZONE); + $static_time = new DrupalDateTime('2020-02-20 15:00:00', 'Europe/Brussels'); $this->freezeTime($static_time); $this->cronRun(); $this->drupalGet($node->toUrl()); @@ -561,7 +561,7 @@ public function testEventRendering(): void { // Assert "Registration date" field when registration will finish today in // one hour. - $static_time = new DrupalDateTime('2020-02-21 13:00:00', DateTimeItemInterface::STORAGE_TIMEZONE); + $static_time = new DrupalDateTime('2020-02-21 13:00:00', 'Europe/Brussels'); $this->freezeTime($static_time); $this->cronRun(); $this->drupalGet($node->toUrl()); @@ -570,7 +570,7 @@ public function testEventRendering(): void { $this->assertEquals('Book your seat, the registration will end today, 21 February 2020, 15:00 CET', $registration_info_content->getText()); // Assert "Registration date" field in the past. - $static_time = new DrupalDateTime('2020-02-24 13:00:00', DateTimeItemInterface::STORAGE_TIMEZONE); + $static_time = new DrupalDateTime('2020-02-24 13:00:00', 'Europe/Brussels'); $this->freezeTime($static_time); $this->cronRun(); $this->drupalGet($node->toUrl()); @@ -580,7 +580,7 @@ public function testEventRendering(): void { // Assert "Report text" and "Summary for report" fields when event is // finished. - $static_time = new DrupalDateTime('2020-04-15 13:00:00', DateTimeItemInterface::STORAGE_TIMEZONE); + $static_time = new DrupalDateTime('2020-04-15 13:00:00', 'Europe/Brussels'); $this->freezeTime($static_time); $this->cronRun(); $this->drupalGet($node->toUrl()); @@ -1005,21 +1005,21 @@ public function testEventRendering(): void { $this->assertEmpty($status_container->find('css', 'div.ecl-message__content div.ecl-message__title')); // Event is ongoing, but livestream is not. - $static_time = new DrupalDateTime('2020-04-17 14:00:00', DateTimeItemInterface::STORAGE_TIMEZONE); + $static_time = new DrupalDateTime('2020-04-17 14:00:00', 'Europe/Brussels'); $this->freezeTime($static_time); $this->cronRun(); $this->drupalGet($node->toUrl()); $this->assertStringContainsString('This event has started. The livestream will start at 18 April 2020, 23:00 AEST.', $status_container->find('css', 'div.ecl-message__content div.ecl-message__title')->getText()); // Event is ongoing and livestream also. - $static_time = new DrupalDateTime('2020-04-18 20:00:00', DateTimeItemInterface::STORAGE_TIMEZONE); + $static_time = new DrupalDateTime('2020-04-18 20:00:00', 'Europe/Brussels'); $this->freezeTime($static_time); $this->cronRun(); $this->drupalGet($node->toUrl()); $this->assertStringContainsString('This event has started. You can also watch it via livestream.', $status_container->find('css', 'div.ecl-message__content div.ecl-message__title')->getText()); // Event is ongoing but livestream is finished. - $static_time = new DrupalDateTime('2020-04-20 22:00:00', DateTimeItemInterface::STORAGE_TIMEZONE); + $static_time = new DrupalDateTime('2020-04-20 22:00:00', 'Europe/Brussels'); $this->freezeTime($static_time); $this->cronRun(); $this->drupalGet($node->toUrl()); @@ -1062,7 +1062,7 @@ public function testEventRendering(): void { $this->assertSession()->elementTextNotContains('css', 'div.ecl-message__content div.ecl-message__description', 'Event status message.'); // Set current time after the event ends. - $static_time = new DrupalDateTime('2020-05-15 13:00:00', DateTimeItemInterface::STORAGE_TIMEZONE); + $static_time = new DrupalDateTime('2020-05-15 13:00:00', 'Europe/Brussels'); $this->freezeTime($static_time); $this->cronRun(); $this->drupalGet($node->toUrl());