From 8418e01a840cd2d6f55291929b126b1e6b1f028f Mon Sep 17 00:00:00 2001 From: sterni Date: Sat, 29 May 2021 16:02:00 +0200 Subject: feat(fun/🕰️): get the time as an emoji clock face MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 . 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 --- "fun/\360\237\225\260\357\270\217/lib.lisp" | 32 +++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 "fun/\360\237\225\260\357\270\217/lib.lisp" (limited to 'fun/🕰️/lib.lisp') diff --git "a/fun/\360\237\225\260\357\270\217/lib.lisp" "b/fun/\360\237\225\260\357\270\217/lib.lisp" new file mode 100644 index 000000000000..d23db033743e --- /dev/null +++ "b/fun/\360\237\225\260\357\270\217/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)))) -- cgit 1.4.1