Archive for the 'NSDateComponents' Category

2016/02/10 ISO8601ちっくな週カウント




– Created 2016-02-10 by Takaaki Naganoya
– 2016 Piyomaru Software
use AppleScript version “2.4″
use scripting additions
use framework “Foundation”

set aNSDate to makeNSDate(2016, 1, 1) of me
set aCal to current application’s NSCalendar’s currentCalendar()
aCal’s setMinimumDaysInFirstWeek:1
set aWN to (aCal’s components:(current application’s NSWeekCalendarUnit) fromDate:aNSDate)’s week()

aCal’s setMinimumDaysInFirstWeek:4 –ISO8601 Week Count
set bWN to (aCal’s components:(current application’s NSWeekCalendarUnit) fromDate:aNSDate)’s week()

return {aWN, bWN}
–>  {1, 52}

on makeNSDate(aYear as integer, aMonth as integer, aDay as integer)
  set aComp to current application’s NSDateComponents’s alloc()’s init()
aComp’s setDay:aDay
aComp’s setMonth:aMonth
aComp’s setYear:aYear
set aGrego to current application’s NSCalendar’s calendarWithIdentifier:(current application’s NSGregorianCalendar)
set aDate to aGrego’s dateFromComponents:aComp
return aDate
end makeNSDate

★Click Here to Open This Script