IMP_Message_Date::format PHP Méthode

format() public méthode

Formats the date.
public format ( integer $format ) : string
$format integer Formatting options: - DATE_FORCE: Force use of date formatting, instead of time formatting, for all dates. - DATE_FULL: Use full representation of date, including time information. - DATE_ISO_8601: Return ISO 8601 formatted date. - DATE_LOCAL: Display localized formatting (with timezone information). Displays "Today" for the current date.
Résultat string The formatted date string.
    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);
    }

Usage Example

Exemple #1
0
 /**
  */
 protected function _getHeaderValue($ob, $header)
 {
     switch ($header) {
         case 'date':
             $date_ob = new IMP_Message_Date($ob['Date']);
             return $date_ob->format($date_ob::DATE_LOCAL);
         default:
             return parent::_getHeaderValue($ob, $header);
     }
 }
All Usage Examples Of IMP_Message_Date::format