working on holiday names from timestamp
parent
6c75287bef
commit
48394f8449
|
@ -0,0 +1 @@
|
||||||
|
Doug Coleman
|
|
@ -0,0 +1 @@
|
||||||
|
Doug Coleman
|
|
@ -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
|
|
@ -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"
|
|
@ -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"
|
|
@ -1,7 +1,7 @@
|
||||||
! Copyright (C) 2009 Doug Coleman.
|
! Copyright (C) 2009 Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! 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
|
IN: calendar.holidays.us.tests
|
||||||
|
|
||||||
[ 10 ] [ 2009 us-federal holidays length ] unit-test
|
[ 10 ] [ 2009 us-federal holidays length ] unit-test
|
||||||
[ ] [ 2009 canada holidays drop ] unit-test
|
|
||||||
|
|
|
@ -1,29 +1,15 @@
|
||||||
! Copyright (C) 2009 Doug Coleman.
|
! Copyright (C) 2009 Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors assocs calendar combinators
|
USING: accessors assocs calendar calendar.holidays
|
||||||
combinators.short-circuit fry kernel lexer math namespaces
|
calendar.holidays.private combinators combinators.short-circuit
|
||||||
parser sequences shuffle vocabs words ;
|
fry kernel lexer math namespaces parser sequences shuffle
|
||||||
|
vocabs words ;
|
||||||
IN: calendar.holidays.us
|
IN: calendar.holidays.us
|
||||||
|
|
||||||
SINGLETONS: world us us-federal canada commonwealth-of-nations ;
|
SINGLETONS: us us-federal ;
|
||||||
|
|
||||||
<<
|
|
||||||
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 )
|
|
||||||
|
|
||||||
<PRIVATE
|
<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 saturday? ] [ 1 days time- ] }
|
||||||
|
@ -31,18 +17,12 @@ GENERIC: holidays ( n symbol -- seq )
|
||||||
[ ]
|
[ ]
|
||||||
} cond ;
|
} cond ;
|
||||||
|
|
||||||
|
PRIVATE>
|
||||||
|
|
||||||
M: us-federal holidays
|
M: us-federal holidays
|
||||||
(holidays)
|
(holidays)
|
||||||
[ execute( timestamp -- timestamp' ) adjust-federal-holiday ] with map ;
|
[ 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 -- ? )
|
: us-post-office-open? ( timestamp -- ? )
|
||||||
{ [ sunday? not ] [ us-federal holiday? not ] } 1&& ;
|
{ [ 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: columbus-day october 2 monday-of-month ;
|
||||||
HOLIDAY-NAME: columbus-day us-federal "Columbus Day"
|
HOLIDAY-NAME: columbus-day us-federal "Columbus Day"
|
||||||
|
|
||||||
HOLIDAY: veterans-day november 11 >>day ;
|
HOLIDAY-NAME: armistice-day us-federal "Veterans 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: thanksgiving-day november 4 thursday-of-month ;
|
HOLIDAY: thanksgiving-day november 4 thursday-of-month ;
|
||||||
HOLIDAY-NAME: thanksgiving-day us-federal "Thanksgiving Day"
|
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: christmas-day december 25 >>day ;
|
||||||
HOLIDAY-NAME: christmas-day world "Christmas Day"
|
HOLIDAY-NAME: christmas-day world "Christmas Day"
|
||||||
HOLIDAY-NAME: christmas-day us-federal "Christmas Day"
|
HOLIDAY-NAME: christmas-day us-federal "Christmas Day"
|
||||||
|
|
Loading…
Reference in New Issue