diff options
author | Holger Dürer <me@hdurer.net> | 2017-05-19 22:10:38 +0100 |
---|---|---|
committer | Holger Dürer <me@hdurer.net> | 2017-06-19 17:16:29 +0100 |
commit | 20e3b77a9a37373754d0adedcee2ede6cf1f5922 (patch) | |
tree | dc182bd2a2084fedb67940aa1dec2e1d4631db75 /lisp/mastodon-tl.el | |
parent | d746a724db23fc3d897a6c6f11fca75b709b727c (diff) |
Show the posting date in a more readable, relative to current time format.
This is still static, i.e. doesn't update as time progresses.
Diffstat (limited to 'lisp/mastodon-tl.el')
-rw-r--r-- | lisp/mastodon-tl.el | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 66452dd..4556613 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -146,6 +146,38 @@ Return value from boosted content if available." (or (cdr (assoc field (cdr (assoc 'reblog toot)))) (cdr (assoc field toot)))) +(defun mastodon-tl--relative-time-description (time-stamp) + "Returns a string with a human readable description of TIME-STMAP relative to the current time. + +E.g. this could return something like \"1 min ago\", \"yesterday\", etc. +TIME-STAMP is assumed to be in the past." + (let* ((now (current-time)) + (time-difference (time-subtract now time-stamp)) + (seconds-difference (float-time time-difference))) + (cond + ((< seconds-difference 60) + "less than a minute ago") + ((<= seconds-difference (* 1.5 60)) + "one minute ago") + ((< seconds-difference (* 60 59.5)) + (format "%d minutes ago" (round (/ seconds-difference 60)))) + ((<= seconds-difference (* 1.5 60 60)) + "one hour ago") + ((< seconds-difference (* 60 60 23.5)) + (format "%d hours ago" (round (/ seconds-difference 60 60)))) + ((<= seconds-difference (* 1.5 60 60 24)) + "one day ago") + ((<= seconds-difference (* 60 60 24 6.5)) + (format "%d days ago" (round (/ seconds-difference 60 60 24)))) + ((<= seconds-difference (* 1.5 60 60 24 7)) + "one week ago") + ((<= seconds-difference (* 60 60 24 365)) + (format "%d weeks ago" (round (/ seconds-difference 60 60 24 7)))) + ((<= seconds-difference (* 1.5 60 60 24 365)) + "one year ago") + (t + (format "%d years ago" (round (/ seconds-difference 60 60 24 365.25))))))) + (defun mastodon-tl--byline (toot) "Generate byline for TOOT." (let ((id (cdr (assoc 'id toot))) @@ -163,7 +195,11 @@ Return value from boosted content if available." (mastodon-tl--byline-author toot) (mastodon-tl--byline-boosted toot) " " - (format-time-string mastodon-toot-timestamp-format (date-to-time timestamp)) + (let ((parsed-time (date-to-time timestamp))) + (propertize + (format-time-string mastodon-toot-timestamp-format parsed-time) + 'timestamp parsed-time + 'display (mastodon-tl--relative-time-description parsed-time))) (propertize "\n ------------" 'face 'default)) 'favourited-p faved 'boosted-p boosted |