You are here

function date_append_zone in Date 5

A function to append the zone offset or name to a display

Alternative to timezone identifiers in format string needed because format string tz identification may display server zone rather than site or date zone no option for zone abbreviation (i.e. EST) because zone abbreviations are not unique, nor are they available in the timezone.inc data

Parameters

$type - the type of display desired:

  • '0000' will display zone offset like -0500
  • '00:00' will display zone offset like -05:00
  • 'name' will display zone name

File

./date.inc, line 541
Date/time API functions

Code

function date_append_zone($date, $type = '') {
  if (!$type) {
    return;
  }
  $offset = intval($date->local->offset);
  $hours = intval($offset / 3600);
  $minutes = intval($offset / 60 - $hours * 60);
  switch (trim($type)) {
    case '0000':
      return ' ' . sprintf('%+05d', $hours * 100);
    case '00:00':
      return ' ' . sprintf('%+03d', $hours) . ':' . sprintf('%02d', $minutes);
    case 'name':
      return ' ' . $date->local->timezone;
  }
}