I am using Joda-Time and I would like to check if a specific date is not the last day of a year (in other words the date should not be 31/12/XXXX). It should work for any year.
To implement this check I have done something like this:
DateTime dataSecondoMovimento = new DateTime(mappaQuote.get(2).getDatariferimentoprezzo());
if(!(dataSecondoMovimento.getMonthOfYear() == 12 && dataSecondoMovimento.getDayOfMonth() == 31)) {
System.out.println("It is not the end of year !!!");
}
So basically I am checking if the month is not December and if the day is not 31 (both have to be true for it not to be the last day of year). I think that this should work fine.
My question: does Joda-Time provide a neater way of doing this? Does there exist a method of checking if a specific date is the last day of the year?
IMHO, your way is quite practical.
The only thing comes to my mind is
dataSecondoMovimento.plusDays(1).getDayOfYear() == 1
which is shorter but hardly more effective
P.S.: I've found a small benefit in this approach -- it will work for slightly improbable situation with non-Gregorian calendar which doesn't have 12 months or 31 days in the last one!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With