1 ! Copyright (C) 2009 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: combinators combinators.smart io.encodings.utf8 io.files
4 kernel namespaces sequences splitting unicode.case accessors
8 CONSTANT: zoneinfo-paths
10 "vocab:zoneinfo/africa"
11 "vocab:zoneinfo/antarctica"
13 "vocab:zoneinfo/australasia"
14 "vocab:zoneinfo/europe"
15 "vocab:zoneinfo/northamerica"
16 "vocab:zoneinfo/pacificnew"
17 "vocab:zoneinfo/solar87"
18 "vocab:zoneinfo/solar88"
19 "vocab:zoneinfo/solar89"
20 "vocab:zoneinfo/southamerica"
21 "vocab:zoneinfo/systemv"
22 "vocab:zoneinfo/leapseconds"
27 TUPLE: raw-zone name gmt-offset rules/save format until ;
28 TUPLE: raw-rule name from to type in on at save letters ;
29 TUPLE: raw-link from to ;
30 TUPLE: raw-leap year month day hms corr r/s ;
33 TUPLE: rule name from to at ;
37 : rule-to ( m string -- m n )
45 : rule-on ( string -- obj )
47 { [ dup string>number ] [ ] }
48 { [ "last" ?head ] [ month-abbreviation>n ] }
49 { [ ] [ month-abbreviation>n ] }
53 ! [ string>number -1/0. or ]
56 ! [ month-abbreviation>n ]
59 : raw-rule>rule ( raw-rule -- rule )
62 : parse-rule ( seq -- rule )
76 ] input<sequence raw-rule boa ;
78 : raw-zone>zone ( raw-zone -- zone )
81 : parse-zone ( seq -- zone )
88 } cleave raw-zone boa ;
90 : parse-partial-zone ( seq -- zone )
91 [ last-zone get name>> ] dip
97 } cleave raw-zone boa ;
99 : raw-link>link ( raw-link -- link )
102 : parse-link ( seq -- link )
109 ] input<sequence raw-link boa ;
111 : raw-leap>leap ( raw-leap -- leap )
114 : parse-leap ( seq -- link )
125 ] input<sequence raw-leap boa ;
127 : parse-line ( seq -- tuple )
130 { "zone" [ parse-zone dup last-zone set raw-zone>zone ] }
131 { "rule" [ parse-rule raw-rule>rule ] }
132 { "link" [ parse-link raw-link>link ] }
133 { "leap" [ parse-leap raw-leap>leap ] }
134 [ drop harvest parse-partial-zone ]
137 : parse-zoneinfo-file ( path -- seq )
139 [ "#" split1 drop ] map harvest
140 [ "\t " split harvest ] map harvest
141 [ [ parse-line ] map ] with-scope ;
143 : load-zoneinfo-files ( -- seq )
144 zoneinfo-paths [ parse-zoneinfo-file ] map ;
150 ! from - year or "min"
152 ! from "1938" or "min"
153 ! to "1945" or "max" or "only"
154 ! type "-" always "-"
155 ! in "Mar" -- 3-letter month name
156 ! on "26" or "Mon>=15" or lastSun lastFri
157 ! at "23:00s" "12:13:00s" "1:00s" "1:00u"
158 ! save "-0:00:05" "1:00" "0:14:15"
159 ! letters "S" or "-" or "AMT" "BDST"
162 ! name "Indian/Maldives"
163 ! gmt-offset "4:54:00" "9:55:56" "-9:55:56"
164 ! rules/save "-" "0:20" "0:30" "1:00" "AN" "W-Eur" "Winn" "Zion" "sol87" "sol88"
165 ! format "LMT" "%s" "%sT" "A%sT" "AC%sT" "ACT"
167 ! { "1847" "Dec" "1" "0:00s" }
168 ! { "1883" "Nov" "18" "12:12:57" }
169 ! { "1989" "Sep" "lastSun" "2:00s" }
172 ! T{ link { from "Asia/Riyadh88" } { to "Mideast/Riyadh88" } }