From cc12302f47b19b3057e4a85d50373fb56cd175f0 Mon Sep 17 00:00:00 2001 From: Guillaume Viguier Date: Sat, 13 Mar 2010 10:45:37 -0500 Subject: [PATCH] Date and time - Chamilo - CT#696 --- main/inc/lib/main_api.lib.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/main/inc/lib/main_api.lib.php b/main/inc/lib/main_api.lib.php index a322df3ae5..49e69d449a 100755 --- a/main/inc/lib/main_api.lib.php +++ b/main/inc/lib/main_api.lib.php @@ -4410,6 +4410,23 @@ function api_convert_and_format_date($time = null, $format = null, $from_timezon return api_format_date($time, $format); } +/** + * Converts a string into a timestamp safely (handling timezones), using strtotime + * + * @param string String to be converted + * @param string Timezone (if null, the timezone will be determined based on user preference, or timezone chosen by the admin for the platform) + * @return int Timestamp + * + * @author Guillaume Viguier + */ +function api_strtotime($time, $timezone = null) { + $system_timezone = date_default_timezone_get(); + date_default_timezone_set($timezone); + $timestamp = strtotime($time); + date_default_timezone_set($system_timezone); + return $timestamp; +} + /* DEPRECATED FUNCTIONS */ /**