weird date "string" glitch

Can anyone tell me why applescript seems to convert some strings to dates
for no apparent reason?

I want to try to convert a string to a date and if it fails do something
else, as in:

Try
Set d to date "string"
On error
Set d to "cannot make a date out of the string"
End try

But I’m finding that some strings just turn into a random date:


-- "Steve's with the apostrophe"
--set d to date "Security Now! Episode 16: Your Questions, Steve's Answers"

set d to date "Thursday, September 1, 2005 4:00:00 PM"

--- "Steves" without the apostrophe
--set d to date "Security Now! Episode 16: Your Questions, Steves Answers"

set d to date "Friday, December 2, 2005 4:00:00 PM"

-- this gets the expected result when attempting to compile:
-- (Invalid date and time Security Now.)

--set d to date "Security Now"


Can anyone tell me what’s going on with that?

-- "Steve's with the apostrophe"
set the_string to "Security Now! Episode 16: Your Questions, Steve's Answers"
set d to date the_string
-->date "Thursday, September 1, 2005 4:00:00 PM"
(*
you get September because the 's is interpreted as just "s" which AS coerces to September
since no day is there, it defaults to the first day of the month;
16 is coerced to the 16th hour of the day, 4:00 PM
*)

--- "Steves" without the apostrophe
set the_string to "Security Now! Episode 16: Your Questions, Steves Answers"
set d to date the_string
-->date "Friday, December 2, 2005 4:00:00 PM"
(*
you get December 2 because there is nothing that AS can coerce to a month or day
so it defaults to the current date;
again, 16 is coerced to the 16th hour of the day, 4:00 PM
*)

set the_string to "Security Now"
set d to date the_string
--> error: "Invalid date and time Security Now."
(*
you get an error because there is nothing to be coerced to a date or time
*)

See this thread for more information.

Jon

thanks john, you’re the archive master! but as I said in that thread, the implications of that are nuts. what was apple thinking?