aboutsummaryrefslogtreecommitdiff
path: root/module/datetime/instance.scm
blob: d6c843489a6ab1c00463519c932f6d4d92b2f2b3 (plain)
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
(define-module (datetime instance)
  :use-module (hnh util)
  :use-module (calp util config)
  :use-module (hnh util exceptions)
  :use-module ((hnh util path) :select (path-append))
  :use-module (datetime zic)
  :use-module ((xdg basedir) :prefix xdg-)
  :use-module (calp translation)
  :export (zoneinfo))

(define-config tz-list '()
  description: (G_ "List of default zoneinfo files to be parsed"))

;; TODO see (vcomponent uil instance), this has a similar problem with early load
;; Takes a list of zoneinfo files relative
;; $XDG-DATA-HOME/calp/zoneinfo, which will probably be
;; '("tzdata/europe" "tzdata/afrifa" ...)
;; and builds all these into one giant zoneinfo database object
;; Note that scripts/tzget should be run beforehand, to download the
;; data
(define-once zoneinfo
  (let ((cache (make-hash-table)))
    (label self
           (case-lambda
             (()
              (define tz-list (tz-list))
              (if (null? tz-list)
                (warning (G_ "Default zoneinfo only available when tz-dir and tz-list are configured"))
                (self tz-list)))
             ((file-list)
              (provide 'zoneinfo)
              (let* ((directory (path-append (xdg-data-home) "/calp/zoneinfo"))
                     (key (cons directory file-list)))
                (aif (hash-ref cache key)
                     it
                     (let ((tz (read-zoneinfo
                                 (map (lambda (s) (path-append directory s))
                                      file-list))))
                       (hash-set! cache key tz)
                       tz))))))))