public function FeedsDateTime::__construct in Feeds 7.2
Same name and namespace in other branches
- 6 plugins/FeedsParser.inc \FeedsDateTime::__construct()
- 7 plugins/FeedsParser.inc \FeedsDateTime::__construct()
Overridden constructor.
Parameters
$time: time string, flexible format including timestamp. Invalid formats will fall back to 'now'.
$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 724 - Contains FeedsParser and related classes.
Class
- FeedsDateTime
- Extend PHP DateTime class with granularity handling, merge functionality and slightly more flexible initialization parameters.
Code
public function __construct($time = '', $tz = NULL) {
$this->originalValue = $time;
if (is_numeric($time)) {
// Assume UNIX timestamp if it doesn't look like a simple year.
if (strlen($time) > 4) {
$time = "@" . $time;
}
else {
$time = 'January ' . $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 (!date_create($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);
}