JodaTime account for non whole-months and days
As I understand it JodaTime's
Period() calculates whole months and days leaving some reminders out of the calculation.
So if we have an
startDate = "2017/01/01T00:00:00" and an
endDate = "2017/17/06T12:00:00", we'll get
5 months and
16 days because the 6th month hasn't completed yet and the 17th day either. Working as advertised but the user doesn't expect to see that.
What i need is to obtain
17 days respectively.
I've tried with Java's
Calendar but it sucks and with Joda's
Days() but they return the same results. I've tried to understand under which conditions those reminders exists in order to add them up but I failed and the countless SO threads about the issue fail to explain where those reminders go or if they're recoverable.
Current code is:
Calendar calendarThen = Calendar.getInstance(); LocalDateTime dateNow = LocalDateTime.now(); calendarThen.setTimeInMillis(milis); // old date in milliseconds LocalDateTime dateThen = LocalDateTime.fromCalendarFields(calendarThen); PeriodType monthDay = PeriodType.yearMonthDayTime(); Period period = new Period(dateThen, dateNow, monthDay); years= period.getYears(); months = period.getMonths(); days = period.getDays(); hours = period.getHours(); minutes = period.getMinutes(); seconds = period.getSeconds();
Is there an easy way to calculate and add the reminder non-whole months and days? or even does JodaTime has a class that account for those reminders?