I just started to use Joda Time and for a week now I was satisfied with the results. I am trying to get the time range period between two dates of the format 'yyyy-MM-dd HH'.
Until I came to a test case I am writing and it seems to me the result is wrong:
2014-02-05 05 - 2016-02-04 05
Joda Results:
Years: 1 Months: 11 Days: 2 Hours: 0
Expected Results:
Years: 1 Months: 11 Days: 30 Hours: 0
I only need 1 more day to get it to a FULL 2 years....
I am not a QA but certainly this is a bug to me... I also talked to our QA about this and she agreed.
I want to raise a bug in Github but it pointed me to use Stackoverflow first.. any clarification will be greatly appreciated.
String hourFormat = "yyyy-MM-dd HH";
String startTime = "2014-02-05 05";
String endTime = "2016-02-04 05";
DateTimeFormatter hourFormatter = DateTimeFormat.forPattern(hourFormat);
DateTime start = hourFormatter.parseDateTime(startTime);
DateTime end = hourFormatter.parseDateTime(endTime );
Interval interval = new Interval(start, end);
Period period = interval.toPeriod();
System.out.println(String.format(
"Years: %d Months: %d Days: %d Hours: %d",
period.getYears(), period.getMonths(), period.getDays(), period.getHours()
));