public function date_sql_handler::arg_replace in Date 7.3
Same name and namespace in other branches
- 5.2 date_api_sql.inc \date_sql_handler::arg_replace()
- 6.2 date_api_sql.inc \date_sql_handler::arg_replace()
- 7 date_api/date_api_sql.inc \date_sql_handler::arg_replace()
- 7.2 date_api/date_api_sql.inc \date_sql_handler::arg_replace()
Convert strings like '+1 day' to the ISO equivalent, like 'P1D' .
File
- date_api/
date_api_sql.inc, line 1103 - SQL helper for Date API.
Class
- date_sql_handler
- A class to manipulate date SQL.
Code
public function arg_replace($arg) {
if (!preg_match('/([+|-])\\s?([0-9]{1,32})\\s?([day(s)?|week(s)?|month(s)?|year(s)?|hour(s)?|minute(s)?|second(s)?]{1,10})/', $arg, $results)) {
return str_replace('now', '@', $arg);
}
$direction = $results[1];
$count = $results[2];
$item = $results[3];
$replace = array(
'now' => '@',
'+' => 'P',
'-' => 'P-',
'years' => 'Y',
'year' => 'Y',
'months' => 'M',
'month' => 'M',
'weeks' => 'W',
'week' => 'W',
'days' => 'D',
'day' => 'D',
'hours' => 'H',
'hour' => 'H',
'minutes' => 'M',
'minute' => 'M',
'seconds' => 'S',
'second' => 'S',
' ' => '',
' ' => '',
);
$args = array(
'hours',
'hour',
'minutes',
'minute',
'seconds',
'second',
);
if (in_array($item, $args)) {
$prefix = 'T';
}
else {
$prefix = '';
}
$return = $prefix;
$return .= strtr($direction, $replace);
$return .= $count;
$return .= strtr($item, $replace);
return $return;
}