Skip to content
Snippets Groups Projects
Commit b627750b authored by Owen Bush's avatar Owen Bush
Browse files

Finishing up the form config to array conversions for all event types

parent 06373db9
No related branches found
No related tags found
No related merge requests found
......@@ -471,7 +471,7 @@ class EventSeries extends EditorialContentEntityBase implements EventInterface {
* The date object for the weekly start date.
*/
public function getWeeklyStartDate() {
return $this->get('weekly_recurring_date')->start_date;
return $this->get('weekly_recurring_date')->start_date->setTime(0, 0, 0);
}
/**
......@@ -481,7 +481,7 @@ class EventSeries extends EditorialContentEntityBase implements EventInterface {
* The date object for the weekly end date.
*/
public function getWeeklyEndDate() {
return $this->get('weekly_recurring_date')->end_date;
return $this->get('weekly_recurring_date')->end_date->setTime(0, 0, 0);
}
/**
......@@ -525,7 +525,7 @@ class EventSeries extends EditorialContentEntityBase implements EventInterface {
* The date object for the monthly start date.
*/
public function getMonthlyStartDate() {
return $this->get('monthly_recurring_date')->start_date;
return $this->get('monthly_recurring_date')->start_date->setTime(0, 0, 0);
}
/**
......@@ -535,7 +535,7 @@ class EventSeries extends EditorialContentEntityBase implements EventInterface {
* The date object for the monthly end date.
*/
public function getMonthlyEndDate() {
return $this->get('monthly_recurring_date')->end_date;
return $this->get('monthly_recurring_date')->end_date->setTime(0, 0, 0);
}
/**
......
......@@ -140,7 +140,7 @@ class EventCreationService {
public function convertFormConfigToArray(FormStateInterface $form_state) {
$config = [];
$date_timezone = new \DateTimeZone(drupal_get_user_timezone());
$user_timezone = new \DateTimeZone(drupal_get_user_timezone());
$utc_timezone = new \DateTimeZone(DATETIME_STORAGE_TIMEZONE);
$user_input = $form_state->getUserInput();
......@@ -148,11 +148,13 @@ class EventCreationService {
switch ($config['type']) {
case 'weekly':
$start_timestamp = $user_input['weekly_recurring_date'][0]['value']['date'] . 'T00:00:00';
$start_timestamp = $user_input['weekly_recurring_date'][0]['value']['date'] . 'T12:00:00';
$start_date = DrupalDateTime::createFromFormat(DATETIME_DATETIME_STORAGE_FORMAT, $start_timestamp, $utc_timezone);
$start_date->setTime(0, 0, 0);
$end_timestamp = $user_input['weekly_recurring_date'][0]['end_value']['date'] . 'T00:00:00';
$end_timestamp = $user_input['weekly_recurring_date'][0]['end_value']['date'] . 'T12:00:00';
$end_date = DrupalDateTime::createFromFormat(DATETIME_DATETIME_STORAGE_FORMAT, $end_timestamp, $utc_timezone);
$end_date->setTime(0, 0, 0);
$config['start_date'] = $start_date;
$config['end_date'] = $end_date;
......@@ -163,11 +165,13 @@ class EventCreationService {
break;
case 'monthly':
$start_timestamp = $user_input['weekly_recurring_date'][0]['value']['date'] . 'T00:00:00';
$start_timestamp = $user_input['weekly_recurring_date'][0]['value']['date'] . 'T12:00:00';
$start_date = DrupalDateTime::createFromFormat(DATETIME_DATETIME_STORAGE_FORMAT, $start_timestamp, $utc_timezone);
$start_date->setTime(0, 0, 0);
$end_timestamp = $user_input['weekly_recurring_date'][0]['end_value']['date'] . 'T00:00:00';
$end_timestamp = $user_input['weekly_recurring_date'][0]['end_value']['date'] . 'T12:00:00';
$end_date = DrupalDateTime::createFromFormat(DATETIME_DATETIME_STORAGE_FORMAT, $end_timestamp, $utc_timezone);
$end_date->setTime(0, 0, 0);
$config['start_date'] = $start_date;
$config['end_date'] = $end_date;
......@@ -191,21 +195,25 @@ class EventCreationService {
case 'custom':
foreach ($user_input['custom_date'] as $custom_date) {
$start_date = $end_date = NULL;
$start_timestamp = implode('T', $custom_date['value']);
$start_date = DrupalDateTime::createFromFormat(DATETIME_DATETIME_STORAGE_FORMAT, $start_timestamp, $date_timezone);
// Convert the DateTime object back to UTC timezone.
$start_date->setTimezone($utc_timezone);
$end_timestamp = implode('T', $custom_date['end_value']);
$end_date = DrupalDateTime::createFromFormat(DATETIME_DATETIME_STORAGE_FORMAT, $end_timestamp, $date_timezone);
// Convert the DateTime object back to UTC timezone.
$end_date->setTimezone($utc_timezone);
$config['custom_dates'][] = [
'start_date' => $start_date,
'end_date' => $end_date,
];
if (!empty($custom_date['value']['date'])
&& !empty($custom_date['value']['time'])
&& !empty($custom_date['end_value']['date'])
&& !empty($custom_date['end_value']['time'])) {
$start_timestamp = implode('T', $custom_date['value']);
$start_date = DrupalDateTime::createFromFormat(DATETIME_DATETIME_STORAGE_FORMAT, $start_timestamp, $user_timezone);
// Convert the DateTime object back to UTC timezone.
$start_date->setTimezone($utc_timezone);
$end_timestamp = implode('T', $custom_date['end_value']);
$end_date = DrupalDateTime::createFromFormat(DATETIME_DATETIME_STORAGE_FORMAT, $end_timestamp, $user_timezone);
// Convert the DateTime object back to UTC timezone.
$end_date->setTimezone($utc_timezone);
$config['custom_dates'][] = [
'start_date' => $start_date,
'end_date' => $end_date,
];
}
}
break;
}
......
......@@ -85,13 +85,13 @@ class WeeklyRecurringDateWidget extends DateRangeDefaultWidget {
$item['value'] = '';
}
else {
$item['value'] = substr($item['value'], 0, 10) . 'T00:00:00';
$item['value'] = substr($item['value'], 0, 10) . 'T12:00:00';
}
if (empty($item['end_value'])) {
$item['end_value'] = '';
}
else {
$item['end_value'] = substr($item['end_value'], 0, 10) . 'T00:00:00';
$item['end_value'] = substr($item['end_value'], 0, 10) . 'T12:00:00';
}
$item['days'] = array_filter($item['days']);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment