You are here

public function DateObject::toArray in Date 7

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

Helper to return all standard date parts in an array. Will return '' for parts in which it lacks granularity.

1 call to DateObject::toArray()
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.

File

date_api/date_api.module, line 487
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 toArray($force = FALSE) {
  return array(
    'year' => $this
      ->format('Y', $force),
    'month' => $this
      ->format('n', $force),
    'day' => $this
      ->format('j', $force),
    'hour' => intval($this
      ->format('H', $force)),
    'minute' => intval($this
      ->format('i', $force)),
    'second' => intval($this
      ->format('s', $force)),
    'timezone' => $this
      ->format('e', $force),
  );
}