function node_import_check_date in Node import 6
Check if the value is a valid date.
Uses: $field['output_format'] (output format type - defaults to DATE_UNIX). Uses: $options['date_format'], $options['date_custom'] and $options['timezone'] (default to date_default_timezone_name()).
Related topics
1 string reference to 'node_import_check_date'
- node_import_fields in ./
node_import.inc - Returns a list of available content fields for given node_import type.
File
- ./
node_import.inc, line 1189 - Public API of the Node import module.
Code
function node_import_check_date(&$value, $field, $options, $preview) {
$timezone = isset($options['timezone']) ? $options['timezone'] : date_default_timezone_name();
$input_format = $options['date_format'] == 'custom' ? $options['date_custom'] : $options['date_format'];
$output_format = isset($field['output_format']) ? $field['output_format'] : DATE_UNIX;
if (date_is_valid($value, DATE_ISO)) {
$value = date_convert($value, DATE_ISO, $output_format, $timezone);
return TRUE;
}
module_load_include('inc', 'date_api', 'date_api_elements');
if ($date = date_convert_from_custom($value, $input_format)) {
// It is useless to check for date_is_valid() as it is a DATE_DATETIME already.
$value = date_convert($date, DATE_DATETIME, $output_format, $timezone);
return TRUE;
}
if (date_is_valid($value, DATE_UNIX)) {
$value = date_convert($value, DATE_UNIX, $output_format, $timezone);
return TRUE;
}
node_import_input_error(t('Input error: %value is not allowed for %name (not a date in %date format).', array(
'%value' => $value,
'%name' => $field['title'],
'%date' => format_date(time(), 'custom', $input_format),
)));
return FALSE;
}