-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzoneinfo.lisp
75 lines (64 loc) · 2.08 KB
/
zoneinfo.lisp
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
;;;; zoneinfo.lisp
(defpackage #:zoneinfo
(:use #:cl)
(:export *tz-release*
*info*
get-info
;; Symbols for types of time of day
universal-time
local-time
standard-time
daylight-saving-time
;; Symbols for weekdays
monday
tuesday
wednesday
thursday
friday
saturday
sunday
;; Misc symbols for zones & rules
zone
rule
only
min
max
last
>=
<=))
(in-package #:zoneinfo)
(eval-when (:compile-toplevel :load-toplevel :execute)
(let* ((system (asdf:find-system 'zoneinfo t))
(release-path (asdf:system-relative-pathname system "TZ_RELEASE")))
(defparameter *zoneinfo-dist-dir*
(asdf:system-relative-pathname system "zoneinfo-dist/"))
(defparameter *tz-release*
(string-trim '(#\linefeed #\return #\space)
(uiop:read-file-string release-path)))))
(defmacro read-resource (name)
(with-open-file (stream (uiop:subpathname *zoneinfo-dist-dir* name))
(let ((*read-eval* nil))
`(quote ,(read stream)))))
(defmacro def-info ()
`(defparameter *info*
(list
,@(loop :for name :in (list "africa"
"antarctica"
"asia"
"australasia"
"backward"
"backzone"
"etcetera"
"europe"
"factory"
"northamerica"
"southamerica")
:for sym := (intern (string-upcase name) :keyword)
:collect `(cons (quote ,sym)
(read-resource ,(format nil "~a.lisp" name)))))))
(def-info)
(defun get-info (source)
(let ((result (cdr (assoc source *info*))))
(if result
result
(error "Unknown source ~a" source))))