function event_validate_form_date in Event 5
Same name and namespace in other branches
- 5.2 event.module \event_validate_form_date()
Validates the start and end times in a node form submission.
- Changes 24 hour time to 12 hour time (if the module is configured to do this).
- Adjusts times for time zone offsets.
Parameters
$node The submitted node with form data.:
$date The name of the event's date ('start' or 'end') to validate and set.:
Related topics
1 call to event_validate_form_date()
- event_nodeapi in ./
event.module - hook_nodeapi implementation
File
- ./
event.module, line 1534
Code
function event_validate_form_date(&$node, $date) {
$prefix = $date . '_';
/**
* If using javascript pop-up calendar, convert input date back to individual date parts expected by the validator
*/
if (module_exists('jscalendar')) {
$get = $prefix . 'date';
$this_date = $node->{$get};
$timestamp = mktime(substr($this_date, 11, 2), substr($this_date, 14, 2), substr($this_date, 17, 2), substr($this_date, 5, 2), substr($this_date, 8, 2), substr($this_date, 0, 4));
$node->{$prefix . 'year'} = date('Y', $timestamp);
$node->{$prefix . 'month'} = date('n', $timestamp);
$node->{$prefix . 'day'} = date('d', $timestamp);
if (variable_get('event_ampm', '0')) {
$node->{$prefix . 'ampm'} = substr($this_date, 11, 2) >= 12 ? 'pm' : 'am';
}
$node->{$prefix . 'hour'} = variable_get('event_ampm', '0') ? date('g', $timestamp) : date('H', $timestamp);
$node->{$prefix . 'minute'} = date('i', $timestamp);
}
// If we have all the parameters, re-calculate $node->event_$date .
if (isset($node->{$prefix . 'year'}) && isset($node->{$prefix . 'month'}) && isset($node->{$prefix . 'day'}) && isset($node->{$prefix . 'hour'}) && isset($node->{$prefix . 'minute'})) {
$hour = $node->{$prefix . 'hour'};
if (variable_get('event_ampm', '0')) {
if ($node->{$prefix . 'ampm'} == 'pm' && $hour != 12) {
$hour += 12;
}
elseif ($node->{$prefix . 'ampm'} == 'am' && $hour == 12) {
$hour -= 12;
}
}
// translate the input values to GMT and set the node property value
$offset = event_get_offset($node->timezone, gmmktime($hour, $node->{$prefix . 'minute'}, 0, $node->{$prefix . 'month'}, $node->{$prefix . 'day'}, $node->{$prefix . 'year'}));
$node->{'event_' . $date} = _event_mktime($hour, $node->{$prefix . 'minute'}, 0, $node->{$prefix . 'month'}, $node->{$prefix . 'day'}, $node->{$prefix . 'year'}, $offset);
}
elseif (!$node->{$date}) {
// Round to nearest hour:
$now = _event_user_time();
$node->{$date} = $now - $now % (60 * 60);
}
}