diff options
author | Logan Hunt <loganjh@amazon.com> | 2022-05-24 16:22:00 -0700 |
---|---|---|
committer | Logan Hunt <loganjh@amazon.com> | 2022-05-24 16:22:00 -0700 |
commit | 47b6bdf8b737bf12f5f7b8839ed2389ff28c723c (patch) | |
tree | b5be62069a96b7461b8ec4bae588d375591616e3 /time.lisp | |
parent | 3db9a2eb7a7d14ce935f5902b0c21ce4fd5eb729 (diff) | |
download | lispruns-47b6bdf8b737bf12f5f7b8839ed2389ff28c723c.tar.gz lispruns-47b6bdf8b737bf12f5f7b8839ed2389ff28c723c.zip |
Write code into systems and add formatting for highlight lists
Diffstat (limited to 'time.lisp')
-rw-r--r-- | time.lisp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/time.lisp b/time.lisp new file mode 100644 index 0000000..3d0f2bb --- /dev/null +++ b/time.lisp @@ -0,0 +1,18 @@ +;; Makes a-list with '((hours . HOURS) (minutes . MINUTES) (seconds . SECONDS) (ms . MILLISECONDS)) +(defun make-time-alist (ms) + `((hours . ,(floor (/ ms (* 1000 60 60)))) + (minutes . ,(floor (mod (/ ms (* 1000 60)) 60))) + (seconds . ,(floor (mod (/ ms 1000) 60))) + (ms . ,(mod ms 1000)))) + +;; Formats, disregarding min/hour if they shouldn't be shown, a time alist to "H:M:S.ms" +(defun format-time (time-alist) + (let + ((hours (cdr (assoc 'hours time-alist))) + (minutes (cdr (assoc 'minutes time-alist))) + (seconds (cdr (assoc 'seconds time-alist))) + (centis (round (/ (cdr (assoc 'ms time-alist)) 10)))) + (concatenate 'string + (unless (zerop hours) (format nil "~2,'0d:" hours)) + (unless (and (zerop minutes) (zerop hours)) (format nil "~2,'0d:" minutes)) + (format nil "~2,'0d.~2,'0d" seconds centis)))) |