/**
  * return the timezone set for the WP install
  * @return string valid timezone string for PHP DateTimeZone() class
  */
 public static function get_timezone()
 {
     return EEH_DTT_Helper::get_valid_timezone_string();
 }
 /**
  * See $_timezone property for description of what the timezone property is for.  This SETS the timezone internally for being able to reference what timezone we are running conversions on when converting TO the internal timezone (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp).
  *  This is available to all child classes that may be using the EE_Datetime_Field for a field data type.
  *
  * @access public
  * @param string $timezone A valid timezone string as described by @link http://www.php.net/manual/en/timezones.php
  * @return void
  */
 public function set_timezone($timezone = '')
 {
     EE_Registry::instance()->load_helper('DTT_Helper');
     $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone);
     //make sure we clear all cached properties because they won't be relevant now
     $this->_clear_cached_properties();
     //make sure we update field settings and the date for all EE_Datetime_Fields
     $model_fields = $this->get_model()->field_settings(false);
     foreach ($model_fields as $field_name => $field_obj) {
         if ($field_obj instanceof EE_Datetime_Field) {
             $field_obj->set_timezone($this->_timezone);
             if (isset($this->_fields[$field_name]) && $this->_fields[$field_name] instanceof DateTime) {
                 $this->_fields[$field_name]->setTimezone(new DateTimeZone($this->_timezone));
             }
         }
     }
 }
 /**
  * This will take an incoming timezone string and return the abbreviation for that timezone
  * @param  string $timezone_string
  * @return string           abbreviation
  */
 public function get_timezone_abbrev($timezone_string)
 {
     $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string);
     $dateTime = new DateTime('now', new DateTimeZone($timezone_string));
     return $dateTime->format('T');
 }
 /**
  * 	test_get_timezone_string_from_gmt_offset
  */
 function test_get_timezone_string_from_gmt_offset()
 {
     // TEST 4: gmt offsets
     $orig_timezone_string = get_option('timezone_string');
     $orig_gmt_offset = get_option('gmt_offset');
     // set timezone string to empty string
     update_option('timezone_string', '');
     $gmt_offsets = array(-12, -11.5, -11, -10.5, -10, -9.5, -9, -8.5, -8, -7.5, -7, -6.5, -6, -5.5, -5, -4.5, -4, -3.5, -3, -2.5, -2, -1.5, -1, -0.5, 0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 5.75, 6, 6.5, 7, 7.5, 8, 8.5, 8.75, 9, 9.5, 10, 10.5, 11, 11.5, 12, 12.75, 13, 13.75, 14);
     foreach ($gmt_offsets as $gmt_offset) {
         update_option('gmt_offset', $gmt_offset);
         try {
             $timezone_string = EEH_DTT_Helper::get_valid_timezone_string();
             if (empty($timezone_string)) {
                 $this->fail(sprintf(__('The WP GMT offset setting %1$s has resulted in an invalid timezone_string!', 'event_espresso'), $gmt_offset));
             }
         } catch (EE_Error $e) {
             $gmt_offset = $gmt_offset >= 0 ? '+' . (string) $gmt_offset : (string) $gmt_offset;
             $gmt_offset = str_replace(array('.25', '.5', '.75'), array(':15', ':30', ':45'), $gmt_offset);
             $gmt_offset = 'UTC' . $gmt_offset;
             $this->fail(sprintf(__('The WP GMT offset setting %1$s has thrown an Exception, but should not have!', 'event_espresso'), $gmt_offset));
             unset($gmt_offset);
         }
     }
     update_option('timezone_string', $orig_timezone_string);
     update_option('gmt_offset', $orig_gmt_offset);
 }