1 date_sql_handler.inc | date_sql_handler::arg_range($arg) |
Use the parsed values from the ISO argument to determine the min and max date for this period.
File
- core/
modules/ date/ views/ date_sql_handler.inc, line 844 - SQL helper for Date API.
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);
// 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]))) {
$min_date = date_now();
$max_date = 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);
}
// Build a range from a period to period argument.
if (empty($parts[0]['date']) && !empty($parts[0]['period']) && !empty($parts[1]['period'])) {
$min_date = date_now();
$max_date = clone($min_date);
foreach ($parts[0]['period'] as $part => $value) {
date_modify($min_date, "+$value $part");
}
date_modify($min_date, '-1 second');
foreach ($parts[1]['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'])) {
$value = $this->complete_date($parts[0]['date'], 'min');
$min_date = new BackdropDateTime($value, date_default_timezone(), DATE_FORMAT_DATETIME);
// Build a range from a single date-only argument.
if (empty($parts[1]) || (empty($parts[1]['date']) && empty($parts[1]['period']))) {
$value = $this->complete_date($parts[0]['date'], 'max');
$max_date = new BackdropDateTime($value, date_default_timezone(), DATE_FORMAT_DATETIME);
return array($min_date, $max_date);
}
// Build a range from start date + period.
elseif (!empty($parts[1]['period'])) {
foreach ($parts[1]['period'] as $part => $value) {
$max_date = 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'])) {
$value = $this->complete_date($parts[1]['date'], 'max');
$max_date = new BackdropDateTime($value, date_default_timezone(), DATE_FORMAT_DATETIME);
if (isset($min_date)) {
return array($min_date, $max_date);
}
}
// Build a range from period + end date.
if (!empty($parts[0]['period'])) {
$min_date = date_now();
foreach ($parts[0]['period'] as $part => $value) {
date_modify($min_date, "$value $part");
}
return array($min_date, $max_date);
}
// Intercept invalid info and fall back to the current date.
$now = date_now();
return array($now, $now);
}