depot/third_party/tvl/fun/🕰️/lib.lisp
Default email a291c8690a Project import generated by Copybara.
GitOrigin-RevId: e6e19f3d81a982a62e1bba08f0b4f7fdc21b4ea0
2022-05-19 16:39:52 +02:00

32 lines
1.2 KiB
Common Lisp
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

(defpackage 🕰
(:use :cl)
(:import-from :local-time
:timestamp-subtimezone :*default-timezone* :sec-of)
(:export :))
(in-package :🕰)
(declaim (optimize (safety 3)))
(defparameter *clock-emojis*
(vector #\🕛 #\🕧 ; 00:00 - 00:30
#\🕐 #\🕜 ; 01:00 - 01:30
#\🕑 #\🕝 ; 00:00 - 00:30
#\🕒 #\🕞 ; 00:00 - 00:30
#\🕓 #\🕟 ; 00:00 - 00:30
#\🕔 #\🕠 ; 00:00 - 00:30
#\🕕 #\🕡 ; 00:00 - 00:30
#\🕖 #\🕢 ; 00:00 - 00:30
#\🕗 #\🕣 ; 00:00 - 00:30
#\🕘 #\🕤 ; 00:00 - 00:30
#\🕙 #\🕥 ; 00:00 - 00:30
#\🕚 #\🕦)) ; 11:00 - 11:30
(defun (timestamp &optional (tz *default-timezone*))
"Convert a LOCAL-TIME:TIMESTAMP into the nearest Unicode clock face.
Use TZ (which defaults to LOCAL-TIME:*DEFAULT-TIMEZONE*) to determine
the UTC offset to factor when determining the local clock face."
(let* ((offset (multiple-value-bind (offset-secs _dst _name)
(timestamp-subtimezone timestamp tz)
offset-secs))
(secs (+ (sec-of timestamp) offset)))
(elt *clock-emojis* (mod (round (/ secs 1800)) 24))))