diff options
Diffstat (limited to 'system/helpers')
-rw-r--r-- | system/helpers/date_helper.php | 47 |
1 files changed, 22 insertions, 25 deletions
diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index c601dc9e5..d5036f645 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); } } @@ -315,13 +314,13 @@ if ( ! function_exists('local_to_gmt')) $time = time(); } - return mktime( - gmdate('H', $time), - gmdate('i', $time), - gmdate('s', $time), - gmdate('m', $time), - gmdate('d', $time), - gmdate('Y', $time) + return gmmktime( + date('H', $time), + date('i', $time), + date('s', $time), + date('m', $time), + date('d', $time), + date('Y', $time) ); } } @@ -376,9 +375,7 @@ if ( ! function_exists('mysql_to_unix')) // since the formatting changed with MySQL 4.1 // YYYY-MM-DD HH:MM:SS - $time = str_replace('-', '', $time); - $time = str_replace(':', '', $time); - $time = str_replace(' ', '', $time); + $time = str_replace(array('-', ':', ' '), '', $time); // YYYYMMDDHHMMSS return mktime( |