• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Getting human-understandable time from iCal
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Getting human-understandable time from iCal
      • From: Martin Orpen <email@hidden>
  • Prev by Date: Re: AppleScript causing FMP XML output error?
  • Next by Date: Create record in FileMaker
  • Previous by thread: Re: Getting human-understandable time from iCal
  • Next by thread: Re: Getting human-understandable time from iCal
  • Index(es):
    • Date
    • Thread