Shane et al,
So here's my simple, but more verbose than I'd like, error trapping for an ISO date/time string that includes time zone data (remember I allow only local time zone):
TZD = time zone designator (Z or +hh:mm or -hh:mm)
Even though the spec indicates the TZD is to be used ONLY when time is included, I'm checking for it in anything AFTER the date. So, my validation should trap:
"2017-03-05-05:00"
"2017-03-05Z"
"2017-03-05T13:01:02-05:00"
"2017-03-05T13:01:02+05:00"
"2017-03-05T13:01:02Z"
if (length of
pDateStr > 10) then
set
endISO to (text 11 thru -1 of
pDateStr)
if ((length of
pDateStr) > 19 ¬
or (offset
of "Z"
in endISO) > 0 ¬
or (offset
of "+"
in endISO) > 0 ¬
or (offset
of "-"
in endISO) > 0) then
error "Time Zone codes NOT allowed"
number 1001
end if
end if
on error
errMsg number
errNum
if
errNum = 1001 then
set
errMsgAddl to return &
errMsg
else
set
errMsgAddl to ""
end if
error "[ERROR]" &
return &
"INVALID Date Format: " & pDateStr &
errMsgAddl
If anyone can improve on my code, it will be welcomed.
One thing, I'm avoiding use of RegEx just because I don't want to require Satimage.osax, or use the more complicated ASObjC. (but maybe there's a simple way . . .)
Jim Underwood
aka JMichaelTX