Michael Tesař Michael Tesař - 4 months ago 29
AppleScript Question

Get last day in month in AppleScript and holidays in current month

I am writing an AppleScript which generates an MS Excel spreadsheet every month. I need to know how many days are in the current month, then go trough all months and decide if a given day is a weekday or a 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 the last day in a month?

  2. How do I efficiently loop trough all days in the current month and decide if it is Sunday, Saturday or a day specified somewhere else (for example, in a text file of xlsx spreadsheet)?


The script below 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