• 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 14:18:14 +0100

Martin Orpen wrote on Wed, 29 Sep 2004 10:10:05 +0100:

>on 29/9/04 3:48 am, Nigel Garvey at email@hidden
>wrote:
>
>> Vanilla AppleScript can:
>
>Damn, you always seem to have these great routines to hand, especially with
>maths stuff... :-)

Not quite to hand. It kept me up till nearly 4:00 this morning. :-)

>[snip script]
>
>It does it fast too, but it doesn't do it accurately enough:
>
>-->    date "Friday, February 28, 2003 11:30:00 am"
>-->    date "Tuesday, April 1, 2003 11:30:00 am"
>-->    "0 yr 1 mth 4 dy 0 hr 0 min 0 sec"

That is actually right by the logic I was using. One calendar month on
from February 28, 2003 is March 28, 2003. From there, it's another four
days to April 1. However, my script did have a few flaws, so here's a
safer version:

  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, d, t} to {(later's year) - (earlier's year), (later's day) -
(earlier's day), (later's time) - (earlier's time)}
    copy {later, earlier} to {b, c}
    set {b's month, c's month} to {January, January}
    set m to (b - 2500000 - later) div -2500000 - (c - 2500000 - earlier)
div -2500000

    if t < 0 then set {d, t} to {d - 1, t + days} -- borrow a day
    if d < 0 then set {m, d} to {m - 1, d + ((later - (later's day) *
days)'s day)} -- borrow the month before 'later'
    if m < 0 then set {y, m} to {y - 1, m + 12} -- borrow a year

    set {h, min, s} to {t div hours, t mod hours div minutes, t mod
minutes}

    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"


NG
 _______________________________________________
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

  • Prev by Date: ftp transfer
  • Next by Date: Re: GUI screen capture?
  • Previous by thread: Re: Getting human-understandable time from iCal
  • Next by thread: How to parse a textfile ?
  • Index(es):
    • Date
    • Thread