summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2012-06-14 01:43:07 +0200
committerAndrey Andreev <narf@bofh.bg>2012-06-14 01:43:07 +0200
commit35d6b35182b6ed65c34ca7bf06975b93f4cd403b (patch)
tree550e2351d5670951033338c9d394ca647ce584ee
parentd461934184d95b0cfb2feec93f27b621ef72a5c2 (diff)
parent7400965017f87c3aba18bf75ed7d732359fd577d (diff)
Merge pull request #1223 from Razican/new_date
New now() function for the Date helper
-rw-r--r--application/config/config.php14
-rw-r--r--system/helpers/date_helper.php29
-rw-r--r--system/libraries/Session.php14
-rw-r--r--user_guide_src/source/changelog.rst1
-rw-r--r--user_guide_src/source/helpers/date_helper.rst18
-rw-r--r--user_guide_src/source/installation/upgrade_300.rst11
6 files changed, 55 insertions, 32 deletions
diff --git a/application/config/config.php b/application/config/config.php
index 2628885f0..31ff2024d 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'] = "";
@@ -362,10 +362,10 @@ $config['compress_output'] = FALSE;
| Master Time Reference
|--------------------------------------------------------------------------
|
-| 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.
+| Options are 'local' or any PHP supported timezone. This pref tells the
+| system whether to use your server's local time as the master 'now'
+| reference, or convert it to any PHP supported timezone. See the 'date
+| helper' page of the user guide for information regarding date handling.
|
*/
$config['time_reference'] = 'local';
diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php
index c601dc9e5..a5c46e47b 100644
--- a/system/helpers/date_helper.php
+++ b/system/helpers/date_helper.php
@@ -42,29 +42,28 @@ 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
+ * "time_reference" setting
*
+ * @param string
* @return int
*/
- function now()
+ function now($timezone = NULL)
{
- $CI =& get_instance();
-
- if (strtolower($CI->config->item('time_reference')) === 'gmt')
+ if (empty($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.');
- }
+ $timezone = config_item('time_reference');
+ }
- return $system_time;
+ if ($timezone === 'local' OR $timezone === date_default_timezone_get())
+ {
+ return time();
}
- return time();
+ $datetime = new DateTime('now', new DateTimeZone($timezone));
+ sscanf($datetime->format('j-n-Y G:i:s'), '%d-%d-%d %d:%d:%d', $day, $month, $year, $hour, $minute, $second);
+
+ return mktime($hour, $minute, $second, $month, $day, $year);
}
}
diff --git a/system/libraries/Session.php b/system/libraries/Session.php
index 7beedd96b..9fdf744c3 100644
--- a/system/libraries/Session.php
+++ b/system/libraries/Session.php
@@ -786,9 +786,17 @@ class CI_Session {
*/
protected function _get_time()
{
- return (strtolower($this->time_reference) === 'gmt')
- ? mktime(gmdate('H'), gmdate('i'), gmdate('s'), gmdate('m'), gmdate('d'), gmdate('Y'))
- : time();
+ $timezone = config_item('time_reference');
+
+ if ($timezone === 'local' OR $timezone === date_default_timezone_get())
+ {
+ return time();
+ }
+
+ $datetime = new DateTime('now', new DateTimeZone($timezone));
+ sscanf($datetime->format('j-n-Y G:i:s'), '%d-%d-%d %d:%d:%d', $day, $month, $year, $hour, $minute, $second);
+
+ return mktime($hour, $minute, $second, $month, $day, $year);
}
// --------------------------------------------------------------------
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 039e8acf3..1f5bcb648 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -48,6 +48,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..1b7177fc2 100644
--- a/user_guide_src/source/helpers/date_helper.rst
+++ b/user_guide_src/source/helpers/date_helper.rst
@@ -21,13 +21,21 @@ 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
+server's local time or any PHP suported timezone, based on the "time reference"
+setting in your config file. If you do not intend to set your master time reference
+to any other PHP suported timezone (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()
+.. php:method:: now($timezone = NULL)
+
+ :param string $timezone: The timezone you want to be returned
+ :returns: integer
+
+::
+ echo now("Australia/Victoria");
+
+If a timezone is not provided, it will return time() based on "time_reference" setting.
mdate()
=======
diff --git a/user_guide_src/source/installation/upgrade_300.rst b/user_guide_src/source/installation/upgrade_300.rst
index 63c4227dc..d8a3d5bc1 100644
--- a/user_guide_src/source/installation/upgrade_300.rst
+++ b/user_guide_src/source/installation/upgrade_300.rst
@@ -41,8 +41,15 @@ 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 can now select all PHP supported timezones in the `time_reference` setting, listed here:
+`Supported timezones <http://www.php.net/timezones>`_. You can also use 'local' if you want to get time().
+
+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