Exemplo n.º 1
0
  // -----------------------------------------------------------------------
  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);
  }
Exemplo n.º 2
0
 public void testWithFieldAdded3() {
   DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0);
   try {
     test.withFieldAdded(null, 6);
     fail();
   } catch (IllegalArgumentException ex) {
   }
 }
Exemplo n.º 3
0
  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));
    }
  }
Exemplo n.º 4
0
 public void testWithFieldAdded4() {
   DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0);
   DateTime result = test.withFieldAdded(DurationFieldType.years(), 0);
   assertSame(test, result);
 }