From: Michael M Slusarz Date: Thu, 30 Sep 2010 19:13:38 +0000 (-0600) Subject: Improve formatting of date in print view. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=262779c877abad32b8aa22b194143e2700404f13;p=horde.git Improve formatting of date in print view. --- diff --git a/imp/lib/Ui/Mailbox.php b/imp/lib/Ui/Mailbox.php index 11af43da4..f2a7bfd2c 100644 --- a/imp/lib/Ui/Mailbox.php +++ b/imp/lib/Ui/Mailbox.php @@ -15,6 +15,9 @@ */ class IMP_Ui_Mailbox { + const DATE_FORCE = 1; + const DATE_FULL = 2; + /** * The current mailbox. * @@ -190,19 +193,27 @@ class IMP_Ui_Mailbox /** * Formats the date header. * - * @param integer $date The UNIX timestamp. + * @param integer $date The UNIX timestamp. + * @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) + public function getDate($date, $format = 0) { if (empty($date)) { return _("Unknown Date"); } - if (!isset($this->_cache['today_start'])) { - $this->_cache['today_start'] = strtotime('today'); - $this->_cache['today_end'] = strtotime('today + 1 day'); + 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'); } try { @@ -220,10 +231,16 @@ class IMP_Ui_Mailbox } $udate = $d->format('U'); - if (($udate < $this->_cache['today_start']) || - ($udate > $this->_cache['today_end'])) { + if (($format & self::DATE_FORCE) || + ($udate < $this->_cache['today_start']->format('U')) || + ($udate > $this->_cache['today_end']->format('U'))) { /* Not today, use the date. */ - return strftime($GLOBALS['prefs']->getValue('date_format'), $udate); + if ($format & self::DATE_FULL) { + return strftime($GLOBALS['prefs']->getValue('date_format'), $udate) . + ' [' . strftime($GLOBALS['prefs']->getValue('time_format'), $udate) . ']'; + } + + return strftime($GLOBALS['prefs']->getValue('date_format_mini'), $udate); } /* Else, it's today, use the time. */ diff --git a/imp/view.php b/imp/view.php index 998abc27d..b933bc54e 100644 --- a/imp/view.php +++ b/imp/view.php @@ -231,6 +231,12 @@ case 'print_attach': $headers = array(); foreach ($basic_headers as $key => $val) { if ($hdr_val = $headerob->getValue($key)) { + /* Format date string. */ + if ($key == 'date') { + $imp_ui_mbox = new IMP_Ui_Mailbox(); + $hdr_val = $imp_ui_mbox->getDate($hdr_val, IMP_Ui_Mailbox::DATE_FORCE | IMP_Ui_Mailbox::DATE_FULL); + } + $headers[] = array( 'header' => htmlspecialchars($val), 'value' => htmlspecialchars($hdr_val)