Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello,
I'm using the TalendDate.parseDate() to convert the string to date.
When I'm entering the wrong date that doesn't exist TalendDate.parseDate("yyyy-MM-dd", "2023-02-48") I'm getting the result: 2023-03-20
I was pretty sure it should fail on the conversion.
Thanks
Hello @COW_WW BA ,
TalendDate.parseDate() will invoke the java.util.Calendar to parse the date and it won't validate the date.
As a workaround, please use SimpleDateFormat like:
new SimpleDateFormat("yyyy-MM-dd").parse("2023-03-02")
Thanks
Aiming
Hi
You can also use tSchemaCompliancdCheck to validate the date before converting the string to a Date.
Regards
Shong
Should this workaround validate the date? I just tried it and got the same result.
new SimpleDateFormat("yyyy-MM-dd").parse("2023-02-48")
The result is: 2023-03-20
The typicall frameworks ignore such wrong dates and correct them automatically.
This will not help!
You need to switch of the lenient mode which cause the automatically correction.
To do so use: TalendDate.parseDate("yyyy-MM-dd", "2023-03-48", false)
You will get as result an exception like this: java.lang.IllegalArgumentException: DAY_OF_MONTH
You need to switch off the lenient mode which cause the automatically correction.
To do so use: TalendDate.parseDate("yyyy-MM-dd", "2023-03-48", false)
You will get as result an exception like this: java.lang.IllegalArgumentException: DAY_OF_MONTH