Re: Getting human-understandable time from iCal
Re: Getting human-understandable time from iCal
- Subject: Re: Getting human-understandable time from iCal
- From: Nigel Garvey <email@hidden>
- Date: Wed, 29 Sep 2004 03:48:04 +0100
Martin Orpen wrote on Tue, 28 Sep 2004 13:02:25 +0100:
>I'd like to be able to get the time between events in iCal in a more
>"readable" format.
>
>I can easily get seconds between events:
>
>tell application "iCal"
> set t1 to start date of first event of calendar 9 whose summary is
>"xx01"
> set t2 to start date of first event of calendar 9 whose summary is
>"xx02"
> set t3 to t2 - t1
>end tell
>
>Can iCal be scripted to return years/months/days/hours/minutes/seconds?
Vanilla AppleScript can:
on calendarInterval(later, earlier)
if earlier comes after later then
set {later, earlier} to {earlier, later}
set sign to "-"
else
set sign to ""
end if
set y to (later's year) - (earlier's year)
copy later to b
set b's month to earlier's month
set m to (b - 2500000 - later) div -2500000 - 1
set d to (later's day) - (earlier's day)
set t to (later's time) - (earlier's time)
if t < 0 then set {d, t} to {d - 1, days + t}
set {h, min, s} to {t div hours, t mod hours div minutes, t mod
minutes}
if d < 0 then set {m, d} to {m - 1, d + (day of (later - (later's
day) * days))}
if m < 0 then set {y, m} to {y - 1, m + 12}
return sign & y & " yr " & m & " mth " & d & " dy " & h & " hr " &
min & " min " & s & " sec"
end calendarInterval
set now to date "Friday, 4 June 2004 00:12:30"
set backThen to date "Saturday, 5 June 1999 00:12:31"
calendarInterval(now, backThen)
--> "4 yr 11 mth 29 dy 23 hr 59 min 59 sec"
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden