public static function get_local_timezone($reset = FALSE)
 {
     if ($reset) {
         self::$local_timezone = NULL;
     }
     if (!isset(self::$local_timezone)) {
         $tzstring = get_option('timezone_string');
         if (empty($tzstring)) {
             $gmt_offset = get_option('gmt_offset');
             if ($gmt_offset == 0) {
                 $tzstring = 'UTC';
             } else {
                 $gmt_offset *= HOUR_IN_SECONDS;
                 $tzstring = timezone_name_from_abbr('', $gmt_offset);
                 if (false === $tzstring) {
                     $is_dst = date('I');
                     foreach (timezone_abbreviations_list() as $abbr) {
                         foreach ($abbr as $city) {
                             if ($city['dst'] == $is_dst && $city['offset'] == $gmt_offset) {
                                 $tzstring = $city['timezone_id'];
                                 break 2;
                             }
                         }
                     }
                 }
                 if (false === $tzstring) {
                     $tzstring = 'UTC';
                 }
             }
         }
         self::$local_timezone = new DateTimeZone($tzstring);
     }
     return self::$local_timezone;
 }
Beispiel #2
0
 static function getTimeZonesArray($choose_one = null)
 {
     $timezones = array();
     if (function_exists("timezone_name_from_abbr")) {
         if (!is_null($choose_one)) {
             $timezones[null] = $choose_one;
         }
         for ($x = -12; $x <= 14; $x++) {
             $tz_name = timezone_name_from_abbr("", $x * 60 * 60, 0);
             if ($tz_name != "") {
                 $timezones[$tz_name] = "[GMT";
                 if ($x > 0) {
                     $timezones[$tz_name] .= " +" . $x;
                 } elseif ($x < 0) {
                     $timezones[$tz_name] .= " " . $x;
                 }
                 $timezones[$tz_name] .= "] ";
                 $timezones[$tz_name] .= str_replace("_", " ", $tz_name);
             }
         }
     } else {
         $timezones = array('Pacific/Apia' => '[GMT -11] Pacific/Apia', 'Pacific/Honolulu' => '[GMT -10] Pacific/Honolulu', 'America/Anchorage' => '[GMT -9] America/Anchorage', 'America/Los_Angeles' => '[GMT -8] America/Los Angeles', 'America/Denver' => '[GMT -7] America/Denver', 'America/Chicago' => '[GMT -6] America/Chicago', 'America/New_York' => '[GMT -5] America/New York', 'America/Halifax' => '[GMT -4] America/Halifax', 'America/Sao_Paulo' => '[GMT -3] America/Sao Paulo', 'Atlantic/Azores' => '[GMT -1] Atlantic/Azores', 'Europe/London' => '[GMT] Europe/London', 'Europe/Paris' => '[GMT +1] Europe/Paris', 'Europe/Helsinki' => '[GMT +2] Europe/Helsinki', 'Europe/Moscow' => '[GMT +3] Europe/Moscow', 'Asia/Dubai' => '[GMT +4] Asia/Dubai', 'Asia/Karachi' => '[GMT +5] Asia/Karachi', 'Asia/Krasnoyarsk' => '[GMT +7] Asia/Krasnoyarsk', 'Asia/Tokyo' => '[GMT +9] Asia/Tokyo', 'Australia/Melbourne' => '[GMT +10] Australia/Melbourne', 'Pacific/Auckland' => '[GMT +12] Pacific/Auckland');
     }
     return $timezones;
 }
