(define (american-time h m s) (cond ((< h 0) (laml-error "Cannot handle this hour:" h)) ((and (= h 12) (= m 0) (= s 0)) "noon") ((< h 12) (string-append (format-hour-minutes-seconds h m s) " " "am")) ((= h 12) (string-append (format-hour-minutes-seconds h m s) " " "pm")) ((and (= h 24) (= m 0) (= s 0)) "midnight") ((<= h 24) (string-append (format-hour-minutes-seconds (- h 12) m s) " " "pm")) (else (laml-error "Cannot handle this hour:" h)))) (define (format-hour-minutes-seconds h m s) (string-append (zero-pad-string (number->string h)) ":" (zero-pad-string (number->string m)) ":" (zero-pad-string (number->string s)))) (define (zero-pad-string str) (if (= 1 (string-length str)) (string-append "0" str) str))