! 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
} [
"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
+
"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"
: 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
":" 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 ]
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 ;