Beispiel #3
0
 /** Diff two date objects. Only full units are returned */
 public static function diff(TimeInterval $interval, Date $date1, Date $date2) : int
 {
     if ($date1->getOffsetInSeconds() != $date2->getOffsetInSeconds()) {
         // Convert date2 to same timezone as date1. To work around PHP bug #45038,
         // not just take the timezone of date1, but construct a new one which will
         // have a timezone ID - which is required for this kind of computation.
         $tz = new TimeZone(timezone_name_from_abbr('', $date1->getOffsetInSeconds(), $date1->toString('I')));
         // Now, convert both dates to the same time (actually we only need to convert the
         // second one, as the first will remain in the same timezone)
         $date2 = $tz->translate($date2);
     }
     // Then cut off timezone, by setting both to GMT
     $date1 = DateUtil::setTimeZone($date1, new TimeZone('GMT'));
     $date2 = DateUtil::setTimeZone($date2, new TimeZone('GMT'));
     switch ($interval) {
         case TimeInterval::$YEAR:
             return -($date1->getYear() - $date2->getYear());
         case TimeInterval::$MONTH:
             return -(($date1->getYear() - $date2->getYear()) * 12 + ($date1->getMonth() - $date2->getMonth()));
         case TimeInterval::$DAY:
             return -(intval($date1->getTime() / 86400) - intval($date2->getTime() / 86400));
         case TimeInterval::$HOURS:
             return -(intval($date1->getTime() / 3600) - intval($date2->getTime() / 3600));
         case TimeInterval::$MINUTES:
             return -(intval($date1->getTime() / 60) - intval($date2->getTime() / 60));
         case TimeInterval::$SECONDS:
             return -($date1->getTime() - $date2->getTime());
     }
 }
 /**
  * Returns the timezone string for a site, even if it's set to a UTC offset
  *
  * Adapted from http://www.php.net/manual/en/function.timezone-name-from-abbr.php#89155
  *
  * @return string valid PHP timezone string
  */
 private function determine_timezone_string()
 {
     // If site timezone string exists, return it.
     if ($timezone = get_option('timezone_string')) {
         return $timezone;
     }
     // Get UTC offset, if it isn't set then return UTC.
     if (0 === ($utc_offset = get_option('gmt_offset', 0))) {
         return 'UTC';
     }
     // Adjust UTC offset from hours to seconds.
     $utc_offset *= HOUR_IN_SECONDS;
     // Attempt to guess the timezone string from the UTC offset.
     $timezone = timezone_name_from_abbr('', $utc_offset);
     // Last try, guess timezone string manually.
     if (false === $timezone) {
         $is_dst = date('I');
         foreach (timezone_abbreviations_list() as $abbr) {
             foreach ($abbr as $city) {
                 if ($city['dst'] == $is_dst && $city['offset'] == $utc_offset) {
                     return $city['timezone_id'];
                 }
             }
         }
     }
     // Fallback to UTC.
     return 'UTC';
 }
/**
 * Retrieve the timezone id.
 *
 * Credit: Pippin Williamson & the rest of the EDD team.
 *
 * @return  string
 * @since   1.0.0
 */
