Wonkiness in todate() and how to validate incoming dates

I am getting some strange values from todate().

{
  todate("02/28/2025"),
  todate("02/29/2025"),
  todate("02/30/2025"),
  todate("02/31/2025"),
  todate("02/32/2025"),
  todate("06/31/2025"),
  todate("RR/28/B025")
}

It seems to try to auto-correct an invalid date to a valid date.  But it also seems to allow characters in the date which it evaluates somehow and comes up with wild dates as a result.

First Question:  What's going on with todate() that it results in off-the-wall values?

My scenarion is this.... I have a webApi that receives a json string which contains structured data that includes multiple date fields.  The webApi uses cast/fromjson to convert the json input string directly to a CDT that uses Date fields.  The CDT is passed to our expression rules that operate on the data.

For example...

CDT  (SH_Test)

Expression rule (faking the WebApi)

a!localVariables(
  local!inputString: "{ ""name"": ""Bob Smith"", ""birthDate"": ""GG/28/2025"", ""favoriteColor"": ""red-orange""}",
  local!cdt: cast('type!{urn:com:appian:types:SH}SH_Test', a!fromJson(local!inputString)),
  local!cdt
)

Output

So the first time my expression rule can analyze the value, it is already a wonky date.

In theory, I could maybe separate the fromJson and the cast to insert some sort of date validation on the intermediary dictionary created by fromJson.  That would be ugly and cumbersome given the number of dates I have but doable (i'll just have to ask for a raise).

But, how can the date string be properly validated?  Is there anything built-in that will check a string for a valid date?  One that will complain for "02/29/2025" (not a leap year) or "GG/28/2025" (text month)?

Thanks.

  Discussion posts and replies are publicly visible