Skip to content

Commit

Permalink
Merge pull request #1058 from openeuropa/EWPP-2033
Browse files Browse the repository at this point in the history
EWPP-2033: Display Event programme timezone after the time.
  • Loading branch information
upchuk authored Mar 16, 2022
2 parents af1a671 + 601233d commit 94428f0
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
langcode: en
status: true
dependencies: { }
id: oe_event_programme_date
label: 'Event programme date'
locked: false
pattern: 'j M Y'
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
langcode: en
status: true
dependencies: { }
id: oe_event_programme_date_hour
label: 'Event programme date with hour'
locked: false
pattern: 'j M Y, h:i A'

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
langcode: en
status: true
dependencies: { }
id: oe_event_programme_hour_timezone
label: 'Event programme hour with timezone'
locked: false
pattern: 'h:i A T'
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
langcode: en
status: true
dependencies: { }
id: oe_event_programme_hour_timezone
label: 'Event programme hour with timezone'
locked: false
pattern: 'h:i A T'
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,19 @@ function oe_theme_content_event_post_update_30001() {
$date_format->save();
}
}

/**
* Update Event programme date formats.
*/
function oe_theme_content_event_post_update_30002(): void {
// Remove "Event programme date with timezone" as it's not used anymore.
$date_timezone = DateFormat::load('oe_event_programme_date_timezone');
$date_timezone->delete();

// Create new time format with timezone.
$storage = new FileStorage(drupal_get_path('module', 'oe_theme_content_event') . '/config/post_updates/30002_event_programme_date_format');
$config = $storage->read('core.date_format.oe_event_programme_hour_timezone');
$config['_core']['default_config_hash'] = Crypt::hashBase64(serialize($config));
$date_format = DateFormat::create($config);
$date_format->save();
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,22 @@ class ProgrammeExtraField extends EventExtraFieldBase {
/**
* Programme datetime format.
*/
const PROGRAMME_DATETIME_FORMAT = 'oe_event_programme_date_hour_timezone';
const PROGRAMME_DATETIME_FORMAT = 'oe_event_programme_date_hour';

/**
* Programme datetime with timezone format.
*/
const PROGRAMME_DATETIME_TIMEZONE_FORMAT = 'oe_event_programme_date_hour_timezone';

/**
* Programme date format.
*/
const PROGRAMME_DATE_FORMAT = 'oe_event_programme_date_timezone';
const PROGRAMME_DATE_FORMAT = 'oe_event_programme_date';

/**
* Programme time with timezone format.
*/
const PROGRAMME_TIME_TIMEZONE_FORMAT = 'oe_event_programme_hour_timezone';

/**
* Programme time format.
Expand Down Expand Up @@ -194,7 +204,7 @@ protected function generateEventProgrammeLabel(ProgrammeItemInterface $programme
// show only start time.
$start_date_format = $previous_end_date === $start_day ? self::PROGRAMME_TIME_FORMAT : self::PROGRAMME_DATETIME_FORMAT;
// If event program item running in within day, show only end time.
$end_date_format = $start_day === $end_day ? self::PROGRAMME_TIME_FORMAT : self::PROGRAMME_DATETIME_FORMAT;
$end_date_format = $start_day === $end_day ? self::PROGRAMME_TIME_TIMEZONE_FORMAT : self::PROGRAMME_DATETIME_TIMEZONE_FORMAT;
$template = '{% trans %}{{ start_date }} - {{ end_date }}{% endtrans %}';
$context = [
'start_date' => $this->dateFormatter->format($start_datetime->getTimestamp(), $start_date_format, '', $timezone),
Expand All @@ -203,7 +213,7 @@ protected function generateEventProgrammeLabel(ProgrammeItemInterface $programme
// If the event program item running within 1 day and there are no
// other event program items in the current day coming before,
// show the date with time range within a day.
if ($start_date_format === self::PROGRAMME_DATETIME_FORMAT && $end_date_format === self::PROGRAMME_TIME_FORMAT) {
if ($start_date_format === self::PROGRAMME_DATETIME_FORMAT && $end_date_format === self::PROGRAMME_TIME_TIMEZONE_FORMAT) {
$template = '{% trans %}{{ start_day }},<br>{{ start_date }} - {{ end_date }}{% endtrans %}';
$context['start_day'] = $this->dateFormatter->format($start_datetime->getTimestamp(), self::PROGRAMME_DATE_FORMAT, '', $timezone);
$context['start_date'] = $this->dateFormatter->format($start_datetime->getTimestamp(), self::PROGRAMME_TIME_FORMAT, '', $timezone);
Expand Down
18 changes: 9 additions & 9 deletions tests/src/Functional/ContentEventRenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -782,15 +782,15 @@ public function testEventRendering(): void {
$timeline_expected_values = [
'items' => [
[
'label' => '17 Feb 2020, 02:00 PM UTC - 27 Feb 2020, 02:00 PM UTC',
'label' => '17 Feb 2020, 02:00 PM - 27 Feb 2020, 02:00 PM UTC',
'title' => 'Session 1',
'body' => 'Description Session 1',
], [
'label' => '17 Feb 2020, 02:00 PM UTC - 27 Feb 2020, 02:00 PM UTC',
'label' => '17 Feb 2020, 02:00 PM - 27 Feb 2020, 02:00 PM UTC',
'title' => 'Session 2',
'body' => 'Description Session 2',
], [
'label' => '17 Feb 2020, 02:00 PM UTC - 27 Feb 2020, 02:00 PM UTC',
'label' => '17 Feb 2020, 02:00 PM - 27 Feb 2020, 02:00 PM UTC',
'title' => 'Session 3',
'body' => 'Description Session 3',
],
Expand Down Expand Up @@ -819,15 +819,15 @@ public function testEventRendering(): void {
$timeline_expected_values = [
'items' => [
[
'label' => '15 Nov 2019, 11:00 AM UTC - 15 Nov 2019, 03:00 PM UTC',
'label' => '15 Nov 2019, 11:00 AM - 15 Nov 2019, 03:00 PM UTC',
'title' => 'Session 3',
'body' => 'Description Session 3',
], [
'label' => '10:00 PM - 11:00 PM',
'label' => '10:00 PM - 11:00 PM UTC',
'title' => 'Session 1',
'body' => 'Description Session 1',
], [
'label' => '17 Feb 2020, 02:00 PM UTC - 27 Feb 2020, 02:00 PM UTC',
'label' => '17 Feb 2020, 02:00 PM - 27 Feb 2020, 02:00 PM UTC',
'title' => 'Session 2',
'body' => 'Description Session 2',
],
Expand Down Expand Up @@ -862,15 +862,15 @@ public function testEventRendering(): void {
$timeline_expected_values = [
'items' => [
[
'label' => '14 Nov 2019 UTC,<br>09:00 PM - 10:00 PM',
'label' => '14 Nov 2019,<br>09:00 PM - 10:00 PM UTC',
'title' => 'Session 3',
'body' => 'Description Session 3',
], [
'label' => '10:15 PM - 11:15 PM',
'label' => '10:15 PM - 11:15 PM UTC',
'title' => 'Session 1',
'body' => 'Description Session 1',
], [
'label' => '15 Nov 2019 UTC,<br>10:00 PM - 11:00 PM',
'label' => '15 Nov 2019,<br>10:00 PM - 11:00 PM UTC',
'title' => 'Session 2',
'body' => 'Description Session 2',
],
Expand Down

0 comments on commit 94428f0

Please sign in to comment.