function charitable_get_timezone_id()
{
    $timezone = get_option('timezone_string');
    /* If site timezone string exists, return it */
    if ($timezone) {
        return $timezone;
    }
    $utc_offset = 3600 * get_option('gmt_offset', 0);
    /* Get UTC offset, if it isn't set return UTC */
    if (!$utc_offset) {
        return 'UTC';
    }
    /* Attempt to guess the timezone string from the UTC offset */
    $timezone = timezone_name_from_abbr('', $utc_offset);
    /* Last try, guess timezone string manually */
    if ($timezone === false) {
        $is_dst = date('I');
        foreach (timezone_abbreviations_list() as $abbr) {
            foreach ($abbr as $city) {
                if ($city['dst'] == $is_dst && $city['offset'] == $utc_offset) {
                    return $city['timezone_id'];
                }
            }
        }
    }
    /* If we still haven't figured out the timezone, fall back to UTC */
    return 'UTC';
}
 public static function get_timezone_id()
 {
     // if site timezone string exists, return it
     if ($timezone = get_option('timezone_string')) {
         return $timezone;
     }
     // get UTC offset, if it isn't set return UTC
     if (!($utc_offset = 3600 * get_option('gmt_offset', 0))) {
         return 'UTC';
     }
     // attempt to guess the timezone string from the UTC offset
     $timezone = timezone_name_from_abbr('', $utc_offset);
     // last try, guess timezone string manually
     if (FALSE === $timezone) {
         $is_dst = date('I');
         foreach (timezone_abbreviations_list() as $abbr) {
             foreach ($abbr as $city) {
                 if ($city['dst'] == $is_dst && $city['offset'] == $utc_offset) {
                     return $city['timezone_id'];
                 }
             }
         }
     }
     return 'UTC';
     // fallback
 }
 /**
  * Returns the timezone string for a site, even if it's set to a UTC offset
  *
  * Adapted from http://www.php.net/manual/en/function.timezone-name-from-abbr.php#89155
  *
  * @return string valid PHP timezone string
  */
 private static function wp_get_timezone_string()
 {
     $blog_timezone = get_option('timezone_string');
     $blog_gmt_offset = get_option('gmt_offset', 0);
     // if site timezone string exists, return it
     if ($timezone = $blog_timezone) {
         return $timezone;
     }
     // get UTC offset, if it isn't set then return UTC
     if (0 === ($utc_offset = $blog_gmt_offset)) {
         return 'UTC';
     }
     // adjust UTC offset from hours to seconds
     $utc_offset *= 3600;
     // attempt to guess the timezone string from the UTC offset
     if ($timezone = timezone_name_from_abbr('', $utc_offset, 0)) {
         return $timezone;
     }
     // last try, guess timezone string manually
     $is_dst = date('I');
     foreach (timezone_abbreviations_list() as $abbr) {
         foreach ($abbr as $city) {
             if ($city['dst'] == $is_dst && $city['offset'] == $utc_offset) {
                 return $city['timezone_id'];
             }
         }
     }
     // fallback to UTC
     return 'UTC';
 }
 /**
  * Return DateTimeZone name.
  *
  * @param int $offset
  * @return string timezone name.
  */
 public static function getTimezone($offset = 0)
 {
     $name = timezone_name_from_abbr(null, $offset * 3600, true);
     if ($name === false) {
         $name = timezone_name_from_abbr(null, $offset * 3600, false);
     }
     return $name;
 }
Beispiel #9
0
 public static function getTimezoneValue($offset, $format = 'e')
 {
     if (!$offset) {
         $offset = '+00:00';
     }
     $t1 = \DateTime::createFromFormat($format, $offset);
     return timezone_name_from_abbr($t1->format('T'), $t1->format('Z'), -0);
 }
Beispiel #10
0
 public static function timezoneOffsetSecondsToTimezoneName($seconds)
 {
     $timezoneAbbreviation = timezone_name_from_abbr('', $seconds, 1);
     if ($timezoneAbbreviation === false) {
         $timezoneAbbreviation = timezone_name_from_abbr('', $seconds, 0);
     }
     return $timezoneAbbreviation;
 }
Beispiel #11
0
function setTimezoneByOffset($offset)
{
    $is_DST = FALSE;
    // observing daylight savings?
    $timezone_name = timezone_name_from_abbr('', $offset * 3600, $is_DST);
    // e.g. "America/New_York"
    date_default_timezone_set($timezone_name);
}
 /**
  * Retrieve a JSON object containing a time zone name given a timezone
  * abbreviation.
  *
  * @param string $abbreviation
  *   Time zone abbreviation.
  * @param int $offset
  *   Offset from GMT in seconds. Defaults to -1 which means that first found
  *   time zone corresponding to abbr is returned. Otherwise exact offset is
  *   searched and only if not found then the first time zone with any offset
  *   is returned.
  * @param null|bool $is_daylight_saving_time
  *   Daylight saving time indicator. If abbr does not exist then the time
  *   zone is searched solely by offset and isdst.
  *
  * @return JsonResponse
  *   The timezone name in JsonResponse object.
  */
 public function getTimezone($abbreviation = '', $offset = -1, $is_daylight_saving_time = NULL)
 {
     // An abbreviation of "0" passed in the callback arguments should be
     // interpreted as the empty string.
     $abbreviation = $abbreviation ? $abbreviation : '';
     $timezone = timezone_name_from_abbr($abbreviation, intval($offset), $is_daylight_saving_time);
     return new JsonResponse($timezone);
 }
