You are here

public function DateObject::hasGranularity in Date 7

Same name and namespace in other branches
  1. 7.3 date_api/date_api.module \DateObject::hasGranularity()
  2. 7.2 date_api/date_api.module \DateObject::hasGranularity()

Checks granularity array for a given entry. Accepts an array, in which case all items must be present (AND's the query)

4 calls to DateObject::hasGranularity()
DateObject::hasTime in date_api/date_api.module
Returns whether this object has time set. Used primarily for timezone conversion and formatting.
DateObject::merge in date_api/date_api.module
This function will keep this object's values by default.
DateObject::setTimezone in date_api/date_api.module
Overrides default DateTime function. Only changes output values if actually had time granularity. This should be used as a "converter" for output, to switch tzs.
DateObject::validGranularity in date_api/date_api.module

File

date_api/date_api.module, line 262
This module will make the date API available to other modules. Designed to provide a light but flexible assortment of functions and constants, with more functionality in additional files that are not loaded unless other modules specifically include them.

Class

DateObject
Extend PHP DateTime class with granularity handling, merge functionality and slightly more flexible initialization parameters.

Code

public function hasGranularity($g = NULL) {
  if ($g === NULL) {

    //just want to know if it has something valid

    //means no lower granularities without higher ones
    $last = TRUE;
    foreach (self::$allgranularity as $arg) {
      if ($arg == 'timezone') {
        continue;
      }
      if (in_array($arg, $this->granularity) && !$last) {
        return FALSE;
      }
      $last = in_array($arg, $this->granularity);
    }
    return in_array('year', $this->granularity);
  }
  if (is_array($g)) {
    foreach ($g as $gran) {
      if (!in_array($gran, $this->granularity)) {
        return FALSE;
      }
    }
    return TRUE;
  }
  return in_array($g, $this->granularity);
}