Re: Getting time components of date
Re: Getting time components of date
- Subject: Re: Getting time components of date
- From: Nigel Garvey <email@hidden>
- Date: Wed, 24 Dec 2003 10:25:29 +0000
Graff wrote on Tue, 23 Dec 2003 04:51:49 -0500:
>
I have no doubt that Arthur's script is quick but sometimes you need to
>
balance speed verses complexity. The best balance of speed and
>
complexity is probably the command-line tool "date" even though it is
>
0.0076 seconds slower than Arthur's code.
It can also only handle the current system date and can only be used in
Mac OS X. Arthur's code, besides being faster, can handle any date thrown
at it and works on any system since the invention of AppleScript. The
balance is actually script performance versus the scripter's personal
convenience. (I'm not, of course, suggesting that any particular method
*must* be used. I'm just trying to clarify the logic.)
>
I mean, to use the date tool
>
you need 1 line of code as opposed to 123 for Arthur's code, even with
>
the comments and extra blank lines taken out of it!
You don't need to type them out every time. AppleScript allows for the
loading of libraries. With Arthur's handler in a library, you only need
one line to use it too.
>
Anyways, if this function really needs to be any faster than 0.01
>
seconds then AppleScript is the wrong tool to be using for this
>
purpose.
If you're writing an AppleScript in which the need for a date and time
string arises, then AppleScript's the tool you're using. The greater
speed and flexibility of its vanilla solutions is a bonus. :-)
I can't get your "won't get faster than this" process to work. Terminal
complains: "cc: Command not found." when I try to compile the text file.
But here's a fast, similarly hard-wired AppleScript equivalent. It has
fewer lines than your code, takes less time to set up, and is about ten
times as fast (on my machine) as a shell-scripted Unix date command:
set now to (current date)
set {year:y, day:d, time:t} to now
copy now to b
set b's month to January
tell (y * 10000 + (b - 2500000 - now) div -2500000 * 100 + d) as
Unicode text
set shortDate to text 1 thru 4 & "-" & text 5 thru 6 & "-" & text 7
thru 8
end tell
tell (1000000 + t div hours * 10000 + t mod hours div minutes * 100 + t
mod minutes) as Unicode text
return shortDate & " " & text 2 thru 3 & ":" & text 4 thru 5 & ":" &
text 6 thru 7
end tell
NG
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.