On 15 Jan 2017, at 1:43 am, Deivy Petrescu <email@hidden> wrote:
return ((((month of (current date)) - 1) div 3 + 1) as string) & " Q”
Except that returns the value for your own time zone. I think Chris's offering, judging by the links, was about getting the value based on a different time zone.
(As it happens, there is an NSCalendarUnitQuarter enum, but the docs say not to use it because it's unimplemented.)
Anyway, here's a slight variation on Chris's method -- one that makes it easier to get other components, and works around some enum quirks:
use framework "Foundation" use scripting additions
set currentCalendar to current application's NSCalendar's currentCalendar() set theTimeZone to current application's NSTimeZone's timeZoneWithName:"US/Central" set theComponents to currentCalendar's componentsInTimeZone:theTimeZone fromDate:(current application's NSDate's |date|()) set currentMonth to theComponents's |month|() -- or |year|(), |day|(), |hour|(), |minute|(), |second|(), nanosecond(), weekdayOrdinal(), weekOfMonth(), weekOfYear(), yearForWeekOfYear(), leapMonth()
And if you want to be locale aware as well, you could use something like this:
set currentCalendar to current application's NSCalendar's currentCalendar() currentCalendar's setLocale:(current application's NSLocale's localeWithLocaleIdentifier:"ja_JP") set theTimeZone to current application's NSTimeZone's timeZoneWithName:"Japan/Tokyo" set theComponents to currentCalendar's componentsInTimeZone:theTimeZone fromDate:(current application's NSDate's |date|()) set currentMonth to theComponents's |month|() set currentQuarter to (item ((currentMonth - 1) div 3 + 1) of currentCalendar's standaloneQuarterSymbols()) as text -- or: set currentQuarter to (item ((currentMonth + 2) div 3) of currentCalendar's standaloneQuarterSymbols()) as text --> "第1四半期"
|