public function format($format = 0)
{
global $registry;
$udate = null;
if ($this->_date && !$this->_date->error()) {
try {
$udate = $this->_date->format('U');
if (empty(self::$_cache['tz'])) {
$registry->setTimeZone();
self::$_cache['tz'] = true;
}
} catch (Exception $e) {
}
}
switch ($format) {
case self::DATE_ISO_8601:
$d = clone $this->_date;
$d->setTimezone(new DateTimeZone(date_default_timezone_get()));
return $d->format('c');
case self::DATE_LOCAL:
if (is_null($udate)) {
return '';
}
$this->_buildCache();
$tz = strftime('%Z');
if ($udate < self::$_cache['today_start'] || $udate > self::$_cache['today_end']) {
if ($udate > self::$_cache['yesterday_start']) {
/* Yesterday. */
return sprintf(_("Yesterday, %s %s"), $this->_format('time_format', $udate), $tz);
}
/* Not today, use the date. */
return sprintf('%s (%s %s)', $this->_format('date_format', $udate), $this->_format('time_format', $udate), $tz);
}
/* Else, it's today, use the time only. */
return sprintf(_("Today, %s %s"), $this->_format('time_format', $udate), $tz);
}
if (is_null($udate)) {
return _("Unknown Date");
}
if ($format === self::DATE_FORCE) {
return $this->_format('date_format', $udate) . ' [' . $this->_format('time_format', $udate) . ' ' . strftime('%Z') . ']';
}
$this->_buildCache();
if ($udate < self::$_cache['today_start'] || $udate > self::$_cache['today_end']) {
if ($udate > self::$_cache['yesterday_start']) {
/* Yesterday. */
return sprintf(_("Yesterday, %s"), $this->_format('time_format_mini', $udate));
}
/* Not today, use the date. */
return $format === self::DATE_FULL ? $this->_format('date_format', $udate) . ' [' . $this->_format('time_format', $udate) . ']' : $this->_format('date_format_mini', $udate);
}
/* It's today, use the time. */
return $this->_format('time_format_mini', $udate);
}