diff options
author | Arun Isaac | 2022-06-23 16:11:00 +0530 |
---|---|---|
committer | Arun Isaac | 2022-06-23 16:11:00 +0530 |
commit | 4a57b89d5a2bff16f799e95f3cb29a3739596cc7 (patch) | |
tree | d0ad8ea6e5726872d419d6ddf162d423877e0d48 /bin | |
parent | 39a034de1de30ad0c3b735936637d2985cc24dc0 (diff) | |
download | tissue-4a57b89d5a2bff16f799e95f3cb29a3739596cc7.tar.gz tissue-4a57b89d5a2bff16f799e95f3cb29a3739596cc7.tar.lz tissue-4a57b89d5a2bff16f799e95f3cb29a3739596cc7.zip |
bin: Wean off git's relative dates.
* bin/tissue: Import (srfi srfi-19).
(human-date-string): New function.
(print-issue, print-issue-to-gemtext): Use human-date-string instead
of relative dates captured from git.
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/tissue | 29 |
1 files changed, 25 insertions, 4 deletions
@@ -23,6 +23,7 @@ exec guile --no-auto-compile -s "$0" "$@" (import (rnrs exceptions) (rnrs io ports) (srfi srfi-1) + (srfi srfi-19) (srfi srfi-26) (srfi srfi-37) (srfi srfi-171) @@ -72,6 +73,26 @@ terminal." (define magenta-background (cut color 45 <>)) (define cyan-background (cut color 46 <>)) +(define (human-date-string date) + "Return a human readable rendering of DATE." + (let ((elapsed-time + (time-second + (time-difference (date->time-monotonic (current-date)) + (date->time-monotonic date))))) + (cond + ((< elapsed-time (* 2 60)) + (format #f "~a seconds ago" elapsed-time)) + ((< elapsed-time (* 2 60 60)) + (format #f "~a minutes ago" (round (/ elapsed-time 60)))) + ((< elapsed-time (* 2 24 60 60)) + (format #f "~a hours ago" (round (/ elapsed-time 60 60)))) + ((< elapsed-time (* 2 7 24 60 60)) + (format #f "~a days ago" (round (/ elapsed-time 60 60 24)))) + ((< elapsed-time (* 2 30 24 60 60)) + (format #f "~a weeks ago" (round (/ elapsed-time 60 60 24 7)))) + (else + (format #f "on ~a" (date->string date "~b ~d ~Y")))))) + (define (invalid-option opt name arg loads) (error "Invalid option" name)) @@ -117,13 +138,13 @@ to run tissue." (display (string-append (cyan (string-append "#" (number->string issue-number))) " opened " - (cyan (issue-created-relative-date issue)) + (cyan (human-date-string (issue-created-date issue))) " by " (cyan (issue-creator issue)))) (when (> number-of-posts 1) (display (string-append (cyan ",") " last updated " - (cyan (issue-last-updated-relative-date issue)) + (cyan (human-date-string (issue-last-updated-date issue))) " by " (cyan (issue-last-updater issue))))) (unless (zero? (issue-tasks issue)) @@ -151,11 +172,11 @@ to run tissue." (newline) (format #t "~a opened ~a by ~a" issue-number - (issue-created-relative-date issue) + (human-date-string (issue-created-date issue)) (issue-creator issue)) (when (> number-of-posts 1) (format #t ", last updated ~a by ~a" - (issue-last-updated-relative-date issue) + (human-date-string (issue-last-updated-date issue)) (issue-last-updater issue))) (unless (zero? (issue-tasks issue)) (format #t "; ~a/~a tasks done" |