You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.4 KiB

: PREP-DATE ( day year month -- newDay newYear newMonth )
DUP 3 < IF \ if month is Jan or Feb
-ROT
DUP ROT + \ set newDay to day + year
SWAP 1 - \ and set newYear to year - 1
ELSE
-ROT
DUP ROT + 2 - \ set newDay to day + year - 2
SWAP
THEN ROT ;
: CALCULATE-WEEKDAY ( year month day -- dayOfWeekNum )
SWAP \ wmonth ( year day month )
23 * 9 / \ ( year day result )
\ wday
+ 4 + \ ( year result )
SWAP DUP \ wyear ( result year year )
4 / \ ( result year result2 )
SWAP DUP \ wyear ( result result2 year year )
100 / \ ( result result2 year result3 )
SWAP -ROT \ ( result year result2 result3 )
- ROT + \ ( year result )
SWAP \ wyear ( result year )
400 / + \ ( result )
7 MOD ;
: NUM-TO-WEEKDAY ( dayOfWeekNum -- dayOfWeekStr )
CASE
0 OF S" Sunday" ENDOF
1 OF S" Monday" ENDOF
2 OF S" Tuesday" ENDOF
3 OF S" Wednesday" ENDOF
4 OF S" Thursday" ENDOF
5 OF S" Friday" ENDOF
6 OF S" Saturday" ENDOF
ENDCASE ;
\ https://stackoverflow.com/a/28520469/14857724
\ ( (d+=(m<3?y--:(y-2))), (23*m/9+d+4+y/4-y/100+y/400) ) % 7
TIME&DATE ( t1 t2 t3 day month year )
VALUE year VALUE month VALUE day DROP DROP DROP \ store dates and drop times
day year month PREP-DATE ROT CALCULATE-WEEKDAY DUP VALUE weekday NUM-TO-WEEKDAY
BYE