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"
-- "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
*)