You are here

public function FeedsDateTime::__construct in Feeds 7

Same name and namespace in other branches
  1. 6 plugins/FeedsParser.inc \FeedsDateTime::__construct()
  2. 7.2 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 478

Class

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

Code

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

    // Assume timestamp.
    $time = "@" . $time;
  }

  // PHP < 5.3 doesn't like the GMT- notation for parsing timezones.
  $time = str_replace("GMT-", "-", $time);
  $time = str_replace("GMT+", "+", $time);
  parent::__construct($time, $tz ? $tz : new DateTimeZone("UTC"));
  $this
    ->setGranularityFromTime($time, $tz);
  if (!preg_match('/[a-zA-Z]/', $this
    ->getTimezone()
    ->getName())) {

    // This tz was given as just an offset, which causes problems
    $this
      ->setTimezone(new DateTimeZone("UTC"));
  }
}