You are here

public function FeedsDateTime::__construct in Feeds 6

Same name and namespace in other branches
  1. 7.2 plugins/FeedsParser.inc \FeedsDateTime::__construct()
  2. 7 plugins/FeedsParser.inc \FeedsDateTime::__construct()

Overridden constructor.

Parameters

$time: time string, flexible format including timestamp.

$tz: PHP DateTimeZone object, NULL allowed

1 call to FeedsDateTime::__construct()
FeedsDateTime::__wakeup in plugins/FeedsParser.inc
Upon unserializing, we must re-build ourselves using local variables.

File

plugins/FeedsParser.inc, line 500

Class

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

Code

public function __construct($time = '', $tz = NULL) {

  // Assume UNIX timestamp if numeric.
  if (is_numeric($time)) {
    $time = "@" . $time;
  }

  // PHP < 5.3 doesn't like the GMT- notation for parsing timezones.
  $time = str_replace("GMT-", "-", $time);
  $time = str_replace("GMT+", "+", $time);

  // Some PHP 5.2 version's DateTime class chokes on invalid dates.
  if (!strtotime($time)) {
    $time = 'now';
  }

  // Create and set time zone separately, PHP 5.2.6 does not respect time zone
  // argument in __construct().
  parent::__construct($time);
  $tz = $tz ? $tz : new DateTimeZone("UTC");
  $this
    ->setTimeZone($tz);

  // Verify that timezone has not been specified as an offset.
  if (!preg_match('/[a-zA-Z]/', $this
    ->getTimezone()
    ->getName())) {
    $this
      ->setTimezone(new DateTimeZone("UTC"));
  }

  // Finally set granularity.
  $this
    ->setGranularityFromTime($time, $tz);
}