about summary refs log tree commit diff
path: root/fun/๐Ÿ•ฐ๏ธ/lib.lisp
diff options
context:
space:
mode:
authorsterni <sternenseemann@systemli.org>2021-05-29T14ยท02+0200
committersterni <sternenseemann@systemli.org>2021-05-29T19ยท13+0000
commit8418e01a840cd2d6f55291929b126b1e6b1f028f (patch)
tree7e4b759018c19df4766a1a2555b8e9bee94f3fef /fun/๐Ÿ•ฐ๏ธ/lib.lisp
parentf60d174591a2fdf3de8fe96b9f3bb890a000bfe8 (diff)
feat(fun/๐Ÿ•ฐ๏ธ): get the time as an emoji clock face r/2633
This small tool prints the current time rounded to half-hour precision
as an emoji clock face and exists. It can use both the local time zone
and UTC. Additionally it supports a pseudo dot time format.

Via fun.๐Ÿ•ฐ๏ธ.lib we reexpose the internal library which allows conversion
from LOCAL-TIME:TIMESTAMP to an emoji clock face โ€” maybe we'll want to
integrate this into //web/panettone?

//fun/๐Ÿ•ฐ๏ธ is the spritual (and actual) successor to
<https://github.com/sternenseemann/unicode_clock>.

It likely only works in SBCL due to its heavy usage of unicode symbol
names.

Change-Id: I44204107a14f99b04b0c5290d88e8659f013f423
Reviewed-on: https://cl.tvl.fyi/c/depot/+/3164
Tested-by: BuildkiteCI
Reviewed-by: tazjin <mail@tazj.in>
Diffstat (limited to 'fun/๐Ÿ•ฐ๏ธ/lib.lisp')
-rw-r--r--fun/๐Ÿ•ฐ๏ธ/lib.lisp32
1 files changed, 32 insertions, 0 deletions
diff --git a/fun/๐Ÿ•ฐ๏ธ/lib.lisp b/fun/๐Ÿ•ฐ๏ธ/lib.lisp
new file mode 100644
index 000000000000..d23db033743e
--- /dev/null
+++ b/fun/๐Ÿ•ฐ๏ธ/lib.lisp
@@ -0,0 +1,32 @@
+(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))))