How about this change to human date format?

126 views
Skip to first unread message

Marcin Borkowski

unread,
Mar 11, 2015, 6:25:29 AM3/11/15
to Mu Discuss
Hi all,

the following might make displaying the header view slower, so it might
not be for everybody. However, I personally find this potentially
useful (I'll be testing it over the course of the following days). It
changes the "human" date/time format to display the /yesterday's/ times
as "Y-18:59:00", for instance, and only earlier dates as pure dates.

Optimizations welcome, since this is going to be run multiple times
during the headers display, of course.

--8<---------------cut here---------------start------------->8---
(defsubst mu4e~headers-human-date (msg)
"Show a 'human' date.
If the date is today or yesterday, show the time, otherwise, show
the date. The formats used for date and time are
`mu4e-headers-date-format' and `mu4e-headers-time-format'."
(let ((date (mu4e-msg-field msg :date)))
(if (equal date '(0 0 0))
"None"
(let ((day1 (decode-time date))
(day2 (decode-time (current-time))))
(cond ((and
(eq (nth 3 day1) (nth 3 day2)) ;; day
(eq (nth 4 day1) (nth 4 day2)) ;; month
(eq (nth 5 day1) (nth 5 day2))) ;; year
(format-time-string mu4e-headers-time-format date))
((eq (- (time-to-days current-time) (time-to-days date)) 1)
(format-time-string mu4e-headers-yesterday-time-format date))
(t
(format-time-string mu4e-headers-date-format date)))))))

(defcustom mu4e-headers-yesterday-time-format "Y-%X"
"Time format to use in the headers view for yesterday's
messages. In the format of `format-time-string'."
:type 'string
:group 'mu4e-headers)
--8<---------------cut here---------------end--------------->8---

Best,

--
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University

Dirk-Jan C. Binnema

unread,
Mar 13, 2015, 1:48:10 AM3/13/15
to mu-di...@googlegroups.com
Note that you don't need to override the built-in fields, you can use
the Custom-headers feature.
http://www.djcbsoftware.nl/code/mu/mu4e/HV-Custom-headers.html#HV-Custom-headers

Cheers,
Dirk.

--
Dirk-Jan C. Binnema Helsinki, Finland
e:dj...@djcbsoftware.nl w:www.djcbsoftware.nl
pgp: D09C E664 897D 7D39 5047 A178 E96A C7A1 017D DA3C

Marcin Borkowski

unread,
Mar 13, 2015, 4:17:17 PM3/13/15
to mu-di...@googlegroups.com

On 2015-03-13, at 06:48, Dirk-Jan C. Binnema <dj...@djcbsoftware.nl> wrote:

> Note that you don't need to override the built-in fields, you can use
> the Custom-headers feature.
> http://www.djcbsoftware.nl/code/mu/mu4e/HV-Custom-headers.html#HV-Custom-headers

Nice idea. However, stupid me cannot do that. This is what I tried:

--8<---------------cut here---------------start------------->8---
(defun mu4e~headers-more-human-date (msg)
"Show a 'more human' date. If the date is today or yesterday,
show the time, otherwise, show the date. The formats used for
date and time are `mu4e-headers-date-format' and
`mu4e-headers-time-format'."
(let ((date (mu4e-msg-field msg :date)))
(if (equal date '(0 0 0))
"None"
(let ((day1 (decode-time date))
(day2 (decode-time (current-time))))
(cond ((and
(eq (nth 3 day1) (nth 3 day2)) ;; day
(eq (nth 4 day1) (nth 4 day2)) ;; month
(eq (nth 5 day1) (nth 5 day2))) ;; year
(format-time-string mu4e-headers-time-format date))
((eq (- (time-to-days current-time) (time-to-days date)) 1)
(format-time-string mu4e-headers-yesterday-time-format date))
(t
(format-time-string mu4e-headers-date-format date)))))))

(defcustom mu4e-headers-yesterday-time-format "Y-%X"
"Time format to use in the headers view for yesterday's
messages. In the format of `format-time-string'."
:type 'string
:group 'mu4e-headers)

(setq mu4e-headers-date-format "%F")

(add-to-list 'mu4e-header-info-custom
'(:more-human-date .
(:name "Date"
:shortname "Date"
:help "Date in human-friendly format"
:function #'mu4e~headers-more-human-date)))

(setq mu4e-headers-fields '((:more-human-date . 12)
(:flags . 6)
(:mailing-list . 10)
(:from . 22)
(:subject)))
--8<---------------cut here---------------end--------------->8---

This resulted in:

,----
| error in process filter: Invalid function: (function mu4e~headers-more-human-date)
`----

What am I doing wrong?

> Cheers,
> Dirk.

Dirk-Jan C. Binnema

unread,
Mar 14, 2015, 5:01:17 AM3/14/15
to mu-di...@googlegroups.com

On Friday Mar 13 2015, Marcin Borkowski wrote:

> On 2015-03-13, at 06:48, Dirk-Jan C. Binnema <dj...@djcbsoftware.nl> wrote:
>
>> Note that you don't need to override the built-in fields, you can use
>> the Custom-headers feature.
>> http://www.djcbsoftware.nl/code/mu/mu4e/HV-Custom-headers.html#HV-Custom-headers
>
> Nice idea. However, stupid me cannot do that. This is what I tried:
>
> --8<---------------cut here---------------start------------->8---
> (defun mu4e~headers-more-human-date (msg)

[...]

> ((eq (- (time-to-days current-time) (time-to-days date)) 1)

(curent-time)

[...]

> (add-to-list 'mu4e-header-info-custom
> '(:more-human-date .
> (:name "Date"
> :shortname "Date"
> :help "Date in human-friendly format"
> :function #'mu4e~headers-more-human-date)))

:function mu4e~headers-more-human-date

Marcin Borkowski

unread,
Mar 14, 2015, 10:50:35 AM3/14/15
to mu-di...@googlegroups.com

On 2015-03-14, at 10:01, Dirk-Jan C. Binnema <dj...@djcbsoftware.nl> wrote:

>> ((eq (- (time-to-days current-time) (time-to-days date)) 1)
>
> (current-time)

Yeah. I'm wondering how that worked before. ;-)

>> :function #'mu4e~headers-more-human-date)))
>
> :function mu4e~headers-more-human-date

Thanks! You may now read about this here:
http://mbork.pl/2015-03-14_mu4e_and_human-friendly_date_format
Reply all
Reply to author
Forward
0 new messages