在AppleScript中获取月份的最后一天以及当月的假期

我正在写一个AppleScript,它每个月都会生成一个MS Excel电子表格。 我需要知道当月有多less天,然后每个月都要低谷,决定某一天是平日还是假期。

我想我会节省假期(从这个网站http://kalendar365.cz/statni-svatky/2016作为表,并在本地访问)为此。

我的问题是:

  1. 我如何获得一个月的最后一天?
  2. 如何有效循环当月的所有date,并决定是星期日,星期六还是指定其他地方的date(例如,在xlsx电子表格的文本文件中)?

pbell的答案是有希望的,但GetLastDay函数不能正常工作几个月的时间less于31天; 这里有一个函数可以解决这个问题:

 # Returns the number of days in the month that the given date falls in. # Example: # my GetNumberOfDaysInMonth(current date) on GetNumberOfDaysInMonth(aDate) local aDateCopy copy aDate to aDateCopy set day of aDateCopy to 1 if month of aDateCopy is December then set year of aDateCopy to ((year of aDateCopy) + 1) set month of aDateCopy to 1 else set month of aDateCopy to ((month of aDateCopy) + 1) end if return day of (aDateCopy - 1 * days) end GetNumberOfDaysInMonth 

这个方法的基础是将月份设置为月份的第一个月,然后递增月份(可能会延续到下一年),然后减去1天,即使在闰年,这一天也可以正常运行。

下面的脚本包含你正在寻找的2个例程:GetlastDay和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