function webform_strtodate in Webform 6.3
Same name and namespace in other branches
- 7.4 webform.module \webform_strtodate()
- 7.3 webform.module \webform_strtodate()
Return a date in the desired format taking into consideration user timezones.
3 calls to webform_strtodate()
- webform_expand_date in components/
date.inc - Form API #process function for Webform date fields.
- webform_expand_time in components/
time.inc - Form API #process function for Webform time fields.
- _webform_filter_values in ./
webform.module - Filters all special tokens provided by webform, such as %post and %profile.
File
- ./
webform.module, line 3559
Code
function webform_strtodate($format, $string, $timezone_name = NULL) {
global $user;
// Adjust the time based on the user or site timezone.
// The "timezone_name" variable is provided by DateAPI in Drupal 6.
if (variable_get('configurable_timezones', 1) && $timezone_name == 'user' && $user->uid) {
$timezone_name = isset($GLOBALS['user']->timezone_name) ? $GLOBALS['user']->timezone_name : NULL;
}
// If the timezone is still empty or not set, use the site timezone.
if (empty($timezone_name) || $timezone_name == 'user') {
$timezone_name = variable_get('date_default_timezone_name', NULL);
}
if (!empty($timezone_name) && class_exists('DateTimeZone')) {
// Suppress errors if encountered during string conversion. Exceptions are
// only supported for DateTime in PHP 5.3 and higher.
try {
@($timezone = new DateTimeZone($timezone_name));
@($datetime = new DateTime($string, $timezone));
return @$datetime
->format($format);
} catch (Exception $e) {
return '';
}
}
else {
return date($format, strtotime($string));
}
}