summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Isaac2022-06-23 16:11:00 +0530
committerArun Isaac2022-06-23 16:11:00 +0530
commit4a57b89d5a2bff16f799e95f3cb29a3739596cc7 (patch)
treed0ad8ea6e5726872d419d6ddf162d423877e0d48
parent39a034de1de30ad0c3b735936637d2985cc24dc0 (diff)
downloadtissue-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.
-rwxr-xr-xbin/tissue29
1 files changed, 25 insertions, 4 deletions
diff --git a/bin/tissue b/bin/tissue
index 75f1b9e..e8043e4 100755
--- a/bin/tissue
+++ b/bin/tissue
@@ -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"