I am using Joda-Time to handle dates within an application and found myself perplexed.
I need to produce a date using two strings (one for the date, one for the hour of the day).
I have secured the time of day through the use of a RegEx but there are still some dates that go through my RegEx (something like 30th of february for example).
I thought about using the following DateTime construction within a try block (once the substrings are parsed)
DateTime(
int year,
int monthOfYear,
int dayOfMonth,
int hourOfDay,
int minuteOfHour
)
and then throw my function’s Exception in the catch block, but according to the api doc, this constructor doesn’t throw the IllegalArgumentException exception I expected to catch, like some others do.
Anyone has any pointer to tell if the MoY/DoM couple form a valid one so as to be able to throw an exception ?
Although it’s not documented, it will throw
org.joda.time.IllegalFieldValueException(a subclass ofIllegalArgumentException) if the value is invalid. Sample code:Result:
Obviously it would be nice if this were documented…