Reputation: 604
I want to find the month is equal or after the current YearMonth
final YearMonth yearMonth = YearMonth.of(2020, 8);
final boolean after = yearMonth.isAfter(YearMonth.now());
Here current month is August(8) and I tried isAfter which returns false.
I want to return true for current month also.
Is any method is there in YearMonth itself?
Upvotes: 2
Views: 1009
Reputation: 1
return yearMonth.getMonth().getValue()>= YearMonth.now().getMonth().getValue();
Upvotes: -1
Reputation:
You can just use the negation of the isBefore
method:
final boolean equalOrAfter = !yearMonth.isBefore(YearMonth.now());
After all a YearMonth can either be before, after or equal to another YearMonth, so if a YearMonth is not before another YearMonth it has to be either equal to or after it.
Upvotes: 8