function date_offset in Date 5
A function to calculate offset using timezone.inc file
Parameters
$date_parts - an array of date parts in the format created by getdate(): @param $timezone - the timezone to use @return $offset - the offset of $timezone from GMT on the $date_parts date
2 calls to date_offset()
- date_convert_timezone in ./
date.inc - Timezone conversion function
- date_format_date in ./
date.inc - Format date
File
- ./
date.inc, line 395 - Date/time API functions
Code
function date_offset($date_parts, $timezone = 'GMT') {
include_once './' . drupal_get_path('module', 'date_api') . '/date_timezones.inc';
// no adjustment needed for gmt dates
if ($timezone == 'GMT') {
return 0;
}
// find the timezone info for the input timezone
$timezones = array_flip(date_zonelist());
$zid = $timezones[$timezone];
// create a timestamp for the date to be evaluated
if ($date_parts['year'] < 1970) {
// fudge offset for dates prior to 1970 by finding the offset in 1971
$date_parts['year'] = 1971;
$timestamp = date_array2unix($date_parts);
}
else {
$timestamp = $date_parts[0];
}
return date_get_offset($zid, $timestamp);
}