From c55c4c447007538abd44d564af91056c3a2afc7c Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Tue, 19 Mar 2013 15:32:37 -0700 Subject: [PATCH] zoneinfo: Working on parsing raw rules. --- extra/zoneinfo/zoneinfo.factor | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/extra/zoneinfo/zoneinfo.factor b/extra/zoneinfo/zoneinfo.factor index 2e2ee25717..7d263a6a87 100644 --- a/extra/zoneinfo/zoneinfo.factor +++ b/extra/zoneinfo/zoneinfo.factor @@ -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