Closed (fixed)
Project:
Common Functionality
Version:
7.x-1.x-dev
Component:
Code
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
8 Dec 2010 at 20:04 UTC
Updated:
23 Dec 2010 at 21:20 UTC
function cf_utc_strtotime($date_string, array $function_history = array()){
if (cf_is_empty_or_non_string(__FUNCTION__, 'date_string', $date_string, WATCHDOG_ERROR, $function_history)){
return NULL;
}
date_default_timezone_set('UTC');
$time_data = strtotime($date_string);
date_default_timezone_set(date_default_timezone_name());
return $time_data;
}
The justification for this code is
* Why:
* The date module stores date values in UTC format.
* When using inline scripts to call views for custom purposes there is a need to safely convert this utc date value without changing the current timezone.
*
The date module works using DataTime objects (see http://us2.php.net/manual/en/class.datetime.php). You can use these to change the timezone without changing the default timezone. The timezone should be changed for only the single time being worked on and not the default value.
If you want to use things like date_format_date() which can be used for localization of date strings you need to use DateTime objects because that's the first parameter.
Comments
Comment #1
thekevinday commented