about summary refs log tree commit diff
path: root/fun/๐Ÿ•ฐ๏ธ/lib.lisp
blob: d23db033743e675f88825a1fc0b6487b65162d96 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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))))