summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYoni Rabkin <yoni@rabkins.net>2020-12-02 14:46:17 -0500
committerYoni Rabkin <yoni@rabkins.net>2020-12-02 14:46:17 -0500
commit95553c6eff2a710901d0684842ee16636f2ca578 (patch)
tree76f9c99d3a6c61a362be0ca10ba68b6624918948
parentb23df79bd7f5a6dac61704aceb8036d3ec314a5f (diff)
* rt-liberation.el: vernacular time delta
-rw-r--r--rt-liberation.el39
1 files changed, 35 insertions, 4 deletions
diff --git a/rt-liberation.el b/rt-liberation.el
index bc5e8c6..4520c8f 100644
--- a/rt-liberation.el
+++ b/rt-liberation.el
@@ -1213,6 +1213,36 @@ ASSOC-BROWSER if non-nil should be a ticket browser."
"Expressions to font-lock for RT ticket viewer.")
+(defun rt-liber-viewer2-vernacular-plural (time)
+ "Add an ess as needed."
+ (if (= time 1)
+ ""
+ "s"))
+
+(defun rt-liber-viewer2-vernacular-date (date)
+ "Return a vernacular time delta."
+ (let* ((now (format-time-string "%Y-%m-%dT%T%z" (current-time)))
+ (days-ago (days-between now date)))
+ (cond ((= 0 days-ago)
+ "today")
+ ((< 0 days-ago 7)
+ (format "%s day%s ago" days-ago
+ (rt-liber-viewer2-vernacular-plural days-ago)))
+ ((< 7 days-ago 30)
+ (let ((weeks (floor (/ days-ago 7.0))))
+ (format "%s week%s ago"
+ weeks
+ (rt-liber-viewer2-vernacular-plural weeks))))
+ ((< 30 days-ago 365)
+ (let ((months (floor (/ days-ago 30.0))))
+ (format "%s month%s ago"
+ months
+ (rt-liber-viewer2-vernacular-plural months))))
+ (t (let ((years (floor (/ days-ago 365.0))))
+ (format "%s year%s ago"
+ years
+ (rt-liber-viewer2-vernacular-plural years)))))))
+
(defun rt-liber-viewer2-mode-quit ()
"Bury the ticket viewer."
(interactive)
@@ -1343,15 +1373,16 @@ ASSOC-BROWSER if non-nil should be a ticket browser."
(field (alist-get 'Field section)))
(let ((start (point)))
(insert
- (format "Ticket %s by %s on %s (-N- days ago) (%s)%s\n"
+ (format "Ticket %s by %s, %s (%s) %s [%s]\n"
ticket-id
creator
- date
+ (rt-liber-viewer2-vernacular-date date)
type
(if (and (string= type "Set")
(string= field "Owner"))
- " (owner change)"
- "")))
+ "(owner change)"
+ "")
+ date))
(add-text-properties start
(point)
`(font-lock-face rt-liber-ticket-emph-face))