From 7926c8027a67ff9d64b7d466cfd0bff49c60f6c1 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Mon, 18 Jul 2022 23:55:57 -0500 Subject: [PATCH] zoneinfo: fix parsing of # in europe file. add some unit tests --- extra/zoneinfo/zoneinfo-tests.factor | 31 +++++++++++++++++++++++++++- extra/zoneinfo/zoneinfo.factor | 12 ++++++++--- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/extra/zoneinfo/zoneinfo-tests.factor b/extra/zoneinfo/zoneinfo-tests.factor index f4a6b95209..1fd0d878d6 100644 --- a/extra/zoneinfo/zoneinfo-tests.factor +++ b/extra/zoneinfo/zoneinfo-tests.factor @@ -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 + diff --git a/extra/zoneinfo/zoneinfo.factor b/extra/zoneinfo/zoneinfo.factor index 9f4f22ad0f..834408aac3 100644 --- a/extra/zoneinfo/zoneinfo.factor +++ b/extra/zoneinfo/zoneinfo.factor @@ -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 @@ -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 ; -- 2.34.1