]> gitweb.factorcode.org Git - factor.git/blobdiff - extra/calendar/holidays/us/us.factor
Fixes #2966
[factor.git] / extra / calendar / holidays / us / us.factor
index 2d66ec5468435c3c7b8e21db204240789b42d968..308bb2b51cef76cc58a999a19883edee8743beba 100644 (file)
@@ -1,90 +1,89 @@
 ! 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 ;
+! See https://factorcode.org/license.txt for BSD license.
+USING: accessors calendar calendar.holidays
+calendar.holidays.private calendar.private combinators
+combinators.short-circuit kernel math sequences ;
 IN: calendar.holidays.us
 
-SINGLETONS: world us us-federal canada commonwealth-of-nations ;
+SINGLETONS: us us-federal us-market ;
 
-<<
-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 )
+HOLIDAY: new-years-day january 1 >>day ;
+HOLIDAY-NAME: new-years-day world "New Year's Day"
+HOLIDAY-NAME: new-years-day us-federal "New Year's Day"
+HOLIDAY-NAME: new-years-day us-market "New Year's Day"
 
 <PRIVATE
 
-: (holidays) ( singleton -- seq )
-    all-words swap '[ "holiday" word-prop _ swap key? ] filter ;
-
-: adjust-federal-holiday ( timestamp -- timestamp' )
+: adjust-federal-holiday ( timestamp -- timestamp )
     {
-        { [ dup saturday? ] [ 1 days time- ] }
-        { [ dup sunday? ] [ 1 days time+ ] }
+        ! Don't adjust to Dec 31
+        { [ dup { [ dup new-years-day same-day? ] [ saturday? ] } 1&& ] [ ] }
+        { [ dup saturday? ] [ -1 days (time+) ] }
+        { [ dup sunday? ] [ 1 days (time+) ] }
         [ ]
     } cond ;
 
-M: us-federal holidays
-    (holidays)
-    [ execute( timestamp -- timestamp' ) adjust-federal-holiday ] with map ;
+PRIVATE>
 
-M: object holidays
-    (holidays) [ execute( timestamp -- timestamp' ) ] with map ;
+: adjust-federal-holidays ( timestamp seq -- seq' )
+    [
+        [ clone ] dip execute( timestamp -- timestamp ) adjust-federal-holiday
+    ] with map ;
 
-PRIVATE>
+M: us-federal holidays
+    (holidays) adjust-federal-holidays ;
 
-: holiday? ( timestamp/n singleton -- ? )
-    [ holidays ] [ drop ] 2bi '[ _ same-day? ] any? ;
+M: us-market holidays
+    (holidays) adjust-federal-holidays ;
 
 : us-post-office-open? ( timestamp -- ? )
     { [ sunday? not ] [ us-federal holiday? not ] } 1&& ;
 
-HOLIDAY: new-years-day january 1 >>day ;
-HOLIDAY-NAME: new-years-day world "New Year's Day"
-HOLIDAY-NAME: new-years-day us-federal "New Year's Day"
-
-HOLIDAY: martin-luther-king-day january 3 monday-of-month ;
+HOLIDAY: martin-luther-king-day january 2 monday-of-month ;
 HOLIDAY-NAME: martin-luther-king-day us-federal "Martin Luther King Day"
+HOLIDAY-NAME: martin-luther-king-day us-market "Martin Luther King Day"
 
-HOLIDAY: inauguration-day year dup 4 neg rem + january 20 >>day ;
+HOLIDAY: inauguration-day january 20 >>day [ dup 4 neg rem + ] change-year ;
 HOLIDAY-NAME: inauguration-day us "Inauguration Day"
 
-HOLIDAY: washingtons-birthday february 3 monday-of-month ;
-HOLIDAY-NAME: washingtons-birthday us-federal "Washington's Birthday"
+HOLIDAY: washingtons-birthday february 2 monday-of-month ;
+HOLIDAY-NAME: washingtons-birthday us-market "Washington's Birthday"
+
+HOLIDAY: good-friday easter 2 days time- ;
+HOLIDAY-NAME: good-friday us-market "Good Friday"
+
+HOLIDAY: presidents-day february 2 monday-of-month ;
+HOLIDAY-NAME: presidents-day us-federal "President's Day"
 
 HOLIDAY: memorial-day may last-monday-of-month ;
 HOLIDAY-NAME: memorial-day us-federal "Memorial Day"
+HOLIDAY-NAME: memorial-day us-market "Memorial Day"
+
+HOLIDAY: juneteenth-national-independence-day june 19 >>day ;
+HOLIDAY-NAME: juneteenth-national-independence-day us-federal "Juneteenth National Independence Day"
+HOLIDAY-NAME: juneteenth-national-independence-day us-market "Juneteenth National Independence Day"
 
 HOLIDAY: independence-day july 4 >>day ;
 HOLIDAY-NAME: independence-day us-federal "Independence Day"
+HOLIDAY-NAME: independence-day us-market "Independence Day"
 
-HOLIDAY: labor-day september 1 monday-of-month ;
+HOLIDAY: labor-day september 0 monday-of-month ;
 HOLIDAY-NAME: labor-day us-federal "Labor Day"
+HOLIDAY-NAME: labor-day us-market "Labor Day"
 
-HOLIDAY: columbus-day october 2 monday-of-month ;
+HOLIDAY: columbus-day october 1 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: thanksgiving-day november 3 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-NAME: thanksgiving-day us-market "Thanksgiving Day"
 
 HOLIDAY: christmas-day december 25 >>day ;
 HOLIDAY-NAME: christmas-day world "Christmas Day"
 HOLIDAY-NAME: christmas-day us-federal "Christmas Day"
+HOLIDAY-NAME: christmas-day us-market "Christmas Day"
 
 HOLIDAY: belly-laugh-day january 24 >>day ;
 
@@ -102,8 +101,6 @@ ALIAS: first-day-of-lent ash-wednesday
 
 HOLIDAY: fat-tuesday ash-wednesday 1 days time- ;
 
-HOLIDAY: good-friday easter 2 days time- ;
-
 HOLIDAY: tax-day april 15 >>day ;
 
 HOLIDAY: earth-day april 22 >>day ;
@@ -112,13 +109,15 @@ HOLIDAY: administrative-professionals-day april last-saturday-of-month wednesday
 
 HOLIDAY: cinco-de-mayo may 5 >>day ;
 
-HOLIDAY: mothers-day may 2 sunday-of-month ;
+HOLIDAY: mothers-day may 1 sunday-of-month ;
+
+HOLIDAY: armed-forces-day may 2 saturday-of-month ;
 
-HOLIDAY: armed-forces-day may 3 saturday-of-month ;
+HOLIDAY: national-donut-day june 0 friday-of-month ;
 
 HOLIDAY: flag-day june 14 >>day ;
 
-HOLIDAY: parents-day july 4 sunday-of-month ;
+HOLIDAY: parents-day july 3 sunday-of-month ;
 
 HOLIDAY: grandparents-day labor-day 1 weeks time+ ;
 
@@ -130,11 +129,11 @@ HOLIDAY: citizenship-day september 17 >>day ;
 
 HOLIDAY: bosss-day october 16 >>day ;
 
-HOLIDAY: sweetest-day october 3 saturday-of-month ;
+HOLIDAY: sweetest-day october 2 saturday-of-month ;
 
 HOLIDAY: halloween october 31 >>day ;
 
-HOLIDAY: election-day november 1 monday-of-month 1 days time+ ;
+HOLIDAY: election-day november 0 monday-of-month 1 days time+ ;
 
 HOLIDAY: black-friday thanksgiving-day 1 days time+ ;