NoteTab Clip - Day of Week
19 Feb 2009I seem to be doing rather a lot with NoteTab at the moment and again I thought I’d share something useful I scripted. This time around, it’s relating to date/time and days of the week.
NoteTab has limited date related functionality but I needed to get the day of the week from a date. I chose the Doomsday algorithm to base my clip on and the clips in this post simply generate an integer that represents the day of the week and then translate that into text. The test clip simply takes a date from the user (defaults to today’s date) and then returns a prompt box informing the user what the day of the week is.
H="Day of Week Test"
^!Prompt ^$DayOfWeekLong(^$DayOfWeekInt(^?{(M="00/00/0000")Enter date=^$GetDate(dd/mm/yyyy)$})$)$
H="_DayOfWeekInt"
;Sunday=0/Monday=1/Tuesday=2/Wednesday=3/Thursday=4/Friday=5/Saturday=6
^!SetListDelimiter /
^!SetArray %TheDate%=^&
^!Set %Day%=^%TheDate1%
^!Set %Month%=^$Calc(((^%TheDate2%+9) MOD 12)+1)$
^!Set %YearFull%=^%TheDate3%
;If we are in January or February (month = 11 or 12), reduce the year by 1
^!If ^%Month%<10 SKIP
^!Dec %YearFull%
;Extract the year components
^!Set %YearShort%=^$StrCopyRight("^%YearFull%";2)$
^!Set %Century%=^$StrCopyLeft("^%YearFull%";2)$
:Calculate
^!Result ^$Calc((^%Day% + FLOOR(2.6*^%Month% - 0.2) - 2*^%Century% + ^%YearShort% + FLOOR(^%YearShort%/4) + FLOOR(^%Century%/4)) MOD 7)$
H="_DayOfWeekLong"
^!SetListDelimiter /
^!SetArray %Days%=Sunday/Monday/Tuesday/Wednesday/Thursday/Friday/Saturday
^!Set %Key%=^$Calc(^$DayOfWeekInt(^%TheDate%)$+1)$
^!Result ^%Days^%Key%%