Re: Getting the date of the next or current recurrence of an iCal/Calendar event
Re: Getting the date of the next or current recurrence of an iCal/Calendar event
- Subject: Re: Getting the date of the next or current recurrence of an iCal/Calendar event
- From: Nigel Garvey <email@hidden>
- Date: Wed, 30 Mar 2016 20:39:52 +0100
Shane Stanley wrote on Wed, 30 Mar 2016 11:07:54 +1100:
>On 30 Mar 2016, at 6:32 AM, Nigel Garvey
><email@hidden> wrote:
>>
>> -- The original used NSDate's |date|() and NSCalendar()'s
>>startOfDayForDate:, but this is faster and more legible.
>> tell (current date) to set startASDate to it - (its time)
>> tell current application's NSDate
>> set startNSDate to (its dateWithTimeInterval:0
sinceDate:startASDate)
>> set endNSDate to (its dateWithTimeInterval:0
sinceDate:(startASDate
>>+ (days - 1)))
>> end tell
>
>The problem, though, is that this version still relies on bridging of
>AppleScript dates and NSDates, which was only introduced in 10.11. You
>can't pass an AppleScript date to an NSDate method in 10.9 or 10.10.
Bummer. :( And it turns out too that my AS date version is only faster
on my machine when there are two BOINC tasks running in the background.
With one task or none, your original's faster. :\ But I wasn't after
speed in this instance, just readability.
The original used NSDate's dateWithTimeInterval:sinceDate: to set an end
time 23:59:59 after the start time — a fixed interval. This could
potentially lead to incorrect results on days when the clocks change and
those particular calendar days are either shorter or longer. So setting
the end time directly is still probably better:
-- Create start date and end date (start of day and end of day) for today's occurrences.
tell current application
set now to its NSDate's |date|()
tell its NSCalendar's currentCalendar()
set startNSDate to its startOfDayForDate:now
set endNSDate to its dateBySettingHour:23 minute:59 |second|:59 ofDate:now options:0
end tell
end tell
While researching this, I was amused to see 'NSTimeIntervalSince1970'
described as a "constant" in the NSDate documentation. :)
NG
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden