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

thekevinday’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.