Most of the time, these 2 methods are each others inverse:
Temporal Temporal.plus(long, TemporalUnit)
long Temporal.until(Temporal, TemporalUnit)
For example starting from 1-JAN:
System.out.println("1-JAN plus 1 month: " +
LocalDate.of(2017, 1, 1).plus(1, ChronoUnit.MONTHS));
System.out.println("1-JAN until 1-FEB in months: " +
LocalDate.of(2017, 1, 1).until(LocalDate.of(2017, 2, 1), ChronoUnit.MONTHS));
They are each others inverse:
1-JAN plus 1 month: 2017-02-01
1-JAN until 1-FEB in months: 1 // GOOD
However, in this example starting from 31-JAN:
System.out.println("31-JAN plus 1 month: " +
LocalDate.of(2017, 1, 31).plus(1, ChronoUnit.MONTHS));
System.out.println("31-JAN until 28-FEB in months: " +
LocalDate.of(2017, 1, 31).until(LocalDate.of(2017, 2, 28), ChronoUnit.MONTHS));
They are not each others inverse:
31-JAN plus 1 month: 2017-02-28 // Bad? Should ceil to 1 March?
31-JAN until 28-FEB in months: 0 // Or is this bad? Should be 1?
How can I make them to be each others inverse?
There is only 28 days between those dates so the number of whole months is 0. However you could use a bit of rounding if you want less than 1 month be be considered a month. e.g.
prints
and
prints
You might want to treat all months as notionally 30 days depending on your requirements.