How to validate a string date in Mendix?

1
I'm running into an issue when trying to validate an incoming string date when using parsedatetime.  Using parseDateTimeUTC("32-11-2020”, 'dd-MM-yyyy', empty) does not result into empty but in 02-12-2020. This way I can not validate imported string values containing a date. How do you validate string dates when importing them to a datetime value in Mendix? Do I have to get a java function?   (I now use the “creative” construction getting a substring to catch the "32” and then comparing it with the day part of the resulting DateTime variable ("2") ) => Mendix 8.15.2
asked
6 answers
4

That is either the result of an odd implementation choice or an oversight. It is consistent in adding the days into the next month, even into the next year. It also subtracts days into the previous month, even negative numbers get processed. Some tests on https://mydemoversion8-sandbox.mxapps.io/p/ff/ParseDateTime show these results:

The last example even adds one hour for daylight saving time.

And it takes in big numbers too:

Your “creative” solution is actually very good. As far as I can see it covers all unexpected results.

answered
3

I would consider this a bug. Did some testing. In 8.10 it would give a fault when parsing this string (I did not have 8.9 on my machine). But in later versions it indeed gave this result. I also tested it in Mx7.23.7 and it gave the same result. It seems you found a very peculiar bug here. FIle a bug report to Mendix because this is not correct in my opinion.

Regards,

Ronald

 

answered
2

(The issue is still open at support, I just asked for an update on the topic.)

answered
2

(The issue is still open at support, I just asked for an update on the topic.)

answered
1

last update today: 

This behavior corresponds to the lenient parsing behavior for SimpleDateFormat:
 DateFormat (Java SE 11 & JDK 11) (oracle.com)
 For now, this is not considered a bug in the system and there is no plan to change this behavior.

 

I'm still in the request to get the functioning of the third parameter in scope of this insight.

 

answered
0

I think the easiest way to validate is to take these steps:

 

  1. Convert your string date to a date
  2. check if it doesn't error with error handling
  3. convert your date back into a string, in the same format as your original string date
  4. Compare the two
  5. If not the same, date input is not valid
answered