@param int $tzOffset optional the timezone $date is from
*/
function __construct($date = ‘now’, $tzOffset = 0)
{
if ($date == ‘now’ || empty($date))
{
$this->_date = strtotime(gmdate(“M d Y H:i:s”, time()));
return;
}
$tzOffset *= 3600;
if (is_numeric($date))
{
$this->_date = $date - $tzOffset;
return;
}
if (preg_match(’~(?:(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun),\s+)?(\d{1,2})\s+([a-zA-Z]{3})\s+(\d{4})\s+(\d{2}):(\d{2}):(\d{2})\s+(.*)~i’,$date,$matches))
{
$months = Array(
‘jan’ => 1, ‘feb’ => 2, ‘mar’ => 3, ‘apr’ => 4,
‘may’ => 5, ‘jun’ => 6, ‘jul’ => 7, ‘aug’ => 8,
‘sep’ => 9, ‘oct’ => 10, ‘nov’ => 11, ‘dec’ => 12
);
$matches[2] = strtolower($matches[2]);
if (! isset($months[$matches[2]])) {
return;
}
$this->_date = mktime(
$matches[4], $matches[5], $matches[6],
$months[$matches[2]], $matches[1], $matches[3]
);
if ($this->_date === false) {
return;
}
if ($matches[7][0] == '+') {
$tzOffset = 3600 * substr($matches[7], 1, 2)
+ 60 * substr($matches[7], -2);
} elseif ($matches[7][0] == '-') {
$tzOffset = -3600 * substr($matches[7], 1, 2)
- 60 * substr($matches[7], -2);
} else {
if (strlen($matches[7]) == 1) {
$oneHour = 3600;
$ord = ord($matches[7]);
if ($ord < ord('M')) {
$tzOffset = (ord('A') - $ord - 1) * $oneHour;
} elseif ($ord >= ord('M') && $matches[7] != 'Z') {
$tzOffset = ($ord - ord('M')) * $oneHour;
} elseif ($matches[7] == 'Z') {
$tzOffset = 0;
}
}
switch ($matches[7]) {
case 'UT':
case 'GMT': $tzOffset = 0;
}
}
$this->_date -= $tzOffset;
return;
}
if (preg_match(’~(\d{4})-(\d{2})-(\d{2})T\s:(\d{2}):(\d{2})(.*)~’, $date, $matches))
{
$this->_date = mktime(
$matches[4], $matches[5], $matches[6],
$matches[2], $matches[3], $matches[1]
);
if ($this->_date == false) {
return;
}
if (isset($matches[7][0])) {
if ($matches[7][0] == ‘+’ || $matches[7][0] == ‘-’) {
$tzOffset = 60 * (
substr($matches[7], 0, 3) * 60 + substr($matches[7], -2)
);
} elseif ($matches[7] == ‘Z’) {
$tzOffset = 0;
}
}
$this->_date -= $tzOffset;
return;
}
$this->_date = (strtotime($date) == -1) ? false : strtotime($date);
if ($this->_date) {
$this->_date -= $tzOffset;
}
}