Problem with pub.date:dateTimeFormat

Hello,

We have tried to use the service pub.date:dateTimeFormat to validate an input date.

When the date is null or is a formal string (ex : 'is_not_a_date) or doesn’t respect the current pattern, the service generates an exception.

But, if the string respects the current pattern but is not a “calendar” date (ex : 2007-14-06 16:27:32), these date is accepted by the service and transformed in a “valid” date : 2008-02-06 16:27:32 - if the newpattern is the same).

We are amazed by that fact :confused: .

(I’m not a java expert :blush: )

Thanx in advance for your response.

Christophe

This is a known behavior of the Java classes that manipulate date strings.

A common way to detect this sort of issue in Java is to convert the first string to a Date object. Then convert that to a result string with the same format as the first string.

Compare the first and result string. If they are not the same, the first string had “bad” components.

The way to do this with pub.date:dateTimeFormat is to simply compare the input and output date strings. If they are not the same, then the input date is invalid. The downside is that you can’t tell which part of the string is bad, but that can be a chore for the caller. :slight_smile:

Thank you Reamon for your answer.

I have had already implemented this workaround. It works perfectly (for my need ;-).
We will have a “java” approach for the next uses of Built-in services in the future.

Christophe