Michael Tesař Michael Tesař - 1 year ago 107
AppleScript Question

Get last day in month in AppleScript and hollidays in current moth

I am writing an AppleScript which generates me an attendance MS Excel spreadsheet every month. I need to know how many days are current month, then go trought all month and decide if this days is or it is not a weekdays or holiday.

I suppose I would save holidays (from this web http://kalendar365.cz/statni-svatky/2016 as table and access them locally) for this.

My question is:

  1. How do I get last day in month

  2. How to effitiently loop trough all days in current month and decide if it is sunday, saturday of day specified somewhere else (for example text file of xlsx spreadsheet)

Thank you very much for you time!

-- Michael

Answer Source

The script bellow contains the 2 routines you're looking for : GetlastDay and isWorkingDay :

set myDate to current date -- just for example !

set N to GetlastDay(myDate)
log N --> number of days in month of myDate
set A to IsWorkingday(myDate)
log A --> true if Monday to Friday, false if Saturday/Sunday

on GetlastDay(LDate) -- return last day of month of LDate
copy LDate to L -- to not change LDate
set L's day to 32 -- = first day of next month
set L to L - (1 * days) -- last day of month
return day of L
end GetlastDay

on IsWorkingday(LDate) -- true if date is not Saturday or Sunday
set SD to weekday of LDate
return (SD is not in {"Saturday", "Sunday"})
end IsWorkingday
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download