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 */ /**