• 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: Coping with Date format variations
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Coping with Date format variations


  • Subject: Re: Coping with Date format variations
  • From: Robert Poland <email@hidden>
  • Date: Mon, 24 May 2010 21:22:15 -0600


On May 24, 2010, at 6:12 PM, Michelle Steiner wrote:

On May 24, 2010, at 4:59 PM, Robert Poland wrote:

Is there a simple command that will do this (convert WakeUpTime to an integer), and probably quicker?

set WakeUpTime to "6:31"
set AppleScript's text item delimiters to ":"
set WakeUpTime to my decoupe(WakeUpTime) as integer
display dialog WakeUpTime

set AppleScript's text item delimiters to "" -- restore

on decoupe(t) -- t = time
set {h, m} to text items of t
set timeNumber to ((m as integer) + ((h as integer) * 60)) * 60
return timeNumber as integer
end decoupe

Well, you're not really dealing with data-time formats there; it's strictly string manipulation and arithmetic.  You have extraneous "as integer" statements there.

Also, I'd set and restore the text item delimiters within the handler, because that's the only place they're used.  So here's how I would write it:

set WakeUpTime to "6:31"
set WakeUpTime to my decoupe(WakeUpTime)
display dialog WakeUpTime

on decoupe(t) -- t = time
set AppleScript's text item delimiters to ":"
set {h, m} to text items of t
set AppleScript's text item delimiters to "" -- restore
set timeNumber to ((m as integer) + ((h as integer) * 60)) * 60
return timeNumber
end decoupe

-- Michelle

-- 
Life is not a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside, thoroughly used up, totally worn out, and loudly proclaiming, "WOW! What a ride!!!"

As noticed by others the handler is used several times so that's why the text item delimiters were done that way. Funny no one else mentioned the "as integer"s. I removed them with no apparent ill effects.

Thanks all,


Robert Poland - Fort Collins, CO



 _______________________________________________
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

  • Follow-Ups:
    • Re: Coping with Date format variations
      • From: Michelle Steiner <email@hidden>
References: 
 >Re: Coping with Date format variations (From: Shane Stanley <email@hidden>)
 >Re: Coping with Date format variations (From: Luther Fuller <email@hidden>)
 >Re: Coping with Date format variations (From: "Mark J. Reed" <email@hidden>)
 >Re: Coping with Date format variations (From: LuKreme <email@hidden>)
 >Re: Coping with Date format variations (From: "Mark J. Reed" <email@hidden>)
 >Re: Coping with Date format variations (From: Luther Fuller <email@hidden>)
 >Re: Coping with Date format variations (From: Robert Poland <email@hidden>)
 >Re: Coping with Date format variations (From: Michelle Steiner <email@hidden>)

  • Prev by Date: Re: Coping with Date format variations
  • Next by Date: Re: Coping with Date format variations
  • Previous by thread: Re: Coping with Date format variations
  • Next by thread: Re: Coping with Date format variations
  • Index(es):
    • Date
    • Thread