You are here

public function DateGranularity::setGranularityFromTime in Date 8

Create a granularity array from a string time value.

Parameters

string $time: A date string.

1 call to DateGranularity::setGranularityFromTime()
DateGranularity::__construct in date_api/lib/Drupal/date_api/DateGranularity.php
Constructor. Create a granularity instance.

File

date_api/lib/Drupal/date_api/DateGranularity.php, line 102
Definition of DateGranularity.

Class

DateGranularity
This class manages granularity. It can set granularity, get it from an array, get it from a format string, see if the array has any time or date elements, set and unset various granularity parts, create a nongranularity array of the granularity parts…

Namespace

Drupal\date_api

Code

public function setGranularityFromTime($time) {
  $this->granularity = array();
  $temp = date_parse($time);
  foreach ($this->granularity_parts as $part) {
    if (isset($temp[$part]) && is_numeric($temp[$part])) {
      $this
        ->addGranularity($part);
    }
  }
}