]> gitweb.factorcode.org Git - factor.git/commitdiff
zoneinfo: fix parsing of # in europe file. add some unit tests
authorDoug Coleman <doug.coleman@gmail.com>
Tue, 19 Jul 2022 04:55:57 +0000 (23:55 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Tue, 19 Jul 2022 04:55:57 +0000 (23:55 -0500)
extra/zoneinfo/zoneinfo-tests.factor
extra/zoneinfo/zoneinfo.factor

index f4a6b9520967f897a5b8f628040db2c0dbd936ce..1fd0d878d68be2ad94d7705f5507bffe1a1f01e7 100644 (file)
@@ -1,6 +1,7 @@
 ! Copyright (C) 2013 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel sequences tools.test zoneinfo ;
+USING: accessors assocs calendar kernel math sequences sets
+tools.test zoneinfo ;
 
 { t } [ "PST8PDT" find-zone-rules and >boolean ] unit-test
 
@@ -15,3 +16,31 @@ USING: kernel sequences tools.test zoneinfo ;
 } [
     "EST" find-zone
 ] unit-test
+
+{
+    T{ raw-zone
+        { name "Pacific/Kiritimati" }
+        { gmt-offset "14:00" }
+        { rules/save "-" }
+        { format "+14" }
+        { until { } }
+    }
+} [
+    "Pacific/Kiritimati" timezone>rules last
+] unit-test
+
+! First and last timezones + 24 hours = length of day
+{ 50 } [
+    now midnight "Etc/GMT+12" find-zone gmt-offset>> hms>duration >>gmt-offset
+    now midnight "Etc/GMT-14" find-zone gmt-offset>> hms>duration >>gmt-offset
+    time- duration>hours 24 +
+] unit-test
+
+! Make sure we handle # in weird places, like in "Europe/Athens"
+{ } [
+    raw-zone-map values
+    [ [ gmt-offset>> ] map ] map concat members
+    [ hms>duration ] map
+    drop
+] unit-test
+
index 9f4f22ad0f201c4a298334b171cd34819133b4b8..834408aac3fe76f5e05d83be0009f64640bd8a41 100644 (file)
@@ -19,12 +19,12 @@ CONSTANT: zoneinfo-paths
     "vocab:zoneinfo/pacificnew"
     "vocab:zoneinfo/southamerica"
     "vocab:zoneinfo/backzone"
+    "vocab:zoneinfo/etcetera"
 }
 
 CONSTANT: zoneinfo-extra-paths
 {
     "vocab:zoneinfo/backward"
-    "vocab:zoneinfo/etcetera"
     "vocab:zoneinfo/factory"
     "vocab:zoneinfo/leapseconds"
     "vocab:zoneinfo/systemv"
@@ -32,7 +32,8 @@ CONSTANT: zoneinfo-extra-paths
 
 : zoneinfo-lines ( path -- seq )
     utf8 file-lines
-    [ { [ length 0 = ] [ "#" head? ] } 1|| ] reject ;
+    [ { [ length 0 = ] [ "#" head? ] } 1|| ] reject
+    [ "#" split1-last drop ] map ;
 
 TUPLE: zonetab codes lat lng tz comments ;
 C: <zonetab> zonetab
@@ -285,6 +286,11 @@ ERROR: unknown-last-day string ;
     ":" split1 "0" or [ string>number ] bi@
     [ instant ] 2dip 0 set-time ;
 
+: hms>duration ( str -- duration )
+    ":" split 3 "0" pad-tail
+    [ string>number ] map first3
+    [ instant ] 3dip set-time ;
+
 : rule>timestamp-rest ( timestamp zone -- from )
     {
         [ over fp-infinity? [ drop ] [ in>> month-abbreviation-index >>month ] if ]
@@ -325,7 +331,7 @@ ERROR: unknown-last-day string ;
     raw-rule-map at [
         [
             [ rule>timestamps [ dup fp-infinity? [ timestamp>unix-time ] unless ] bi@ 2array ]
-            [ [ save>> hm>duration ] [ letters>> ] bi 2array ] bi 2array
+            [ [ save>> hms>duration ] [ letters>> ] bi 2array ] bi 2array
         ] map
     ] keep zip ;