;; Multilingualizaton of this module is tricky, as the rules of ;; forming plurals are different from language to language. ;; See GNU's gettext document for the problem. ;; For now, I only support English.
(define-constant secs-in-a-year 31557600) (define-constant secs-in-a-month 2629800) (define-constant secs-in-a-day 86400) (define-constant secs-in-an-hour 3600) (define-constant secs-in-a-minute 60)
(define (how-long-since time . opts) (define (pl num unit) (format "~a ~a~a" num unit (if (= num 1) "" "s")))
(let-optionals* opts ((now (sys-time))) (let ((diff (- now time))) (cond ((>= diff secs-in-a-year) (pl (quotient diff secs-in-a-year) "year")) ((>= diff secs-in-a-month) (pl (quotient diff secs-in-a-month) "month")) ((>= diff secs-in-a-day) (pl (quotient diff secs-in-a-day) "day")) ((>= diff secs-in-an-hour) (pl (quotient diff secs-in-an-hour) "hour")) ((>= diff secs-in-a-minute) (pl (quotient diff secs-in-a-minute) "minute")) (else (pl diff "second"))) )))