]> gitweb.factorcode.org Git - factor.git/commitdiff
working on holiday names from timestamp
authorDoug Coleman <doug.coleman@gmail.com>
Fri, 13 Nov 2009 20:53:27 +0000 (14:53 -0600)
committerDoug Coleman <doug.coleman@gmail.com>
Fri, 13 Nov 2009 20:53:27 +0000 (14:53 -0600)
extra/calendar/holidays/authors.txt [new file with mode: 0644]
extra/calendar/holidays/canada/authors.txt [new file with mode: 0644]
extra/calendar/holidays/canada/canada-tests.factor [new file with mode: 0644]
extra/calendar/holidays/canada/canada.factor [new file with mode: 0644]
extra/calendar/holidays/holidays.factor [new file with mode: 0644]
extra/calendar/holidays/us/us-tests.factor
extra/calendar/holidays/us/us.factor

diff --git a/extra/calendar/holidays/authors.txt b/extra/calendar/holidays/authors.txt
new file mode 100644 (file)
index 0000000..b4bd0e7
--- /dev/null
@@ -0,0 +1 @@
+Doug Coleman
\ No newline at end of file
diff --git a/extra/calendar/holidays/canada/authors.txt b/extra/calendar/holidays/canada/authors.txt
new file mode 100644 (file)
index 0000000..b4bd0e7
--- /dev/null
@@ -0,0 +1 @@
+Doug Coleman
\ No newline at end of file
diff --git a/extra/calendar/holidays/canada/canada-tests.factor b/extra/calendar/holidays/canada/canada-tests.factor
new file mode 100644 (file)
index 0000000..916f5ee
--- /dev/null
@@ -0,0 +1,7 @@
+! Copyright (C) 2009 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: calendar.holidays calendar.holidays.canada kernel
+tools.test ;
+IN: calendar.holidays.canada.tests
+
+[ ] [ 2009 canada holidays drop ] unit-test
diff --git a/extra/calendar/holidays/canada/canada.factor b/extra/calendar/holidays/canada/canada.factor
new file mode 100644 (file)
index 0000000..304388f
--- /dev/null
@@ -0,0 +1,11 @@
+! Copyright (C) 2009 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: calendar calendar.holidays ;
+IN: calendar.holidays.canada
+
+SINGLETONS: canada canadian-federal ;
+
+HOLIDAY: canadian-thanksgiving-day october 2 monday-of-month ;
+HOLIDAY-NAME: canadian-thanksgiving-day canadian-federal "Thanksgiving Day"
+
+HOLIDAY-NAME: armistice-day commonwealth-of-nations "Remembrance Day"
diff --git a/extra/calendar/holidays/holidays.factor b/extra/calendar/holidays/holidays.factor
new file mode 100644 (file)
index 0000000..a50c709
--- /dev/null
@@ -0,0 +1,55 @@
+! Copyright (C) 2009 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors assocs calendar fry kernel parser sequences
+shuffle vocabs words memoize ;
+IN: calendar.holidays
+
+SINGLETONS: all world commonwealth-of-nations ;
+
+<<
+SYNTAX: HOLIDAY:
+    CREATE-WORD
+    dup "holiday" word-prop [
+        dup H{ } clone "holiday" set-word-prop
+    ] unless
+    parse-definition (( timestamp/n -- timestamp )) define-declared ;
+
+SYNTAX: HOLIDAY-NAME:
+    scan-word "holiday" word-prop scan-word scan-object spin set-at ;
+>>
+
+GENERIC: holidays ( n singleton -- seq )
+
+<PRIVATE
+
+: (holidays) ( singleton -- seq )
+    all-words swap '[ "holiday" word-prop _ swap key? ] filter ;
+
+M: object holidays
+    (holidays) [ execute( timestamp -- timestamp' ) ] with map ;
+
+PRIVATE>
+
+M: all holidays
+    drop
+    all-words [ "holiday" word-prop key? ] with filter ;
+
+: holiday? ( timestamp/n singleton -- ? )
+    [ holidays ] [ drop ] 2bi '[ _ same-day? ] any? ;
+
+: holiday-assoc ( timestamp/n singleton -- assoc )
+    [ >gmt midnight ] dip
+    [ dup (holidays) ] [ drop ] 2bi
+    '[ [ _ swap execute( ts -- ts' ) >gmt midnight ] keep ] { } map>assoc
+    rot '[ drop _ same-day? ] assoc-filter
+    values [ "holiday" word-prop at ] with map ;
+
+: holiday-name ( singleton word -- string/f )
+    "holiday" word-prop at ;
+
+: holiday-names ( timestamp/n singleton -- seq )
+    [ nip ] [ holiday-assoc ] 2bi
+    [ holiday-name ] with map ;
+
+HOLIDAY: armistice-day november 11 >>day ;
+HOLIDAY-NAME: armistice-day world "Armistice Day"
index 995d1ff5611d65432db60e27e8bc67c605b35598..23ab535e9802a613d0595e778dfabb233daf2c92 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2009 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: calendar.holidays.us kernel sequences tools.test ;
+USING: calendar.holidays calendar.holidays.us kernel sequences
+tools.test ;
 IN: calendar.holidays.us.tests
 
 [ 10 ] [ 2009 us-federal holidays length ] unit-test
