Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Business Days...
#3
Function IsTodayHoliday
Code:
Copy      Help
;/
function!

;Returns 1 if today is a holiday (Sunday, Saturday, etc), 0 if not.
;Uses "$my qm$\nbd.ini" that is created using macro "Create Holidays File". Error if the file does not exist.

;EXAMPLE
;if IsTodayHoliday
;,out "holiday"


str inifile="$my qm$\nbd.ini"
if(!dir(inifile)) mes- "File not found:[]%s[][]Read macro 'Create Holidays File'." "" "x" inifile

DATE d.getclock
SYSTEMTIME st
d.tosystemtime(st)
str s1 s2(st.wDay) s3.format("%i-%i" st.wYear st.wMonth)
ret rget(s1 s2 s3 inifile)

Macro Create Holidays File
Code:
Copy      Help
;This macro creates ini file containing sundays and saturdays of next 10 years and of the remainder of this year.
;Run this macro. Then edit the file: add other holidays and possibly remove sun/saturdays that aren't holidays. For each day, use format daynumber=anything or just daynumber=.
;The file later will be used by IsTodayHoliday.


str inifile.expandpath("$my qm$\nbd.ini")
if(dir(inifile))
,mes- "The file already exists. Overwrite?" "" "OC!"
,mes- "Are you sure?" "" "OC!"
int nyears=10 ;;you can change this; it is number of years not including this year

str ini
DATE d.getclock
SYSTEMTIME st
int y ymax month
rep
,d.tosystemtime(st)
,
,if(st.wYear!=y)
,,y=st.wYear
,,if(!ymax) ymax=y+nyears
,,if(y>ymax) break
,
,if(st.wMonth!=month) month=st.wMonth; ini.formata("[%i-%i][]" y month) ;;write year and month as ini section
,
,sel st.wDayOfWeek
,,case [0,6] ini.formata("%i=%s[]" st.wDay iif(st.wDayOfWeek "sat" "sun")) ;;write sundays and saturdays
,
,;other (or some of other) holidays can be added/removed here instead of editing the ini file. Example:
,sel st.wMonth
,,case 1 sel(st.wDay) case 1 ini.formata("%i=%s[]" st.wDay "New Year")
,,;and so on
,
,d=d+1

;out; out ini
ini.setfile(inifile)
inifile-"''"; inifile+"''"
run "notepad.exe" inifile ;;open for editing


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)