aboutsummaryrefslogtreecommitdiff
path: root/gnu/installer/timezone.scm
blob: c336b5f3ba41218ab686f8f2a87b7766c13c11bd (about) (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
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2018 Mathieu Othacehe <m.othacehe@gmail.com>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (gnu installer timezone)
  #:use-module (gnu installer utils)
  #:use-module (guix i18n)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-26)
  #:use-module (srfi srfi-34)
  #:use-module (srfi srfi-35)
  #:use-module (ice-9 match)
  #:use-module (ice-9 receive)
  #:export (locate-children
            timezone->posix-tz
            timezone-has-child?
            zonetab->timezone-tree
            posix-tz->configuration))

(define %not-blank
  (char-set-complement char-set:blank))

(define (posix-tz->timezone tz)
  "Convert given TZ in Posix format like \"Europe/Paris\" into a list like
(\"Europe\" \"Paris\")."
  (string-split tz #\/))

(define (timezone->posix-tz timezone)
  "Convert given TIMEZONE like (\"Europe\" \"Paris\") into a Posix timezone
like \"Europe/Paris\"."
  (string-join timezone "/"))

(define (zonetab->timezones zonetab)
  "Parse ZONETAB file and return the corresponding list of timezones."

  (define (zonetab-line->posix-tz line)
    (let ((tokens (string-tokenize line %not-blank)))
      (match tokens
        ((code coordinates tz _ ...)
         tz))))

  (call-with-input-file zonetab
    (lambda (port)
      (let* ((lines (read-lines port))
             ;; Filter comment lines starting with '#' character.
             (tz-lines (filter (lambda (line)
                                 (not (eq? (string-ref line 0)
                                           #\#)))
                               lines)))
        (map (lambda (line)
               (posix-tz->timezone
                (zonetab-line->posix-tz line)))
             tz-lines)))))

(define (timezones->timezone-tree timezones)
  "Convert the list of timezones, TIMEZONES into a tree under the form:

	(\"America\" (\"North_Dakota\" \"New_Salem\" \"Center\"))

representing America/North_Dakota/New_Salem and America/North_Dakota/Center
timezones."

  (define (remove-first lists)
    "Remove the first element of every sublists in the argument LISTS."
    (map (lambda (list)
           (if (null? list) list (cdr list)))
         lists))

  (let loop ((cur-timezones timezones))
    (match cur-timezones
      (() '())
      (((region . rest-region) . rest-timezones)
       (if (null? rest-region)
           (cons (list region) (loop rest-timezones))
           (receive (same-region other-region)
               (partition (lambda (timezone)
                            (string=? (car timezone) region))
                          cur-timezones)
             (acons region
                    (loop (remove-first same-region))
                    (loop other-region))))))))

(define (locate-children tree path)
  "Return the children of the timezone indicated by PATH in the given
TREE. Raise a condition if the PATH could not be found."
  (let ((extract-proc (cut map car <>)))
    (match path
      (() (sort (extract-proc tree) string<?))
      ((region . rest)
       (or (and=> (assoc-ref tree region)
                  (cut locate-children <> rest))
           (raise
            (condition
             (&message
              (message
               (format #f (G_ "Unable to locate path: ~a.") path))))))))))

(define (timezone-has-child? tree timezone)
  "Return #t if the given TIMEZONE any child in TREE and #f otherwise."
  (not (null? (locate-children tree timezone))))

(define* (zonetab->timezone-tree zonetab)
  "Return the timezone tree corresponding to the given ZONETAB file."
  (timezones->timezone-tree (zonetab->timezones zonetab)))


;;;
;;; Configuration formatter.
;;;

(define (posix-tz->configuration timezone)
  "Return the configuration field for TIMEZONE."
  `((timezone ,timezone)))
8a11290a41de2'>about -rw-r--r--assembly.scm5073logplainabout -rw-r--r--astronomy.scm6682logplainabout -rw-r--r--attr.scm3169logplainabout -rw-r--r--audio.scm133831logplainabout -rw-r--r--augeas.scm2588logplainabout -rw-r--r--authentication.scm3466logplainabout -rw-r--r--autogen.scm2762logplainabout -rw-r--r--autotools.scm18617logplainabout d---------aux-files116logplain -rw-r--r--avahi.scm4243logplainabout -rw-r--r--avr.scm7071logplainabout -rw-r--r--axoloti.scm16276logplainabout -rw-r--r--backup.scm41906logplainabout -rw-r--r--base.scm58762logplainabout -rw-r--r--bash.scm15925logplainabout -rw-r--r--batik.scm8837logplainabout -rw-r--r--bdw-gc.scm4741logplainabout -rw-r--r--benchmark.scm7380logplainabout -rw-r--r--bioconductor.scm39697logplainabout -rw-r--r--bioinformatics.scm579227logplainabout -rw-r--r--bison.scm2137logplainabout -rw-r--r--bittorrent.scm18206logplainabout -rw-r--r--boost.scm8643logplainabout -rw-r--r--bootloaders.scm33979logplainabout -rw-r--r--bootstrap.scm25179logplainabout d---------bootstrap195logplain -rw-r--r--build-tools.scm11684logplainabout -rw-r--r--busybox.scm4417logplainabout -rw-r--r--c.scm9400logplainabout -rw-r--r--calcurse.scm2978logplainabout -rw-r--r--calendar.scm8406logplainabout -rw-r--r--ccache.scm2448logplainabout -rw-r--r--cdrom.scm33359logplainabout -rw-r--r--certs.scm8919logplainabout -rw-r--r--check.scm79990logplainabout -rw-r--r--chemistry.scm13749logplainabout -rw-r--r--chez.scm26254logplainabout -rw-r--r--ci.scm13473logplainabout -rw-r--r--cinnamon.scm3246logplainabout -rw-r--r--cluster.scm3502logplainabout -rw-r--r--cmake.scm7868logplainabout -rw-r--r--cobol.scm3003logplainabout -rw-r--r--code.scm29262logplainabout -rw-r--r--commencement.scm46490logplainabout -rw-r--r--compression.scm98512logplainabout -rw-r--r--compton.scm4097logplainabout -rw-r--r--conkeror.scm3730logplainabout -rw-r--r--conky.scm3210logplainabout -rw-r--r--connman.scm6893logplainabout -rw-r--r--cook.scm3594logplainabout -rw-r--r--cpio.scm2038logplainabout -rw-r--r--cpp.scm10805logplainabout -rw-r--r--cppi.scm1775logplainabout -rw-r--r--cran.scm273620logplainabout -rw-r--r--cross-base.scm21515logplainabout -rw-r--r--crypto.scm37097logplainabout -rw-r--r--cryptsetup.scm5257logplainabout -rw-r--r--cups.scm30748logplainabout -rw-r--r--curl.scm10871logplainabout -rw-r--r--cyrus-sasl.scm3023logplainabout -rw-r--r--databases.scm122182logplainabout -rw-r--r--datamash.scm2011logplainabout -rw-r--r--datastructures.scm8520logplainabout -rw-r--r--dav.scm4598logplainabout -rw-r--r--dc.scm2236logplainabout -rw-r--r--debian.scm7685logplainabout -rw-r--r--debug.scm15979logplainabout -rw-r--r--dejagnu.scm3510logplainabout -rw-r--r--dico.scm3527logplainabout -rw-r--r--dictionaries.scm11987logplainabout -rw-r--r--digest.scm2346logplainabout -rw-r--r--direct-connect.scm2606logplainabout -rw-r--r--disk.scm29376logplainabout -rw-r--r--display-managers.scm14888logplainabout -rw-r--r--django.scm31764logplainabout -rw-r--r--djvu.scm2064logplainabout -rw-r--r--dlang.scm15099logplainabout -rw-r--r--dns.scm29623logplainabout -rw-r--r--docbook.scm11877logplainabout -rw-r--r--docker.scm5368logplainabout -rw-r--r--documentation.scm9893logplainabout -rw-r--r--dunst.scm3159logplainabout -rw-r--r--dvtm.scm2311logplainabout -rw-r--r--ebook.scm11872logplainabout -rw-r--r--ed.scm2374logplainabout -rw-r--r--education.scm12661logplainabout -rw-r--r--electronics.scm10325logplainabout -rw-r--r--elf.scm9800logplainabout -rw-r--r--elixir.scm4143logplainabout -rw-r--r--emacs.scm496867logplainabout -rw-r--r--embedded.scm49235logplainabout -rw-r--r--emulators.scm54912logplainabout -rw-r--r--enchant.scm3655logplainabout -rw-r--r--engineering.scm77331logplainabout -rw-r--r--enlightenment.scm19545logplainabout -rw-r--r--entr.scm2854logplainabout -rw-r--r--erlang.scm9477logplainabout -rw-r--r--fabric-management.scm7029logplainabout -rw-r--r--fcitx.scm5006logplainabout -rw-r--r--figlet.scm1797logplainabout -rw-r--r--file-systems.scm9689logplainabout -rw-r--r--file.scm2115logplainabout -rw-r--r--finance.scm36403logplainabout -rw-r--r--firmware.scm21651logplainabout -rw-r--r--flashing-tools.scm18628logplainabout -rw-r--r--flex.scm3606logplainabout -rw-r--r--fltk.scm5769logplainabout -rw-r--r--fonts.scm57467logplainabout -rw-r--r--fontutils.scm30089logplainabout -rw-r--r--forth.scm2434logplainabout -rw-r--r--fpga.scm13912logplainabout -rw-r--r--freedesktop.scm51288logplainabout -rw-r--r--freeipmi.scm2013logplainabout -rw-r--r--fribidi.scm1891logplainabout -rw-r--r--ftp.scm10938logplainabout -rw-r--r--fvwm.scm3296logplainabout -rw-r--r--game-development.scm51326logplainabout -rw-r--r--games.scm242682logplainabout -rw-r--r--gawk.scm3785logplainabout -rw-r--r--gcal.scm2889logplainabout -rw-r--r--gcc.scm44631logplainabout -rw-r--r--gd.scm6421logplainabout -rw-r--r--gdb.scm4600logplainabout -rw-r--r--geo.scm38302logplainabout -rw-r--r--gettext.scm8824logplainabout -rw-r--r--ghostscript.scm15409logplainabout -rw-r--r--gimp.scm15309logplainabout -rw-r--r--gkrellm.scm2451logplainabout -rw-r--r--gl.scm31007logplainabout -rw-r--r--glib.scm35499logplainabout -rw-r--r--gnome.scm288476logplainabout -rw-r--r--gnu-doc.scm4109logplainabout -rw-r--r--gnu-pw-mgr.scm2378logplainabout -rw-r--r--gnucash.scm12513logplainabout -rw-r--r--gnunet.scm14716logplainabout -rw-r--r--gnupg.scm41174logplainabout -rw-r--r--gnustep.scm11910logplainabout -rw-r--r--gnuzilla.scm38209logplainabout -rw-r--r--gobby.scm7921logplainabout -rw-r--r--golang.scm142301logplainabout -rw-r--r--gperf.scm2354logplainabout -rw-r--r--gprolog.scm2742logplainabout -rw-r--r--gps.scm8997logplainabout -rw-r--r--graph.scm8531logplainabout -rw-r--r--graphics.scm33871logplainabout -rw-r--r--graphviz.scm10571logplainabout -rw-r--r--groff.scm6571logplainabout -rw-r--r--groovy.scm47175logplainabout -rw-r--r--gsasl.scm4640logplainabout -rw-r--r--gstreamer.scm18319logplainabout -rw-r--r--gtk.scm68457logplainabout -rw-r--r--guile-wm.scm6932logplainabout -rw-r--r--guile.scm95596logplainabout -rw-r--r--gv.scm3247logplainabout -rw-r--r--gxmessage.scm2352logplainabout -rw-r--r--ham-radio.scm2063logplainabout -rw-r--r--hardware.scm11656logplainabout -rw-r--r--haskell-check.scm30571logplainabout -rw-r--r--haskell-crypto.scm28868logplainabout -rw-r--r--haskell-web.scm46883logplainabout -rw-r--r--haskell.scm429103logplainabout -rw-r--r--hexedit.scm3222logplainabout -rw-r--r--hugs.scm3688logplainabout -rw-r--r--hurd.scm10722logplainabout -rw-r--r--ibus.scm26196logplainabout -rw-r--r--icu4c.scm4421logplainabout -rw-r--r--idris.scm11486logplainabout -rw-r--r--idutils.scm2816logplainabout -rw-r--r--image-processing.scm16852logplainabout -rw-r--r--image-viewers.scm17369logplainabout -rw-r--r--image.scm59645logplainabout -rw-r--r--imagemagick.scm9406logplainabout -rw-r--r--inklingreader.scm2239logplainabout -rw-r--r--inkscape.scm4434logplainabout -rw-r--r--ipfs.scm11245logplainabout -rw-r--r--irc.scm17781logplainabout -rw-r--r--iso-codes.scm4107logplainabout -rw-r--r--java.scm463698logplainabout -rw-r--r--javascript.scm19434logplainabout -rw-r--r--jemalloc.scm3218logplainabout -rw-r--r--jrnl.scm2353logplainabout -rw-r--r--julia.scm17050logplainabout -rw-r--r--kde-frameworks.scm140151logplainabout -rw-r--r--kde.scm24240logplainabout -rw-r--r--kerberos.scm8630logplainabout -rw-r--r--key-mon.scm2079logplainabout -rw-r--r--kodi.scm20643logplainabout -rw-r--r--language.scm16415logplainabout -rw-r--r--ld-wrapper.in11660logplainabout -rw-r--r--lego.scm5400logplainabout -rw-r--r--less.scm1883logplainabout -rw-r--r--lesstif.scm1817logplainabout -rw-r--r--libbsd.scm2092logplainabout -rw-r--r--libcanberra.scm6088logplainabout -rw-r--r--libdaemon.scm2903logplainabout -rw-r--r--libedit.scm1943logplainabout -rw-r--r--libevent.scm9924logplainabout -rw-r--r--libffcall.scm1813logplainabout -rw-r--r--libffi.scm7663logplainabout -rw-r--r--libftdi.scm1943logplainabout -rw-r--r--libidn.scm3562logplainabout -rw-r--r--libphidget.scm1635logplainabout -rw-r--r--libreoffice.scm43795logplainabout -rw-r--r--libsigsegv.scm2731logplainabout -rw-r--r--libunistring.scm3159logplainabout -rw-r--r--libunwind.scm2259logplainabout -rw-r--r--libusb.scm17837logplainabout -rw-r--r--license.scm6378logplainabout -rw-r--r--lighting.scm3418logplainabout -rw-r--r--linux.scm208712logplainabout -rw-r--r--lirc.scm6284logplainabout -rw-r--r--lisp.scm135142logplainabout -rw-r--r--llvm.scm17279logplainabout -rw-r--r--logging.scm7519logplainabout -rw-r--r--lolcode.scm2406logplainabout -rw-r--r--lout.scm5633logplainabout -rw-r--r--lsof.scm4940logplainabout -rw-r--r--lua.scm20382logplainabout -rw-r--r--lxde.scm20258logplainabout -rw-r--r--lxqt.scm42510logplainabout -rw-r--r--m4.scm2700logplainabout -rw-r--r--machine-learning.scm36434logplainabout -rw-r--r--mail.scm106790logplainabout -rw-r--r--make-bootstrap.scm30968logplainabout -rw-r--r--man.scm9779logplainabout -rw-r--r--markup.scm10116logplainabout -rw-r--r--marst.scm1763logplainabout -rw-r--r--mate.scm57084logplainabout -rw-r--r--maths.scm169828logplainabout -rw-r--r--maven.scm77238logplainabout -rw-r--r--mc.scm4262logplainabout -rw-r--r--mcrypt.scm4576logplainabout -rw-r--r--medical.scm2416logplainabout -rw-r--r--mes.scm5486logplainabout -rw-r--r--messaging.scm73883logplainabout -rw-r--r--microcom.scm2163logplainabout -rw-r--r--mingw.scm4006logplainabout -rw-r--r--moe.scm2216logplainabout -rw-r--r--monitoring.scm17008logplainabout -rw-r--r--mono.scm4681logplainabout -rw-r--r--moreutils.scm3212logplainabout -rw-r--r--motti.scm1669logplainabout -rw-r--r--mp3.scm20838logplainabout -rw-r--r--mpd.scm13885logplainabout -rw-r--r--mpi.scm11851logplainabout -rw-r--r--mtools.scm2673logplainabout -rw-r--r--multiprecision.scm9788logplainabout -rw-r--r--music.scm173882logplainabout -rw-r--r--musl.scm2182logplainabout -rw-r--r--nano.scm2156logplainabout -rw-r--r--ncdu.scm2109logplainabout -rw-r--r--ncurses.scm15320logplainabout -rw-r--r--netpbm.scm7853logplainabout -rw-r--r--nettle.scm4087logplainabout -rw-r--r--networking.scm90018logplainabout -rw-r--r--nfs.scm5411logplainabout -rw-r--r--nickle.scm2481logplainabout -rw-r--r--nim.scm3020logplainabout -rw-r--r--ninja.scm3111logplainabout -rw-r--r--node.scm9602logplainabout -rw-r--r--noweb.scm4392logplainabout -rw-r--r--ntp.scm7800logplainabout -rw-r--r--nutrition.scm3126logplainabout -rw-r--r--nvi.scm2913logplainabout -rw-r--r--ocaml.scm168538logplainabout -rw-r--r--ocr.scm3097logplainabout -rw-r--r--onc-rpc.scm5156logplainabout -rw-r--r--openbox.scm3936logplainabout