저자: Michael Slusarz (slusarz@horde.org)
상속: extends DateTime
예제 #1
0
파일: Date.php 프로젝트: raz0rsdge/horde
 /**
  * Formats the date.
  *
  * @param integer $format  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.
  *
  * @return 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);
 }
예제 #2
0
파일: Ui.php 프로젝트: DSNS-LAB/Dmail
 /**
  * Formats the date header.
  *
  * @param mixed $date      The date object. Either a DateTime object or a
  *                         date string.
  * @param integer $format  Mask of formatting options:
  *   - IMP_Mailbox_Ui::DATE_FORCE - Force use of date formatting, instead
  *                                  of time formatting, for all dates.
  *   - IMP_Mailbox_Ui::DATE_FULL - Use full representation of date,
  *                                 including time information.
  *
  * @return string  The formatted date header.
  */
 public function getDate($date, $format = 0)
 {
     if (!is_object($date)) {
         if (is_null($date)) {
             return _("Unknown Date");
         }
         $date = new Horde_Imap_Client_DateTime($date);
     }
     if (!($format & self::DATE_FORCE) && !isset($this->_cache['today_start'])) {
         $this->_cache['today_start'] = new DateTime('today');
         $this->_cache['today_end'] = new DateTime('today + 1 day');
     }
     $udate = null;
     if (!$date->error()) {
         try {
             $udate = $date->format('U');
         } catch (Exception $e) {
         }
     }
     if (is_null($udate)) {
         return _("Unknown Date");
     }
     if ($format & self::DATE_FORCE || $udate < $this->_cache['today_start']->format('U') || $udate > $this->_cache['today_end']->format('U')) {
         /* Not today, use the date. */
         if ($format & self::DATE_FULL) {
             return strftime($GLOBALS['prefs']->getValue('date_format'), $udate) . ' [' . strftime($GLOBALS['prefs']->getValue('time_format') . ' %Z', $udate) . ']';
         }
         return strftime($GLOBALS['prefs']->getValue('date_format_mini'), $udate);
     }
     /* Else, it's today, use the time. */
     return strftime($GLOBALS['prefs']->getValue('time_format'), $udate);
 }