AppleScript名:2月1日が日曜日でうるう年ではないかチェック(ASOC) |
— Created 2015-02-02 by Shane Stanley use AppleScript version "2.4" use scripting additions use framework "Foundation" –use framework "ASObjCExtras" set resYList to {} –hit year set theNSCalendar to current application’s NSCalendar’s currentCalendar() — do *not* use initWithCalendarIdentifier: repeat with y from 2000 to 2100 set aMlen to getMlenAndVerifyFirstDaysNum(y, 2, theNSCalendar, 28, 1) of me if aMlen = true then set the end of resYList to y end if –set the end of resYList to aMlen end repeat return resYList –> {2009, 2015, 2026, 2037, 2043, 2054, 2065, 2071, 2082, 2093, 2099} on getMlenAndVerifyFirstDaysNum(aYear, aMonth, theNSCalendar, dMax, fdayNum) –現在のLocaleのCalendarで指定年月の日数をかぞえる set theDate to theNSCalendar’s dateWithEra:1 |year|:aYear |month|:aMonth |day|:1 hour:0 minute:0 |second|:0 nanosecond:0 set theResult to theNSCalendar’s rangeOfUnit:(current application’s NSDayCalendarUnit) inUnit:(current application’s NSMonthCalendarUnit) forDate:theDate –> {location:1, length:31} set mLen to |length| of theResult –指定年月の1日を取得 set theDay to theNSCalendar’s components:((current application’s NSWeekdayCalendarUnit) + (current application’s NSMonthCalendarUnit as integer)) fromDate:theDate –指定年月の1日の曜日が指定曜日で、うるう月でなく、指定年月の日数が指定日数(dMax)であるか判定 if (theDay’s |weekday|() = fdayNum) and (theDay’s isLeapMonth() is false) and (mLen = dMax) then return true else return false end if end getMlenAndVerifyFirstDaysNum |
(Visited 37 times, 1 visits today)