/** * Is this time zone equivalent to another * * Tests to see if this time zone is equivalent to a given time zone object. * Equivalence in this context consists in the two time zones having: * * an equal offset from UTC in both standard and Summer time (if * the time zones observe Summer time) * the same Summer time start and end rules, that is, the two time zones * must switch from standard time to Summer time, and vice versa, on the * same day and at the same time * * @param object $pm_tz the Date_TimeZone object to test, or a valid time * zone ID * * @return bool true if this time zone is equivalent to the supplied * time zone * @access public */ function isEquivalent($pm_tz) { if (is_a($pm_tz, "Date_TimeZone")) { if ($pm_tz->getID() == $this->id) { return true; } } else { if (!Date_TimeZone::isValidID($pm_tz)) { return PEAR::raiseError("Invalid time zone ID '{$pm_tz}'", DATE_ERROR_INVALIDTIMEZONE); } if ($pm_tz == $this->id) { return true; } $pm_tz = new Date_TimeZone($pm_tz); } if ($this->getRawOffset() == $pm_tz->getRawOffset() && $this->hasDaylightTime() == $pm_tz->hasDaylightTime() && $this->getDSTSavings() == $pm_tz->getDSTSavings() && $this->getSummerTimeStartMonth() == $pm_tz->getSummerTimeStartMonth() && $this->getSummerTimeStartDay() == $pm_tz->getSummerTimeStartDay() && $this->getSummerTimeStartTime() == $pm_tz->getSummerTimeStartTime() && $this->getSummerTimeEndMonth() == $pm_tz->getSummerTimeEndMonth() && $this->getSummerTimeEndDay() == $pm_tz->getSummerTimeEndDay() && $this->getSummerTimeEndTime() == $pm_tz->getSummerTimeEndTime()) { return true; } else { return false; } }
function calc_timezone($newdate) { global $pref; if (!$pref['datetime'] || !$this->TimeZone) { $newdate = preg_replace('/UT$/', 'UTC', $newdate); $newdate = date("D, j M Y G:i O", strtotime($newdate)); return $newdate; } require_once 'Date.php'; // convert to ISO 8601 format if (preg_match('/(\\d+) ([a-z]+) (\\d\\d\\d?\\d?) (\\d\\d:\\d\\d:\\d\\d) ((\\+|-)\\d\\d\\d\\d|[a-z]+)/i', $newdate, $m)) { if (strlen($m[1]) == 1) { $m[1] = "0{$m['1']}"; } // If a 2 digit date is given then we need to make an assumption // about the actual year. If year >= 80 we can safely assume that // it's a 20th Century date e.g. 89 becomes 1989. Otherwise lets make it // a 21st Century date, e.g. 08 becomes 2008 if (strlen($m[3]) == 2) { $m[3] = $m[3] >= 80 ? "19{$m['3']}" : "20{$m['3']}"; } // format month name with uppercase firt char e.g Sep $m[2] = ucfirst(strtolower($m[2])); // Convert Timezone ID to GMT offset if (!is_numeric($m[5])) { // convert UT > UTC if ($m[5] == 'UT') { $m[5] = 'UTC'; } $dt = new Date_TimeZone($m[5]); $m[5] = $dt->getRawOffset(); if ($m[5] == 0) { $m[5] = 'Z'; } else { $m[5] = $m[5] / 36000; settype($m[5], 'string'); $m[5] = preg_replace('/(-|\\+)/', '${1}0', $m[5]); } } $newdate = "{$m['3']}{$this->months[$m[2]]}{$m['1']}T{$m['4']}{$m['5']}"; // Do timezone conversion $date = new Date($newdate); $date->convertTZbyID($this->TimeZone); $newdate = $date->getDate(); $newdate = date("D, j M Y G:i O", strtotime($newdate)); } elseif (preg_match('/(\\d+) ([a-z]+) (\\d\\d\\d\\d) (\\d\\d:\\d\\d:\\d\\d) (\\w+)/i', $newdate, $m)) { if (strlen($m[1]) == 1) { $m[1] = "0{$m['1']}"; } // If a 2 digit date is given then we need to make an assumption // about the actual year. If year >= 80 we can safely assume that // it's a 20th Century date e.g. 89 becomes 1989. Otherwise lets make it // a 21st Century date, e.g. 08 becomes 2008 if (strlen($m[3]) == 2) { $m[3] = $m[3] >= 80 ? "19{$m['3']}" : "20{$m['3']}"; } // format month name with uppercase firt char e.g Sep $m[2] = ucfirst(strtolower($m[2])); $newdate = "{$m['3']}{$this->months[$m[2]]}{$m['1']}"; // Convert date from timezone ID, rather than +0900 or -1100 format, format in GMT, MST, etc $date = new Date($newdate); $date->setTZByID($m[5]); $newdate = $date->getDate(); $newdate = date("D, j M Y G:i O", strtotime($newdate)); } else { $newdate = date("D, j M Y G:i O", strtotime($newdate)); } return $newdate; }