Improve formatting of date in print view.
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 30 Sep 2010 19:13:38 +0000 (13:13 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 30 Sep 2010 19:47:59 +0000 (13:47 -0600)
imp/lib/Ui/Mailbox.php
imp/view.php

index 11af43d..f2a7bfd 100644 (file)
@@ -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:
+     * <pre>
+     * 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.
+     * </pre>
      *
      * @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. */
index 998abc2..b933bc5 100644 (file)
@@ -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)