phax / ph-commons

Java 11 Library with tons of utility classes required in all projects
Apache License 2.0
30 stars 18 forks source link

PDTXMLConverter.getXMLCalendarDate get the result maybe incorrect #12

Closed ohralathe closed 6 years ago

ohralathe commented 6 years ago

Firstly, thank you @phax because of your useful library, It saved my time a lot. I see a method in you util method return a value maybe incorrect.

Phenomenon

PDTXMLConverter.getXMLCalendarDate(new Date(2018-10-31)) return 2018-09-31

Steps to reproduce

Date d = new Date("2018-10-31") //2018-10-31
// UBL library
DeliveryType deliveryType = new DeliveryType();
deliveryType.setRequestedDeliveryPeriod(new PeriodType() {{
        setEndDate(PDTXMLConverter.getXMLCalendarDate(d));
}});

it return the value with 2018-09-31

I solved by pass a LocalDate argument instead of Date.

Expected

I think the return of these overload methods should be the same with PDTXMLConverter.getXMLCalendarDate(LocalDate localDate);

phax commented 6 years ago

Thanks for pointing that out. The error was in the conversion from GregorianCalendar to XMLGregorianCalendar for the date only. GregorianCalendar has a month range from 0 to 11 whereas XMLGregorianCalendar has a range from 1 to 12 and I missed this in PDTXMLConverter.getXMLCalendarDate (GregorianCalendar)