Beispiel #13
0
 public static function createUser(array $data, array $provider, array $externalToken, array $externalVisitor, XenForo_Model_UserExternal $userExternalModel)
 {
     $user = null;
     /** @var bdApiConsumer_XenForo_Model_UserExternal $userExternalModel */
     $options = XenForo_Application::get('options');
     /** @var XenForo_DataWriter_User $writer */
     $writer = XenForo_DataWriter::create('XenForo_DataWriter_User');
     if ($options->registrationDefaults) {
         $writer->bulkSet($options->registrationDefaults, array('ignoreInvalidFields' => true));
     }
     if (!isset($data['timezone']) and isset($externalVisitor['user_timezone_offset'])) {
         $tzOffset = $externalVisitor['user_timezone_offset'];
         $tzName = timezone_name_from_abbr('', $tzOffset, 1);
         if ($tzName !== false) {
             $data['timezone'] = $tzName;
         }
     }
     if (!empty($data['user_id'])) {
         $writer->setImportMode(true);
     }
     $writer->bulkSet($data);
     if (!empty($data['user_id'])) {
         $writer->setImportMode(false);
     }
     $writer->set('email', $externalVisitor['user_email']);
     if (!empty($externalVisitor['user_gender'])) {
         $writer->set('gender', $externalVisitor['user_gender']);
     }
     if (!empty($externalVisitor['user_dob_day']) && !empty($externalVisitor['user_dob_month']) && !empty($externalVisitor['user_dob_year'])) {
         $writer->set('dob_day', $externalVisitor['user_dob_day']);
         $writer->set('dob_month', $externalVisitor['user_dob_month']);
         $writer->set('dob_year', $externalVisitor['user_dob_year']);
     }
     if (!empty($externalVisitor['user_register_date'])) {
         $writer->set('register_date', $externalVisitor['user_register_date']);
     }
     $userExternalModel->bdApiConsumer_syncUpOnRegistration($writer, $externalToken, $externalVisitor);
     $auth = XenForo_Authentication_Abstract::create('XenForo_Authentication_NoPassword');
     $writer->set('scheme_class', $auth->getClassName());
     $writer->set('data', $auth->generate(''), 'xf_user_authenticate');
     $writer->set('user_group_id', XenForo_Model_User::$defaultRegisteredGroupId);
     $writer->set('language_id', XenForo_Visitor::getInstance()->get('language_id'));
     $writer->advanceRegistrationUserState(false);
     // TODO: option for extra user group
     $writer->preSave();
     if ($writer->hasErrors()) {
         return $user;
     }
     try {
         $writer->save();
         $user = $writer->getMergedData();
         $userExternalModel->bdApiConsumer_updateExternalAuthAssociation($provider, $externalVisitor['user_id'], $user['user_id'], array_merge($externalVisitor, array('token' => $externalToken)));
         XenForo_Model_Ip::log($user['user_id'], 'user', $user['user_id'], 'register_api_consumer');
     } catch (XenForo_Exception $e) {
         XenForo_Error::logException($e, false);
     }
     return $user;
 }
