8
I was messing around 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 it fails. I checked it under both JodaTime 2.1 and 2.2.
Further inspection (using the SamePropertyValuesAs matcher) shows that the failure is caused by a 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 week, timezone, etc. - does not? Is this a bug? Shouldn't you be able to roundtrip a DateTime to a Calendar and back again?