public function DateObject::setTimezone

cis7 date_api.module public DateObject::setTimezone($tz, $force = FALSE)
cle7 date_api.module public DateObject::setTimezone($tz, $force = FALSE)
elmsmedia7 date_api.module public DateObject::setTimezone($tz, $force = FALSE)
icor7 date_api.module public DateObject::setTimezone($tz, $force = FALSE)
meedjum_blog7 date_api.module public DateObject::setTimezone($tz, $force = FALSE)
mooc7 date_api.module public DateObject::setTimezone($tz, $force = FALSE)

Sets the time zone for the current date.

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.

Parameters

object $tz: A timezone object.

bool $force: Whether or not to skip a date with no time. Defaults to FALSE.

1 call to DateObject::setTimezone()
DateObject::__construct in sites/all/modules/ulmus/date/date_api/date_api.module
Constructs a date object.

File

sites/all/modules/ulmus/date/date_api/date_api.module, line 346
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 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('timezone') || $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(TRUE);
    parent::setTimezone($tz);
    $this->setDate($arr['year'], $arr['month'], $arr['day']);
    $this->setTime($arr['hour'], $arr['minute'], $arr['second']);
    $this->addGranularity('timezone');
    return;
  }
  return parent::setTimezone($tz);
}
Error | ELMSLN API

Error

×

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/api.elmsln.org/includes/common.inc:2791) in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/api.elmsln.org/includes/bootstrap.inc).
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/api.elmsln.org/sites/all/modules/apc/drupal_apc_cache.inc).
The website encountered an unexpected error. Please try again later.