function convert_utc_offset_abbr($offset)
{
    $timezone = (int) preg_replace('/[^0-9]/', '', $offset);
    $tz = timezone_name_from_abbr(NULL, $timezone * 3600, TRUE);
    if ($tz === FALSE) {
        $tz = timezone_name_from_abbr(NULL, $offset * 3600, FALSE);
    }
    return (string) $tz;
}
Beispiel #15
0
 /**
  * Set default timezone using offset seconds
  */
 public function setTimezoneOffset($offset = 0, $dlst = false)
 {
     $offset = intval($offset);
     if ($timezone = @timezone_name_from_abbr("", $offset, $dlst)) {
         $this->timezone = $timezone;
         $this->offset = $offset;
         return @date_default_timezone_set($timezone);
     }
     return false;
 }
 protected function fetchAttributes()
 {
     $info = $this->makeSignedRequest('https://api.twitter.com/1/account/verify_credentials.json');
     $this->attributes['id'] = $info->id;
     $this->attributes['name'] = $info->name;
     $this->attributes['url'] = 'http://twitter.com/account/redirect_by_id?id=' . $info->id_str;
     $this->attributes['username'] = $info->screen_name;
     $this->attributes['language'] = $info->lang;
     $this->attributes['timezone'] = timezone_name_from_abbr('', $info->utc_offset, date('I'));
     $this->attributes['photo'] = $info->profile_image_url;
 }
Beispiel #17
0
 public static function detect()
 {
     if (isset($_COOKIE['timezone_offset'])) {
         $offset = (int) $_COOKIE['timezone_offset'];
         $dst = !empty($_COOKIE['timezone_dst']);
         $zone = timezone_name_from_abbr(null, 60 * 60 * $offset, $dst);
         if ($zone) {
             return $zone;
         }
     }
 }
Beispiel #18
0
 /**
  * {@inheritdoc}
  */
 public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property)
 {
     $offset = $value;
     // Convert the integer value of the offset (which can be either
     // negative or positive) to a timezone name.
     // Note: Daylight saving time is not to be used.
     $timezone_name = timezone_name_from_abbr('', intval($offset), 0);
     if (!$timezone_name) {
         $timezone_name = 'UTC';
     }
     return $timezone_name;
 }
Beispiel #19
0
 public function processValues()
 {
     $config_array = array();
     $config_array = $_POST['config'];
     // transform the GMTOFFSET (3600 = GMT+1) into a timezone name, like "Europe/Berlin".
     $config_array['language']['timezone'] = (string) timezone_name_from_abbr('', $_POST['config']['language']['gmtoffset'], 0);
     // write Settings to clansuite.config.php
     if (false === Helper::write_config_settings($config_array)) {
         $this->setStep(5);
         $this->setErrorMessage('Config not written <br />');
     }
 }
 protected function fetchAttributes()
 {
     $info = $this->makeSignedRequest('account/verify_credentials.json');
     $this->attributes['id'] = $info['id'];
     $this->attributes['name'] = $info['name'];
     $this->attributes['url'] = 'http://twitter.com/account/redirect_by_id?id=' . $info['id_str'];
     $this->attributes['username'] = $info['screen_name'];
     $this->attributes['language'] = $info['lang'];
     $this->attributes['timezone'] = timezone_name_from_abbr('', $info['utc_offset'], date('I'));
     $this->attributes['photo'] = $info['profile_image_url'];
     return true;
 }
 protected function setTimeZone($timezone)
 {
     if ($timezone) {
         if (strpos($timezone, '.') !== false) {
             list($hours, $minutes) = explode('.', $timezone);
             $offset = $hours . '.' . round($minutes / 60 * 100);
             $timezone = timezone_name_from_abbr('', $offset * 3600, 0);
         }
         if ($timezone) {
             date_default_timezone_set($timezone);
         }
     }
 }
 public static function timezone()
 {
     $string = get_option('timezone_string');
     if ($string && $string != '') {
         date_default_timezone_set($string);
     } else {
         $offset = round(get_option('gmt_offset'));
         $offset = $offset < -11 ? -11 : ($offset > 13 ? 13 : $offset);
         $string = timezone_name_from_abbr(null, $offset * 3600, true);
         $string = $string ? $string : timezone_name_from_abbr(null, $offset * 3600, false);
         date_default_timezone_set($string);
     }
     return $string;
 }
 static function offset2timezone($offset)
 {
     list($offset, $isdst) = explode(",", $offset);
     list($hOffset, $mOffset) = explode(':', $offset);
     $gmtOffset = $hOffset * 3600;
     $gmtOffset += $mOffset * 60;
     // add skipped minutes
     $t = new DateTime("now", new DateTimeZone('Europe/London'));
     if (!$t->format("I") && $isdst) {
         $isdst = false;
     }
     $timezone = timezone_name_from_abbr(null, $gmtOffset, $isdst);
     return $timezone;
 }
