// ----------------------------------------------------------------------- public void testWithFieldAdded1() { DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); DateTime result = test.withFieldAdded(DurationFieldType.years(), 6); assertEquals(new DateTime(2004, 6, 9, 0, 0, 0, 0), test); assertEquals(new DateTime(2010, 6, 9, 0, 0, 0, 0), result); }
public void testWithFieldAdded3() { DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); try { test.withFieldAdded(null, 6); fail(); } catch (IllegalArgumentException ex) { } }
private void testAdd(Date start, DurationFieldType type, int amt, Date end) { DateTime dtStart = new DateTime(start, ISOChronology.getInstanceUTC()); DateTime dtEnd = new DateTime(end, ISOChronology.getInstanceUTC()); assertEquals(dtEnd, dtStart.withFieldAdded(type, amt)); assertEquals(dtStart, dtEnd.withFieldAdded(type, -amt)); DurationField field = type.getField(ISOChronology.getInstanceUTC()); int diff = field.getDifference(dtEnd.getMillis(), dtStart.getMillis()); assertEquals(amt, diff); if (type == DurationFieldType.years() || type == DurationFieldType.months() || type == DurationFieldType.days()) { LocalDate ymdStart = new LocalDate(start, ISOChronology.getInstanceUTC()); LocalDate ymdEnd = new LocalDate(end, ISOChronology.getInstanceUTC()); assertEquals(ymdEnd, ymdStart.withFieldAdded(type, amt)); assertEquals(ymdStart, ymdEnd.withFieldAdded(type, -amt)); } }
public void testWithFieldAdded4() { DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); DateTime result = test.withFieldAdded(DurationFieldType.years(), 0); assertSame(test, result); }