diff options
author | Andrey Andreev <narf@bofh.bg> | 2012-06-14 01:43:07 +0200 |
---|---|---|
committer | Andrey Andreev <narf@bofh.bg> | 2012-06-14 01:43:07 +0200 |
commit | 35d6b35182b6ed65c34ca7bf06975b93f4cd403b (patch) | |
tree | 550e2351d5670951033338c9d394ca647ce584ee /system | |
parent | d461934184d95b0cfb2feec93f27b621ef72a5c2 (diff) | |
parent | 7400965017f87c3aba18bf75ed7d732359fd577d (diff) |
Merge pull request #1223 from Razican/new_date
New now() function for the Date helper
Diffstat (limited to 'system')
-rw-r--r-- | system/helpers/date_helper.php | 29 | ||||
-rw-r--r-- | system/libraries/Session.php | 14 |
2 files changed, 25 insertions, 18 deletions
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); } // -------------------------------------------------------------------- |