]> gitweb.factorcode.org Git - factor.git/commitdiff
zoneinfo: Add word to parse zone.
authorDoug Coleman <doug.coleman@gmail.com>
Wed, 4 Nov 2020 05:19:55 +0000 (23:19 -0600)
committerDoug Coleman <doug.coleman@gmail.com>
Wed, 4 Nov 2020 05:19:55 +0000 (23:19 -0600)
extra/zoneinfo/zoneinfo.factor

index 87b3f8cabf2211e4d680b0f0cdf51ef60f5daeb1..a599d4b9e6b415dc5f758fd65ed09ee27cb2e403 100644 (file)
@@ -1,9 +1,9 @@
 ! Copyright (C) 2009 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors arrays assocs calendar.english combinators
-combinators.smart io.encodings.utf8 io.files kernel math.parser
-memoize namespaces sequences sequences.extras sorting splitting
-unicode ;
+USING: accessors arrays ascii assocs calendar calendar.english
+combinators combinators.smart io.encodings.utf8 io.files kernel
+math.parser memoize namespaces sequences sequences.extras
+sorting splitting splitting.extras ;
 IN: zoneinfo
 
 CONSTANT: zoneinfo-paths
@@ -151,6 +151,32 @@ ERROR: zone-not-found name ;
         [ string>number ]
     } cond ;
 
+: zone-month ( timestamp month -- timestamp' )
+    month-abbreviation-index >>month ;
+
+: zone-day ( timestamp day -- timestamp' )
+    {
+        { "Sun>=1" [ 0 sunday-of-month ] }
+        { "lastSun" [ last-sunday-of-month ] }
+        [ string>number >>day ]
+    } case ;
+
+! XXX: Don't just drop the s/u, e.g. 2:00:00s
+: zone-time ( timestamp time -- timestamp' )
+    [ Letter? ] split-tail drop
+    time>offset first3 set-time ;
+
+: until>timestamp ( seq -- timestamp )
+    [ 9999 <year-gmt> ]
+    [
+        4 f pad-tail first4 {
+            [ string>number <year-gmt> ]
+            [ [ zone-month ] when* ]
+            [ [ zone-day ] when* ]
+            [ [ zone-time ] when* ]
+        } spread
+    ] if-empty ;
+
 : raw-rule>triple ( raw-rule -- quot )
     {
         [ from>> string>number ]