function partial_date_field_populate_components in Partial Date 7
This generates the best estimate for the date components based on the submitted values.
1 call to partial_date_field_populate_components()
- _partial_date_field_presave in ./
partial_date.admin.inc - Implements hook_field_presave().
File
- ./
partial_date.admin.inc, line 226 - Less freq. functions for field administration.
Code
function partial_date_field_populate_components($item, $start_date = TRUE) {
$base = array(
'year' => $start_date ? PD2_YEAR_MIN : PD2_YEAR_MAX,
'month' => $start_date ? 1 : 12,
'day' => 0,
// Calculate last as this is variable
'hour' => $start_date ? 0 : 23,
'minute' => $start_date ? 0 : 59,
'second' => $start_date ? 0 : 59,
'timezone' => '',
);
foreach (partial_date_components() as $key => $label) {
$value_key = $start_date ? $key : $key . '_to';
if (isset($item[$value_key]) && strlen($item[$value_key])) {
$base[$key] = $item[$value_key];
}
}
if (empty($base['day'])) {
if ($start_date) {
$base['day'] = 1;
}
else {
$month_table = partial_date_month_matrix($base['year']);
if (isset($month_table[$base['month'] - 1])) {
$base['day'] = $month_table[$base['month'] - 1];
}
else {
$base['day'] = 31;
}
}
}
return $base;
}