summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--date_api.module34
-rw-r--r--includes/date_api_filter_handler.inc2
2 files changed, 34 insertions, 2 deletions
diff --git a/date_api.module b/date_api.module
index 3202c70..6359908 100644
--- a/date_api.module
+++ b/date_api.module
@@ -518,11 +518,13 @@ class DateObject extends DateTime {
*
* @param $date
* An array of date parts or a datetime string with values to be forced into date.
+ * @param $granularity
+ * The granularity of the date.
* @param $default
* 'current' - default to current day values.
* 'first' - default to the first possible valid value.
*/
- public function setFuzzyDate($date, $default = 'first') {
+ public function setFuzzyDate($date, $granularity, $default = 'first') {
$comp = new DateObject($date, $this->getTimeZone()->getName());
$arr = $comp->toArray(TRUE);
foreach ($arr as $key => $value) {
@@ -984,6 +986,36 @@ function date_granularity_names() {
}
/**
+ * Give a granularity $precision, return an array of
+ * all the possible granularity elements.
+ */
+function date_granularity_array_from_precision($precision) {
+ $granularity_array = array('year', 'month', 'day', 'hour', 'minute', 'second');
+ switch(($precision)) {
+ case 'year':
+ return array_slice($granularity_array, -6);
+ case 'month':
+ return array_slice($granularity_array, -5);
+ case 'day':
+ return array_slice($granularity_array, -4);
+ case 'hour':
+ return array_slice($granularity_array, -3);
+ case 'minute':
+ return array_slice($granularity_array, -2);
+ default:
+ return $granularity_array;
+ }
+}
+
+/**
+ * Give a granularity array, return the highest precision.
+ */
+function date_granularity_precision($granularity_array) {
+ $input = clone($granularity_array);
+ return array_pop($input);
+}
+
+/**
* A translated array of timezone names.
* Cache the untranslated array, make the translated array a static variable.
*
diff --git a/includes/date_api_filter_handler.inc b/includes/date_api_filter_handler.inc
index 8228ad9..4703e72 100644
--- a/includes/date_api_filter_handler.inc
+++ b/includes/date_api_filter_handler.inc
@@ -496,7 +496,7 @@ class date_api_filter_handler extends views_handler_filter_numeric {
$date_handler = $query_field['date_handler'];
$this->format = $date_handler->views_formats($granularity, 'sql');
$date = date_now();
- $date->setFuzzyDate($this->value[$prefix]);
+ $date->setFuzzyDate($this->value[$prefix], $granularity);
$value = date_format($date, $this->format);
$range = $this->date_handler->arg_range($value);