I fiddled with JodaTime today and I expected this test to pass:
@Test public void dateTimeShouldRoundTrip() { DateTime originalDateTime = new DateTime(2013, 7, 4, 0, 0); DateTime roundTrip = new DateTime(originalDateTime.toGregorianCalendar()); assertThat(roundTrip, is(originalDateTime)); }
But that fails. I tested it under JodaTime 2.1 and 2.2.
A further check (using SamePropertyValuesAs matches) shows that the failure is caused by the difference in the centuryOfEra property:
originalDateTime.getCenturyOfEra(); // 20 roundTrip.getCenturyOfEra(); // 21
So, why does this property change when everything else - year, month, day, day of the week, time zone, etc. - not? This is mistake? Can't you round DateTime to calendar and back?
java jodatime
Paul phillips
source share