diff options
-rw-r--r-- | application/config/config.php | 16 | ||||
-rw-r--r-- | index.php | 2 | ||||
-rw-r--r-- | system/helpers/date_helper.php | 28 | ||||
-rw-r--r-- | user_guide_src/source/changelog.rst | 1 | ||||
-rw-r--r-- | user_guide_src/source/helpers/date_helper.rst | 22 | ||||
-rw-r--r-- | user_guide_src/source/installation/upgrade_300.rst | 10 |
6 files changed, 45 insertions, 34 deletions
diff --git a/application/config/config.php b/application/config/config.php index 2628885f0..eb3ddddb0 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -204,7 +204,7 @@ $config['directory_trigger'] = 'd'; // experimental not currently in use | 4 = All Messages | | You can also pass in a array with threshold levels to show individual error types -| +| | array(2) = Debug Messages, without Error Messages | | For a live site you'll usually only enable Errors (1) to be logged otherwise @@ -253,7 +253,7 @@ $config['cache_path'] = ''; | | If you use the Encryption class or the Session class you | MUST set an encryption key. See the user guide for info. -| +| | http://codeigniter.com/user_guide/libraries/encryption.html | http://codeigniter.com/user_guide/libraries/sessions.html | @@ -297,7 +297,7 @@ $config['sess_time_to_update'] = 300; | 'cookie_domain' = Set to .your-domain.com for site-wide cookies | 'cookie_path' = Typically will be a forward slash | 'cookie_secure' = Cookies will only be set if a secure HTTPS connection exists. -| 'cookie_httponly' = Cookie will only be accessible via HTTP(S) (no javascript) +| 'cookie_httponly' = Cookie will only be accessible via HTTP(S) (no javascript) | */ $config['cookie_prefix'] = ""; @@ -359,16 +359,14 @@ $config['compress_output'] = FALSE; /* |-------------------------------------------------------------------------- -| Master Time Reference +| Master Timezone |-------------------------------------------------------------------------- | -| Options are 'local' or 'gmt'. This pref tells the system whether to use -| your server's local time as the master 'now' reference, or convert it to -| GMT. See the 'date helper' page of the user guide for information -| regarding date handling. +| You can set any PHP supported timezones to be the master timezone when +| you call the now() function. | */ -$config['time_reference'] = 'local'; +$config['timezone'] = 'UTC'; /* @@ -162,6 +162,8 @@ if (defined('ENVIRONMENT')) // END OF USER CONFIGURABLE SETTINGS. DO NOT EDIT BELOW THIS LINE // -------------------------------------------------------------------- +date_default_timezone_set('UTC'); + /* * --------------------------------------------------------------- * Resolve the system path for increased reliability diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index c601dc9e5..3b0c3289d 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -42,29 +42,27 @@ if ( ! function_exists('now')) /** * Get "now" time * - * Returns time() or its GMT equivalent based on the config file preference + * Returns time() based on the timezone parameter or on the "timezone" + * setting * + * @param string * @return int */ - function now() + function now($timezone = NULL) { - $CI =& get_instance(); + $CI =& get_instance(); - if (strtolower($CI->config->item('time_reference')) === 'gmt') + if (is_null($timezone)) { - $now = time(); - $system_time = mktime(gmdate("H", $now), gmdate("i", $now), gmdate("s", $now), gmdate("m", $now), gmdate("d", $now), gmdate("Y", $now)); - - if (strlen($system_time) < 10) - { - $system_time = time(); - log_message('error', 'The Date class could not set a proper GMT timestamp so the local time() value was used.'); - } - - return $system_time; + $timezone = $CI->config->item('timezone'); } - return time(); + $timezone = new DateTimeZone($timezone); + $now = new DateTime('now', $timezone); + $offset = $timezone->getOffset($now); + $time = time() + $offset; + + return $time; } } diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 25b42b2e0..80507b284 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -45,6 +45,7 @@ Release Date: Not Released - Helpers + - Date helper will now return now() based on the timezone you specify. - ``create_captcha()`` accepts additional colors parameter, allowing for color customization. - ``url_title()`` will now trim extra dashes from beginning and end. - Added XHTML Basic 1.1 doctype to :doc:`HTML Helper <helpers/html_helper>`. diff --git a/user_guide_src/source/helpers/date_helper.rst b/user_guide_src/source/helpers/date_helper.rst index 18216c5a2..b6c6ed4bb 100644 --- a/user_guide_src/source/helpers/date_helper.rst +++ b/user_guide_src/source/helpers/date_helper.rst @@ -20,14 +20,20 @@ The following functions are available: now() ===== -Returns the current time as a Unix timestamp, referenced either to your -server's local time or GMT, based on the "time reference" setting in -your config file. If you do not intend to set your master time reference -to GMT (which you'll typically do if you run a site that lets each user -set their own timezone settings) there is no benefit to using this -function over PHP's time() function. - -.. php:method:: now() +Returns the current time as a Unix timestamp, based on the "timezone" parameter. +All PHP available timezones are supported. + +.. php:method:: now($timezone = NULL) + + :param string $timezone: The timezone you want to be returned + :returns: integer + +:: + + $tz = "Australia/Victoria"; + echo now($tz); + +If a timezone is not provided, it will return time() based on "timezone" setting. mdate() ======= diff --git a/user_guide_src/source/installation/upgrade_300.rst b/user_guide_src/source/installation/upgrade_300.rst index 63c4227dc..503e5366c 100644 --- a/user_guide_src/source/installation/upgrade_300.rst +++ b/user_guide_src/source/installation/upgrade_300.rst @@ -41,8 +41,14 @@ need to rename the `$active_record` variable to `$query_builder`. $active_group = 'default'; // $active_record = TRUE; $query_builder = TRUE; - -Step 5: Move your errors folder + +Step 5: Change your use of the Date helper's now() function +=========================================================== + +Function now() has been modified. You can see the changes in :doc:`Date Helper <../helpers/date_helper>` +You must replace $config['time_reference'] with $config['timezone'] in your config.php file. + +Step 6: Move your errors folder =============================== In version 3.0.0, the errors folder has been moved from "application/errors" to "application/views/errors".
\ No newline at end of file |