Changeset 660 for trunk/lib/App.inc.php


Ignore:
Timestamp:
Jan 28, 2019 10:51:50 PM (5 years ago)
Author:
anonymous
Message:

Reduce timezone support to simply setting defaults for user, php, and mysql (all UTC), just to ensure consistency

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/App.inc.php

    r659 r660  
    119119        'sql_time_format' => '%k:%i',
    120120
     121        // Timezone support. No codebase apps currently support switching timezones, but we explicitly set these so they're consistent.
     122        'user_timezone' => 'UTC',
     123        'php_timezone' => 'UTC',
     124        'mysql_timezone' => 'UTC',
     125
    121126        // Use php sessions?
    122127        'enable_session' => false,
     
    370375        }
    371376
    372         // If the 'timezone' parameter is not set, check for a tz cookie.
    373         if (!$this->getParam('timezone') && isset($_COOKIE['tz']) && '' != $_COOKIE['tz']) {
    374             if (preg_match('!^[A-Z_/-]{3,}$!i', $_COOKIE['tz'])) {
    375                 // Valid: tz cookie has a timezone name, like "UTC" or "America/Mexico_City".
    376                 $this->setParam(array('timezone' => $_COOKIE['tz']));
    377             } else if (is_numeric($_COOKIE['tz']) && $_COOKIE['tz'] > -12 && $_COOKIE['tz'] < 14) { // https://en.wikipedia.org/wiki/List_of_UTC_time_offsets#UTC+14:00,_M%E2%80%A0
    378                 // tz cookie has a timezone offset, like "-6" (assume UTC).
    379                 $tz = timezone_name_from_abbr('', $_COOKIE['tz'] * 3600, 0);
    380                 if ($tz && preg_match('!^[A-Z_/-]{3,}$!i', $tz)) {
    381                     // Valid.
    382                     $this->setParam(array('timezone' => $tz));
    383                 } else {
    384                     $this->logMsg(sprintf('Failed to convert UTC offset to timezone: %s', $_COOKIE['tz']), LOG_NOTICE, __FILE__, __LINE__);
    385                 }
    386             } else {
    387                 $this->logMsg(sprintf('Invalid timezone cookie value: %s', $_COOKIE['tz']), LOG_NOTICE, __FILE__, __LINE__);
    388             }
    389         }
    390         if ($this->getParam('timezone')) {
    391             // Set timezone of the user.
    392             if (date_default_timezone_set($this->getParam('timezone'))) {
    393                 $this->logMsg(sprintf('Using timezone: %s', $this->getParam('timezone')), LOG_DEBUG, __FILE__, __LINE__);
    394             } else {
    395                 // Failed: unset the timezone parameter so it isn't used to set the database timezone.
    396                 $this->setParam(array('timezone' => null));
    397                 $this->logMsg(sprintf('Failed to set timezone: %s', $this->getParam('timezone')), LOG_NOTICE, __FILE__, __LINE__);
    398             }
    399         } else {
    400             $this->logMsg(sprintf('Using server timezone: %s', date_default_timezone_get()), LOG_DEBUG, __FILE__, __LINE__);
     377        // Server timezone used internally by PHP.
     378        if ($this->getParam('php_timezone')) {
     379            $this->setTimezone($this->getParam('php_timezone'));
    401380        }
    402381
     
    446425                'db_debug' => $this->getParam('db_debug'),
    447426                'db_die_on_failure' => $this->getParam('db_die_on_failure'),
     427                'timezone' => $this->getParam('mysql_timezone'),
    448428            ));
    449429
     
    17061686        return $ret;
    17071687    }
     1688
     1689    /*
     1690    * Set timezone used internally by PHP.
     1691    *
     1692    * @access   public
     1693    * @param    string  $tz     Timezone, e.g., America/Mexico_City
     1694    * @return
     1695    * @author   Quinn Comendant <quinn@strangecode.com>
     1696    * @since    28 Jan 2019 16:38:38
     1697    */
     1698    public function setTimezone($tz)
     1699    {
     1700        $this->setTimezone();
     1701        // Set timezone for PHP.
     1702        if (date_default_timezone_set($tz)) {
     1703            $this->logMsg(sprintf('Using php timezone: %s', $tz), LOG_DEBUG, __FILE__, __LINE__);
     1704        } else {
     1705            // Failed!
     1706            $this->logMsg(sprintf('Failed to set php timezone: %s', $tz), LOG_WARNING, __FILE__, __LINE__);
     1707        }
     1708    }
    17081709} // End.
Note: See TracChangeset for help on using the changeset viewer.