function date_sql_handler::arg_range in Date 6
Same name and namespace in other branches
- 5.2 date_api_sql.inc \date_sql_handler::arg_range()
- 6.2 date_api_sql.inc \date_sql_handler::arg_range()
- 7.3 date_api/date_api_sql.inc \date_sql_handler::arg_range()
- 7 date_api/date_api_sql.inc \date_sql_handler::arg_range()
- 7.2 date_api/date_api_sql.inc \date_sql_handler::arg_range()
Use the parsed values from the ISO argument to determine the min and max date for this period.
File
- ./
date_api_sql.inc, line 661
Class
- date_sql_handler
- A class to manipulate date SQL.
Code
function arg_range($arg) {
// Parse the argument to get its parts
$parts = $this
->arg_parts($arg);
// Intercept invalid info and fall back to the current date.
if (empty($parts[0]) || empty($parts[0]['date']) && empty($parts[0]['period'])) {
$now = date_now();
return array(
$now,
$now,
);
}
// Build a range from a period-only argument (assumes the min date is now.)
if (empty($parts[0]['date']) && !empty($parts[0]['period']) && (empty($parts[1]) || empty($parts[1]['date']))) {
$min_date = date_now();
$max_date = drupal_clone($min_date);
foreach ($parts[0]['period'] as $part => $value) {
date_modify($max_date, "+{$value} {$part}");
}
date_modify($max_date, '-1 second');
return array(
$min_date,
$max_date,
);
}
if (!empty($parts[0]['date'])) {
$min_date = date_make_date($this
->complete_date($parts[0]['date'], 'min'));
// Build a range from a single date-only argument.
if (empty($parts[1]) || empty($parts[1]['date']) && empty($parts[1]['period'])) {
$max_date = date_make_date($this
->complete_date($parts[0]['date'], 'max'));
return array(
$min_date,
$max_date,
);
}
elseif (!empty($parts[1]['period'])) {
foreach ($parts[1]['period'] as $part => $value) {
$max_date = drupal_clone($min_date);
date_modify($max_date, "+{$value} {$part}");
}
date_modify($max_date, '-1 second');
return array(
$min_date,
$max_date,
);
}
}
// Build a range from start date and end date.
if (!empty($parts[1]['date'])) {
$max_date = $this
->complete_date($parts[1]['date'], 'max');
if (isset($min_date)) {
return array(
$min_date,
$max_date,
);
}
}
// Build a range from period + end date.
if (!empty($parts[0]['period'])) {
foreach ($parts[0]['period'] as $part => $value) {
$min_date = drupal_clone($max_date);
date_modify($min_date, "-{$value} {$part}");
}
return array(
$min_date,
$max_date,
);
}
}