 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors arrays ascii assocs assocs.extras calendar
 calendar.english combinators combinators.short-circuit
-combinators.smart csv grouping interval-maps io.encodings.utf8
-io.files kernel math math.parser memoize namespaces sequences
-sequences.extras sorting splitting splitting.extras ;
+combinators.smart countries grouping interval-maps
+io.encodings.utf8 io.files kernel math math.parser namespaces
+sequences sequences.extras sorting splitting splitting.extras ;
 QUALIFIED: sets
 IN: zoneinfo
 


: parse-zoneinfo-file ( path -- seq )
    zoneinfo-lines
    [ "\t " split ] map
    [ parse-zoneinfo-line ] map ;

MEMO: zoneinfo-files ( -- seq )

    zoneinfo-country-zones
    [ [ codes>> ] [ tz>> ] bi [ 2array ] curry map ] map concat ;

: lookup-country-name ( seq -- seq' ) alpha-2 ?at drop ; inline
: lookup-country-names ( seq -- seq' ) [ lookup-country-name ] map ;

: timezone>country-map ( -- alist )
    parse-zonetabs [ second ] collect-key-by ;

: country>timezones-map ( -- alist )
    parse-zonetabs [ first ] collect-value-by ;

: country-timezones-map ( -- alist )
    country>timezones-map [ dup lookup-country-names zip ] map-values ;

SYMBOL: last-zone

