aboutsummaryrefslogtreecommitdiff
path: root/module/datetime/instance.scm
blob: db24d8a2c15a3247192257e7e98c78a2c0cfc73f (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
(define-module (datetime instance)
  :use-module (util)
  :use-module (util config)
  :use-module (util exceptions)
  :use-module (datetime zic)
  :use-module (directories)
  :export (zoneinfo))

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

;; TODO see (vcomponent instance), this has a similar problem with early load
(define-once zoneinfo
  (let ((cache (make-hash-table)))
    (label self
           (case-lambda
             (()
              (define tz-list (get-config 'tz-list))
              (if (null? tz-list)
                (warning "Default zoneinfo only available when tz-dir and tz-list are configured")
                (self tz-list)))
             ((file-list)
              (provide 'zoneinfo)
              (let* ((directory (path-append data-directory "/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))))))))