我正在编写AppleScript,每月生成一个MS Excel电子表格。我需要知道当月有多少天,然后通过所有月份来决定某一天是工作日还是假日。
我想我会保存假期(从这个网络http://kalendar365.cz/statni-svatky/2016作为表格并在本地访问它们)。
我的问题是:
答案 0 :(得分:0)
pbell's answer很有希望,但GetLastDay
功能在少于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天,然后递增月份(可能会滚动到下一年),并减去1天,即使在闰年中也能正确处理所有日期。< / p>
答案 1 :(得分:-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