]> gitweb.factorcode.org Git - factor.git/commitdiff
Find timezone based on string
authorDoug Coleman <doug.coleman@gmail.com>
Tue, 5 Jul 2011 17:24:26 +0000 (12:24 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Thu, 8 Sep 2011 22:47:47 +0000 (15:47 -0700)
extra/zoneinfo/zoneinfo.factor

index e298046dd3f0462ad51432a2482d357820779746..673da611a9a74fb90e726f687b9f263fc2b44b02 100644 (file)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: combinators combinators.smart io.encodings.utf8 io.files
 kernel namespaces sequences splitting unicode.case accessors
-math.parser calendar ;
+math.parser calendar memoize fry ;
 IN: zoneinfo
 
 CONSTANT: zoneinfo-paths
@@ -125,9 +125,23 @@ TUPLE: leap ;
     [ "\t " split harvest ] map harvest
     [ [ parse-line ] map ] with-scope ;
 
-: load-zoneinfo-files ( -- seq )
+MEMO: zoneinfo-files ( -- seq )
     zoneinfo-paths [ parse-zoneinfo-file ] map ;
+    
+GENERIC: zone-matches? ( string rule -- ? )
 
+M: raw-rule zone-matches? name>> = ;
+M: raw-zone zone-matches? name>> = ;
+M: raw-link zone-matches? from>> = ;
+M: raw-leap zone-matches? 2drop f ;
+
+: find-timezone-rules ( string -- seq )
+    [ zoneinfo-files ] dip '[
+        [ [ _ ] dip zone-matches? ] filter
+    ] map concat sift ;
+
+: find-applicable-rules ( string -- seq )
+    find-timezone-rules [ until>> empty? ] filter ;
 
 
 ! Rule