Beispiel #24
0
 /** Sets up current timezone */
 protected function initDateTimeZone()
 {
     $timezoneString = get_option('timezone_string');
     $gmtOffset = get_option('gmt_offset');
     if (!empty($gmtOffset) and empty($timezoneString)) {
         $offset = floatval(floor($gmtOffset)) * 3600;
         $timezoneString = timezone_name_from_abbr(null, $offset, 0);
     }
     if (empty($timezoneString)) {
         $timezoneString = date_default_timezone_get();
     }
     $this->timezone = new DateTimeZone($timezoneString);
     date_default_timezone_set($timezoneString);
 }
Beispiel #25
0
 /**
  * Create new object and try to identify the timezone
  */
 public function __construct()
 {
     if (self::$success !== null) {
         return;
     }
     if (Platform::isCli() === false && array_key_exists(self::$cookieName, $_COOKIE)) {
         list($offset, $dst) = explode(',', $_COOKIE[self::$cookieName]);
         $timezoneName = timezone_name_from_abbr('', (int) $offset, (int) $dst);
         self::$success = (bool) $timezoneName;
         if (self::$success === true) {
             self::$offset = $offset;
             self::$timezoneName = $timezoneName;
         }
     }
 }
 /**
  * @throws \yii\base\ExitException
  */
 public function run()
 {
     $timezone = Yii::$app->getRequest()->post('timezone', false);
     $zoneList = DateTimeZone::listIdentifiers();
     if (empty($timezone) || !in_array($timezone, $zoneList)) {
         $timezoneAbbr = Yii::$app->getRequest()->post('timezoneAbbr');
         $timezoneOffset = Yii::$app->getRequest()->post('timezoneOffset');
         $timezone = timezone_name_from_abbr($timezoneAbbr, $timezoneOffset * 3600);
     }
     if (!$timezone || !in_array($timezone, $zoneList)) {
         $timezone = date_default_timezone_get();
     }
     Yii::$app->session->set('timezone', $timezone);
     Yii::$app->end();
 }
