Pessoal estou com uma dúvida se alguém com mais fluência em JodaTime ajudasse ficaria agradecido.
Com o seguinte trecho de código:
public static void main(String[] args) throws Exception {
System.out.println(dateDiffJoda("01/31/2009", "02/28/2009"));
System.out.println(dateDiffJoda("01/30/2009", "02/28/2009"));
System.out.println(dateDiffJoda("01/29/2009", "02/28/2009"));
System.out.println(dateDiffJoda("01/28/2009", "02/28/2009"));
System.out.println(dateDiffJoda("01/27/2009", "02/28/2009"));
}
public static String dateDiffJoda(String start, String end) throws Exception {
int startYear = Integer.parseInt(start.substring(6));
int endYear = Integer.parseInt(end.substring(6));
int startMonth = Integer.parseInt(start.substring(0, 2));
int endMonth = Integer.parseInt(end.substring(0, 2));
int startDay = Integer.parseInt(start.substring(3, 5));
int endDay = Integer.parseInt(end.substring(3, 5));
DateTime startTime = new DateTime(startYear, startMonth, startDay, 0, 0, 0, 0);
DateTime endTime = new DateTime(endYear, endMonth, endDay, 0, 0, 0, 0);
endTime = endTime.plusDays(1);
Period period = new Period(startTime.getMillis(), endTime.getMillis(), PeriodType.yearMonthDay());
return PeriodFormat.getDefault().print(period);
}
Obtenho a seguinte saída:
1 month and 1 day
1 month and 1 day
1 month and 1 day
1 month and 1 day
1 month and 2 days
A pergunta é : Como e porque o JodaTime considera 1 mês para as seguintes diferenças de datas ?
01/31/2009 e 02/28/2009
01/30/2009 e 02/28/2009
01/29/2009 e 02/28/2009
01/28/2009 e 02/28/2009
Qualquer ajuda é bem vinda , obrigado.