As all values in text item delimiters are considered since Snow Leopard, this is an alternative
set currentDate to current date
set isotDateString to currentDate as «class isot» as string
set {TID, text item delimiters} to {text item delimiters, {":", "-"}}
set isotItems to text items of isotDateString
set text item delimiters to ""
set trimmedIsotDateString to isotItems as text
set text item delimiters to TID
set currentDate to current date
set isotDateString to currentDate as «class isot» as string
set {TID, text item delimiters} to {text item delimiters, {":", "T", "-"}}
set isotItems to text items of isotDateString
set text item delimiters to TID
All versions look great. I didn’t think about doing it DJ Bazzie Wazzie’s way.
It makes me want to bring out the timer! Looks like a battle between concatenation with range reference form vs. AS text item delimiters with coercion vs. date properties with concatenation. I can’t decide which way to bet on. I’d bet that Nigel timed his version.
Edited: I forgot that Yvan said that about the time. The shell call has too much overhead for just a few dates, but for many dates I don’t know also.
I timed also the Nigel’s version and got the same results than Nigel.
This is why I replaced the shell script by Nigel’s vesion in the handler which is embedded in my library.
Yvan KOENIG (VALLAURIS, France) mercredi 16 octobre 2013 20:41:17
I think I know what that means. It’s mainly about the communication. They’re just saying that it’s ok to use either way, with or without the T. Why do they have to make things so complicated?
I think mutual agreement in the sense here, is that two parties can agree upon a specific protocol amongst themselves. Not a general usage between all users of the general scheme.
The first time I saw it I thought: what a mess, such an awful instruction will be a snail.
Then I saw the timing posted by Nigel and had difficulties to trut it so I mage my own test running the two scheme in a 10,000 iterations lup and I was forced to recognize that it’s extraordinary fast.
So, I typed a # in front of the shell instruction and inserted the “awful code”.
For some usages ” mainly file naming ” I drop the “T” which brings no useful information.
It’s one of the gems which I use daily.
Yvan KOENIG (VALLAURIS, France) jeudi 17 octobre 2013 20:42:24
Mine is not fair, if anyone wants to time it, because it will be cached (i think it has to be). I can do a million repeats still in a blink of an eye. On the other hand, considering the programming language where AppleScript is developed in, it doesn’t amaze me that my version is the fastest solution. But still, AppleScript is always against all odds.
So much stuff is cached these days, in varying places, that a lot of the timing tests done by repeating X times and dividing by X produce misleading results, IMO.