diff options
author | Arun Isaac | 2022-06-27 00:03:41 +0530 |
---|---|---|
committer | Arun Isaac | 2022-06-27 00:19:51 +0530 |
commit | 1a0e0e89a8cefb0016767cf8fb940f64274a40ea (patch) | |
tree | 5ae0a0926914376613f18c47a528aa2f684fc272 /tissue/utils.scm | |
parent | 76991c195740d2edee0a1887b4850e438d8e83d2 (diff) | |
download | tissue-1a0e0e89a8cefb0016767cf8fb940f64274a40ea.tar.gz tissue-1a0e0e89a8cefb0016767cf8fb940f64274a40ea.tar.lz tissue-1a0e0e89a8cefb0016767cf8fb940f64274a40ea.zip |
issue: Move issue printing functions to (tissue issue).
* bin/tissue: Do not import (srfi srfi-19).
(print-issue, print-issue-to-gemtext): Move to tissue/issue.scm.
(human-date-string): Move to tissue/utils.scm.
* tissue/issue.scm: Import (term ansi-color).
* tissue/utils.scm: Import (srfi srfi-19).
Diffstat (limited to 'tissue/utils.scm')
-rw-r--r-- | tissue/utils.scm | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tissue/utils.scm b/tissue/utils.scm index c3b3e3a..aed729b 100644 --- a/tissue/utils.scm +++ b/tissue/utils.scm @@ -18,9 +18,11 @@ (define-module (tissue utils) #:use-module (rnrs io ports) + #:use-module (srfi srfi-19) #:use-module (srfi srfi-26) #:use-module (ice-9 popen) #:export (string-remove-prefix + human-date-string call-with-current-directory get-line-dos-or-unix memoize-thunk)) @@ -29,6 +31,26 @@ "Remove PREFIX from STR." (substring str (string-length prefix))) +(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 (call-with-current-directory curdir thunk) "Call THUNK with current directory set to CURDIR. Restore current directory after THUNK returns." |