Beispiel #27
0
function rdebug_utc($offset = null)
{
    if (is_null($offset)) {
        $offset = isset($_COOKIE['UTC']) ? intval($_COOKIE['UTC']) : -8;
    }
    $rdebug_utc_num = $offset;
    /* At client side, you could:
          var nUTC=((new Date()).getTimezoneOffset() / -60);
          document.cookie = "UTC=" + nUTC + ";";
       */
    $is_DST = FALSE;
    // observing daylight savings?
    $timezone_name = timezone_name_from_abbr('', $offset * 3600, $is_DST);
    date_default_timezone_set($timezone_name);
}
 public function get_predefined_intervals()
 {
     $timezone = get_option('timezone_string');
     if (empty($timezone)) {
         $gmt_offset = (int) get_option('gmt_offset');
         $timezone = timezone_name_from_abbr(null, $gmt_offset * 3600, true);
         if (false === $timezone) {
             $timezone = timezone_name_from_abbr(null, $gmt_offset * 3600, false);
         }
         if (false === $timezone) {
             $timezone = null;
         }
     }
     return apply_filters('mainwp_wp_stream_predefined_date_intervals', array('today' => array('label' => esc_html__('Today', 'default'), 'start' => Carbon::today($timezone)->startOfDay(), 'end' => Carbon::today($timezone)->startOfDay()), 'yesterday' => array('label' => esc_html__('Yesterday', 'mainwp-child-reports'), 'start' => Carbon::today($timezone)->startOfDay()->subDay(), 'end' => Carbon::today($timezone)->startOfDay()->subSecond()), 'last-7-days' => array('label' => sprintf(esc_html__('Last %d Days', 'mainwp-child-reports'), 7), 'start' => Carbon::today($timezone)->subDays(7), 'end' => Carbon::today($timezone)), 'last-14-days' => array('label' => sprintf(esc_html__('Last %d Days', 'mainwp-child-reports'), 14), 'start' => Carbon::today($timezone)->subDays(14), 'end' => Carbon::today($timezone)), 'last-30-days' => array('label' => sprintf(esc_html__('Last %d Days', 'mainwp-child-reports'), 30), 'start' => Carbon::today($timezone)->subDays(30), 'end' => Carbon::today($timezone)), 'this-month' => array('label' => esc_html__('This Month', 'mainwp-child-reports'), 'start' => Carbon::today($timezone)->day(1)), 'last-month' => array('label' => esc_html__('Last Month', 'mainwp-child-reports'), 'start' => Carbon::today($timezone)->day(1)->subMonth(), 'end' => Carbon::today($timezone)->day(1)->subSecond()), 'last-3-months' => array('label' => sprintf(esc_html__('Last %d Months', 'mainwp-child-reports'), 3), 'start' => Carbon::today($timezone)->subMonths(3), 'end' => Carbon::today($timezone)), 'last-6-months' => array('label' => sprintf(esc_html__('Last %d Months', 'mainwp-child-reports'), 6), 'start' => Carbon::today($timezone)->subMonths(6), 'end' => Carbon::today($timezone)), 'last-12-months' => array('label' => sprintf(esc_html__('Last %d Months', 'mainwp-child-reports'), 12), 'start' => Carbon::today($timezone)->subMonths(12), 'end' => Carbon::today($timezone)), 'this-year' => array('label' => esc_html__('This Year', 'mainwp-child-reports'), 'start' => Carbon::today($timezone)->day(1)->month(1)), 'last-year' => array('label' => esc_html__('Last Year', 'mainwp-child-reports'), 'start' => Carbon::today($timezone)->day(1)->month(1)->subYear(), 'end' => Carbon::today($timezone)->day(1)->month(1)->subSecond())), $timezone);
 }
Beispiel #29
0
 function __construct($zone)
 {
     //if string offset
     if (is_string($zone)) {
         $this->DisplayedZone = $this->getNeatZoneForString($zone);
     }
     //if int offset, checks for int or numeric string
     if (is_numeric($zone)) {
         $offset = $zone;
         //check daylight savings time
         if (date('I')) {
             $offset -= 1;
         }
         $this->DisplayedZone = $this->getNeatZoneForString(timezone_name_from_abbr("", $offset * 3600, false));
     }
 }
Beispiel #30
0
 /**
  * @throws \yii\base\ExitException
  */
 public function run()
 {
     //dd(\Yii::$app->getRequest()->get('timezone', false));
     $timezone = \Yii::$app->getRequest()->post('timezone', false);
     $zoneList = \DateTimeZone::listIdentifiers();
     if (!$timezone || empty($timezone) || !in_array($timezone, $zoneList)) {
         $timezoneAbbr = \Yii::$app->getRequest()->get('timezoneAbbr');
         $timezoneOffset = \Yii::$app->getRequest()->get('timezoneOffset');
         $timezone = timezone_name_from_abbr($timezoneAbbr, $timezoneOffset * 3600);
     }
     if (!$timezone || !in_array($timezone, $zoneList)) {
         $timezone = date_default_timezone_get();
     }
     \Yii::$app->session->set('timezone', $timezone);
     return $this->goBack();
 }