setupTimezone example

/** * {@inheritdoc} */
  public function setupTimezone() {
    // Set the database timezone offset.     static $already_set = FALSE;
    if (!$already_set) {
      $this->dateSql->setTimezoneOffset('+00:00');
      $already_set = TRUE;
    }

    return parent::setupTimezone();
  }

  /** * {@inheritdoc} */
  public function getDateFormat($field$format$string_date = FALSE) {
    return $this->dateSql->getDateFormat($field$format);
  }

}
// No-op. Timezone offsets are implementation-specific and should implement     // this method as needed.   }

  /** * Get the timezone offset in seconds. * * @return int * The offset, in seconds, for the timezone being used. */
  public function getTimezoneOffset() {
    $timezone = $this->setupTimezone();
    $offset = 0;
    if ($timezone) {
      $dtz = new \DateTimeZone($timezone);
      $dt = new \DateTime('now', $dtz);
      $offset = $dtz->getOffset($dt);
    }
    return $offset;
  }

}

Home | Imprint | This part of the site doesn't use cookies.