diff options
author | Iban Eguia <admin@razican.com> | 2012-06-11 13:58:30 +0200 |
---|---|---|
committer | Iban Eguia <admin@razican.com> | 2012-06-11 13:58:30 +0200 |
commit | c88daba688d309150a7dce43817ab76ec7834bda (patch) | |
tree | df1515a2fbd6cb29798271301807b6a7768df8c1 /system/helpers | |
parent | a9617a35ce4af051d3ad1298c2c24453460754cc (diff) |
Optimized now() function. Thanks to @narfbg
Diffstat (limited to 'system/helpers')
-rw-r--r-- | system/helpers/date_helper.php | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index d5acec23f..b818da9d8 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -50,25 +50,20 @@ if ( ! function_exists('now')) */ function now($timezone = NULL) { - $CI =& get_instance(); - - if (is_null($timezone)) + if (empty($timezone)) { - $timezone = $CI->config->item('timezone'); + $timezone = config_item('timezone'); } - $time = time(); - if(strtolower($timezone) != 'local') + if ($timezone === 'local' OR $timezone === date_default_timezone_get()) { - $local = new DateTime(NULL, new DateTimeZone(date_default_timezone_get())); - $now = new DateTime(NULL, new DateTimeZone($timezone)); - $lcl_offset = $local->getOffset(); - $tz_offset = $now->getOffset(); - $offset = $tz_offset - $lcl_offset; - $time = $time + $offset; + 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); } } |