-[ ] [ 2009 canada holidays drop ] unit-test
index 2d66ec5468435c3c7b8e21db204240789b42d968..a4fb19c5979204b93e63f466c3ece97651d6b261 100644 (file)
@@ -1,29 +1,15 @@
 ! Copyright (C) 2009 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors assocs calendar combinators
-combinators.short-circuit fry kernel lexer math namespaces
-parser sequences shuffle vocabs words ;
+USING: accessors assocs calendar calendar.holidays
+calendar.holidays.private combinators combinators.short-circuit
+fry kernel lexer math namespaces parser sequences shuffle
+vocabs words ;
 IN: calendar.holidays.us
 
-SINGLETONS: world us us-federal canada commonwealth-of-nations ;
-
-<<
-SYNTAX: HOLIDAY:
-    CREATE-WORD
-    dup H{ } clone "holiday" set-word-prop
-    parse-definition (( timestamp/n -- timestamp )) define-declared ;
-
-SYNTAX: HOLIDAY-NAME:
-    scan-word "holiday" word-prop scan-word scan-object spin set-at ;
->>
-
-GENERIC: holidays ( n symbol -- seq )
+SINGLETONS: us us-federal ;
 
 <PRIVATE
 
-: (holidays) ( singleton -- seq )
-    all-words swap '[ "holiday" word-prop _ swap key? ] filter ;
-
 : adjust-federal-holiday ( timestamp -- timestamp' )
     {
         { [ dup saturday? ] [ 1 days time- ] }
@@ -31,18 +17,12 @@ GENERIC: holidays ( n symbol -- seq )
         [ ]
     } cond ;
 
+PRIVATE>
+
 M: us-federal holidays
     (holidays)
     [ execute( timestamp -- timestamp' ) adjust-federal-holiday ] with map ;
 
-M: object holidays
-    (holidays) [ execute( timestamp -- timestamp' ) ] with map ;
-
-PRIVATE>
-
-: holiday? ( timestamp/n singleton -- ? )
-    [ holidays ] [ drop ] 2bi '[ _ same-day? ] any? ;
-
 : us-post-office-open? ( timestamp -- ? )
     { [ sunday? not ] [ us-federal holiday? not ] } 1&& ;
 
@@ -71,17 +51,11 @@ HOLIDAY-NAME: labor-day us-federal "Labor Day"
 HOLIDAY: columbus-day october 2 monday-of-month ;
 HOLIDAY-NAME: columbus-day us-federal "Columbus Day"
 
-HOLIDAY: veterans-day november 11 >>day ;
-HOLIDAY-NAME: veterans-day us-federal "Veterans Day"
-HOLIDAY-NAME: veterans-day world "Armistice Day"
-HOLIDAY-NAME: veterans-day commonwealth-of-nations "Remembrance Day"
+HOLIDAY-NAME: armistice-day us-federal "Veterans Day"
 
 HOLIDAY: thanksgiving-day november 4 thursday-of-month ;
 HOLIDAY-NAME: thanksgiving-day us-federal "Thanksgiving Day"
 
-HOLIDAY: canadian-thanksgiving-day october 2 monday-of-month ;
-HOLIDAY-NAME: canadian-thanksgiving-day canada "Thanksgiving Day"
-
 HOLIDAY: christmas-day december 25 >>day ;
 HOLIDAY-NAME: christmas-day world "Christmas Day"
 HOLIDAY-NAME: christmas-day us-federal "Christmas Day"