public function FeedsDateTime::setTimezone in Feeds 8.2
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.
In order to set a timezone for a datetime that doesn't have such granularity, merge() it with one that does.
1 call to FeedsDateTime::setTimezone()
- FeedsDateTime::__construct in lib/
Drupal/ feeds/ FeedsDateTime.php - Overridden constructor.
File
- lib/
Drupal/ feeds/ FeedsDateTime.php, line 120
Class
- FeedsDateTime
- Extend PHP DateTime class with granularity handling, merge functionality and slightly more flexible initialization parameters.
Namespace
Drupal\feedsCode
public function setTimezone($tz, $force = FALSE) {
// PHP 5.2.6 has a fatal error when setting a date's timezone to itself.
// http://bugs.php.net/bug.php?id=45038
if (version_compare(PHP_VERSION, '5.2.7', '<') && $tz == $this
->getTimezone()) {
$tz = new \DateTimeZone($tz
->getName());
}
if (!$this
->hasTime() || !$this
->hasGranularity('zone') || $force) {
// this has no time or timezone granularity, so timezone doesn't mean much
// We set the timezone using the method, which will change the day/hour, but then we switch back
$arr = $this
->toArray();
parent::setTimezone($tz);
$this
->setDate($arr['year'], $arr['month'], $arr['day']);
$this
->setTime($arr['hour'], $arr['minute'], $arr['second']);
return;
}
parent::setTimezone($tz);
}