/** * given a set of meta data, prepare date data if it exists * * @param $data array Associative array of event meta data * * @return array */ protected static function prepare_event_date_meta($event_id, $data) { $date_provided = false; if (isset($data['EventAllDay'])) { if (Tribe__Date_Utils::is_all_day($data['EventAllDay'])) { $data['EventAllDay'] = 'yes'; } else { $data['EventAllDay'] = 'no'; } } $datepicker_format = Tribe__Date_Utils::datepicker_formats(tribe_get_option('datepickerFormat')); if (isset($data['EventStartDate'])) { $data['EventStartDate'] = Tribe__Date_Utils::datetime_from_format($datepicker_format, $data['EventStartDate']); } if (isset($data['EventEndDate'])) { $data['EventEndDate'] = Tribe__Date_Utils::datetime_from_format($datepicker_format, $data['EventEndDate']); } if (isset($data['EventAllDay']) && 'yes' === $data['EventAllDay']) { $date_provided = true; $data['EventStartDate'] = tribe_beginning_of_day($data['EventStartDate']); $data['EventEndDate'] = tribe_end_of_day($data['EventEndDate']); } elseif (isset($data['EventStartDate']) && isset($data['EventEndDate'])) { $date_provided = true; delete_post_meta($event_id, '_EventAllDay'); $start_date_string = "{$data['EventStartDate']} {$data['EventStartHour']}:{$data['EventStartMinute']}:00"; $end_date_string = "{$data['EventEndDate']} {$data['EventEndHour']}:{$data['EventEndMinute']}:00"; if (isset($data['EventStartMeridian'])) { $start_date_string .= " {$data['EventStartMeridian']}"; } if (isset($data['EventEndMeridian'])) { $end_date_string .= " {$data['EventEndMeridian']}"; } $data['EventStartDate'] = date(Tribe__Date_Utils::DBDATETIMEFORMAT, strtotime($start_date_string)); $data['EventEndDate'] = date(Tribe__Date_Utils::DBDATETIMEFORMAT, strtotime($end_date_string)); } if (!$date_provided) { $data['EventStartDate'] = get_post_meta($event_id, '_EventStartDate', true); $data['EventEndDate'] = get_post_meta($event_id, '_EventEndDate', true); return $data; } // If a specific timezone was not specified, default to the sitewide timezone if (!isset($data['EventTimezone'])) { $data['EventTimezone'] = Tribe__Events__Timezones::wp_timezone_string(); } // Additionally store datetimes in UTC if (empty($data['EventStartDateUTC'])) { $data['EventStartDateUTC'] = Tribe__Events__Timezones::to_utc($data['EventStartDate'], $data['EventTimezone']); } if (empty($data['EventEndDateUTC'])) { $data['EventEndDateUTC'] = Tribe__Events__Timezones::to_utc($data['EventEndDate'], $data['EventTimezone']); } if (empty($data['EventTimezoneAbbr'])) { $data['EventTimezoneAbbr'] = Tribe__Events__Timezones::abbr($data['EventStartDate'], $data['EventTimezone']); } // sanity check that start date < end date $start_timestamp = strtotime($data['EventStartDate']); $end_timestamp = strtotime($data['EventEndDate']); if ($start_timestamp > $end_timestamp) { $data['EventEndDate'] = $data['EventStartDate']; } $data['EventDuration'] = strtotime($data['EventEndDate']) - $start_timestamp; return $data; }