Skip to main content
Announcements
Accelerate Your Success: Fuel your data and AI journey with the right services, delivered by our experts. Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
COW_WW
Contributor
Contributor

Doesn't TalendDate.parseDate() validate the date?

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

Labels (2)
7 Replies
Anonymous
Not applicable

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

Anonymous
Not applicable

Hi

You can also use tSchemaCompliancdCheck to validate the date before converting the string to a Date.

 

Regards

Shong

COW_WW
Contributor
Contributor
Author

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

jlolling_kloeckner
Contributor
Contributor

The typicall frameworks ignore such wrong dates and correct them automatically.

jlolling_kloeckner
Contributor
Contributor

This will not help!

jlolling_kloeckner
Contributor
Contributor

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

 

jlolling_kloeckner
Contributor
Contributor

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