...so I went ahead and did that:
--------------------------------------------------------------------------------
property ordinals : {"st", "nd", "rd", "th"}
property text item delimiters : {space} & ordinals
property daysOfTheWeek : {¬
"Sunday", "Monday", "Tuesday", "Wednesday", ¬
"Thursday", "Friday", "Saturday"} as text
property monthsOfTheYear : {¬
"January", "February", "March", "April", ¬
"May", "June", "July", "August", "September", ¬
"October", "November", "December"} as text
--------------------------------------------------------------------------------
global ASbaseDate
set ASbaseDate to {}
--------------------------------------------------------------------------------
set input to ["Monday, June 04 2018", "4 June 2018", "4 Jun 2018", "4 Jun 18", ¬
"4/6/18", "6/4/18", "Sunday, 4 June 2018", "4th June 2018", "2018-06-04", ¬
"Jun 4, 2018", "March 15 2018", "15 March 2018", "15 Mar 2018", ¬
"15 Mar 18", "15/3/18", "3/15/18", "Sunday, 15 March 2018", ¬
"15th March 2018", "2018-03-15", "Mar 15, 2018"]
parse(some item of the input)
ASbaseDate
--------------------------------------------------------------------------------
###HANDLERS
#
#
to parse(input as text)
local input
if the input is "" then
if ASbaseDate's middle item > 12 then swap(ASbaseDate, 1, 2)
set [d, m, y] to ASbaseDate
tell (current date) to set ¬
[ASbaseDate, year, its month, day, time] to ¬
[it, y, m, d, 0 * hours + 0 * minutes + 0]
return
end if
script ds
property x0 : first text item of input's first word
property xN : rest of input's words as text
property |?1| : x0 is not in daysOfTheWeek & monthsOfTheYear
to getMonth(m)
script mw
property m0 : m's first item
property mN : rest of m
property |?2| : x0 is in m0
end script
tell mw
if its |?2| is true then return 13 - (m's length)
getMonth(its mN)
end tell
end getMonth
end script
tell ds
if its |?1| is true then -- numerals
tell (its x0 as integer)
if ds's xN = "" and my sum(ASbaseDate) < 1000 then
if it < 1000 then
set end of ASbaseDate to it + 2000
else
set end of ASbaseDate to it
end if
else
set beginning of ASbaseDate to it
end if
end tell
else -- words
if its x0 is in monthsOfTheYear then
its getMonth(monthsOfTheYear's words)
set end of ASbaseDate to the result
end if
end if
parse(its xN)
end tell
end parse
to swap(L as list, i as integer, j as integer)
local L, i, j
set x to item i of L
set item i of L to item j of L
set item j of L to x
end swap
to sum(L as list)
local L
if L = {} then return 0
script Array
property x0 : L's first item
property xN : rest of L
property fn : sum(xN)
end script
tell the Array to return (its x0) + (its fn)
end sum
---------------------------------------------------------------------------❮END❯
I've only done limited case testing, using the input values I've included in the script. It's worth noting that, whilst the dates written as 15/3/18
and 3/15/18
are unequivocally both representations of the Ides of March, the dates written as 4/6/18
and 6/4/18
are ambiguous. Currently, the script defaults to the US-standard, returning dates 6 April 2018
and 4 June 2018
respectively. But, ideally, it's best to advise the user to avoid this format as input, and elect for one of the other myriad date representations.