Skip to content

Commit

Permalink
Ensure that (hms) produces a sane output.
Browse files Browse the repository at this point in the history
This closes #47, by ensuring that single digit minutes, hours, or
seconds are two digits in length.
  • Loading branch information
skx committed Oct 17, 2022
1 parent 2a523b0 commit f78dc6d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions stdlib/stdlib.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,19 @@
(alias minute time:minute)
(alias second time:second)

(set! zero-pad-single-number (fn* (num)
"Prefix the given number with zero, if the number is less than ten"
(if (< num 10)
(sprintf "0%s" num)
num)))

(set! time:hms (fn* ()
"Return the current time, formatted as 'HH:MM:SS', as a string."
(sprintf "%s:%s:%s" (hour) (minute) (second))))
(set! hms time:hms)
(sprintf "%s:%s:%s"
(zero-pad-single-number (hour))
(zero-pad-single-number (minute))
(zero-pad-single-number (second)))))
(alias hms time:hms)


;;
Expand Down

0 comments on commit f78dc6d

Please sign in to comment.