Esempio n. 1
0
 public void testPartialDayOfYearAdd() {
   Partial start =
       new Partial().with(DateTimeFieldType.year(), 2000).with(DateTimeFieldType.dayOfYear(), 366);
   Partial end =
       new Partial().with(DateTimeFieldType.year(), 2004).with(DateTimeFieldType.dayOfYear(), 366);
   assertEquals(end, start.withFieldAdded(DurationFieldType.days(), 365 + 365 + 365 + 366));
   assertEquals(start, end.withFieldAdded(DurationFieldType.days(), -(365 + 365 + 365 + 366)));
 }
Esempio n. 2
0
 /** Private method called from constructor. */
 private void setPeriodInternal(
     int years, int months, int weeks, int days, int hours, int minutes, int seconds, int millis) {
   int[] newValues = new int[size()];
   checkAndUpdate(DurationFieldType.years(), newValues, years);
   checkAndUpdate(DurationFieldType.months(), newValues, months);
   checkAndUpdate(DurationFieldType.weeks(), newValues, weeks);
   checkAndUpdate(DurationFieldType.days(), newValues, days);
   checkAndUpdate(DurationFieldType.hours(), newValues, hours);
   checkAndUpdate(DurationFieldType.minutes(), newValues, minutes);
   checkAndUpdate(DurationFieldType.seconds(), newValues, seconds);
   checkAndUpdate(DurationFieldType.millis(), newValues, millis);
   iValues = newValues;
 }
Esempio 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));
    }
  }