]> gitweb.factorcode.org Git - factor.git/commitdiff
zoneinfo: Working on parsing raw rules.
authorDoug Coleman <doug.coleman@gmail.com>
Tue, 19 Mar 2013 22:32:37 +0000 (15:32 -0700)
committerDoug Coleman <doug.coleman@gmail.com>
Wed, 20 Mar 2013 00:23:26 +0000 (17:23 -0700)
extra/zoneinfo/zoneinfo.factor

index 2e2ee25717e85be0bdd580090cb7a5814c806729..7d263a6a87614bd9e32f9a05713d4bdd7124854d 100644 (file)
@@ -3,7 +3,7 @@
 USING: accessors assocs combinators combinators.short-circuit
 combinators.smart fry io.encodings.utf8 io.files kernel
 math.parser math.statistics memoize namespaces sequences
-splitting unicode.case ;
+splitting unicode.case calendar arrays ;
 IN: zoneinfo
 
 CONSTANT: zoneinfo-paths
@@ -159,6 +159,31 @@ ERROR: zone-not-found name ;
 : find-zone-rules ( string -- zone rules )
     find-zone dup rules/save>> find-rules ;
 
+: number>value ( n -- n' )
+    {
+        { "only" [ f ] }
+        { "min" [ f ] }
+        { "max" [ t ] }
+        [ string>number ]
+    } case ;
+
+: on>value ( n -- n' )
+    ! "3", "Thu>=8" always >=, "lastFri"
+    {
+        { [ dup 3 swap ?nth CHAR: > = ] [
+            3 cut 2 tail [ day-abbreviation3>predicate ] [ string>number ] bi* 2array
+        ] }
+        { [ dup "last" head? ] [ 4 tail day-abbreviation3>n ] }
+        [ string>number ]
+    } cond ;
+
+: raw-rule>triple ( raw-rule -- quot )
+    {
+        [ from>> string>number ]
+        [ in>> month-abbreviation>n ]
+        [ on>> on>value ]
+    } cleave>array ;
+
 ! "Europe/Helsinki" find-zone-rules
 
 ! Rule