org.joda.time.DurationFieldType Java Examples

The following examples show how to use org.joda.time.DurationFieldType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestGJChronology.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
private void testAdd(String start, DurationFieldType type, int amt, String end) {
    DateTime dtStart = new DateTime(start, GJChronology.getInstance(DateTimeZone.UTC));
    DateTime dtEnd = new DateTime(end, GJChronology.getInstance(DateTimeZone.UTC));
    assertEquals(dtEnd, dtStart.withFieldAdded(type, amt));
    assertEquals(dtStart, dtEnd.withFieldAdded(type, -amt));

    DurationField field = type.getField(GJChronology.getInstance(DateTimeZone.UTC));
    int diff = field.getDifference(dtEnd.getMillis(), dtStart.getMillis());
    assertEquals(amt, diff);
    
    if (type == DurationFieldType.years() ||
        type == DurationFieldType.months() ||
        type == DurationFieldType.days()) {
        YearMonthDay ymdStart = new YearMonthDay(start, GJChronology.getInstance(DateTimeZone.UTC));
        YearMonthDay ymdEnd = new YearMonthDay(end, GJChronology.getInstance(DateTimeZone.UTC));
        assertEquals(ymdEnd, ymdStart.withFieldAdded(type, amt));
        assertEquals(ymdStart, ymdEnd.withFieldAdded(type, -amt));
    }
}
 
Example #2
Source File: PeriodFormatterBuilder.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
boolean isSupported(PeriodType type, int field) {
    switch (field) {
    default:
        return false;
    case YEARS:
        return type.isSupported(DurationFieldType.years());
    case MONTHS:
        return type.isSupported(DurationFieldType.months());
    case WEEKS:
        return type.isSupported(DurationFieldType.weeks());
    case DAYS:
        return type.isSupported(DurationFieldType.days());
    case HOURS:
        return type.isSupported(DurationFieldType.hours());
    case MINUTES:
        return type.isSupported(DurationFieldType.minutes());
    case SECONDS:
        return type.isSupported(DurationFieldType.seconds());
    case MILLIS:
        return type.isSupported(DurationFieldType.millis());
    case SECONDS_MILLIS: // drop through
    case SECONDS_OPTIONAL_MILLIS:
        return type.isSupported(DurationFieldType.seconds()) ||
               type.isSupported(DurationFieldType.millis());
    }
}
 
Example #3
Source File: PeriodFormatterBuilder.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
boolean isSupported(PeriodType type, int field) {
    switch (field) {
    default:
        return false;
    case YEARS:
        return type.isSupported(DurationFieldType.years());
    case MONTHS:
        return type.isSupported(DurationFieldType.months());
    case WEEKS:
        return type.isSupported(DurationFieldType.weeks());
    case DAYS:
        return type.isSupported(DurationFieldType.days());
    case HOURS:
        return type.isSupported(DurationFieldType.hours());
    case MINUTES:
        return type.isSupported(DurationFieldType.minutes());
    case SECONDS:
        return type.isSupported(DurationFieldType.seconds());
    case MILLIS:
        return type.isSupported(DurationFieldType.millis());
    case SECONDS_MILLIS: // drop through
    case SECONDS_OPTIONAL_MILLIS:
        return type.isSupported(DurationFieldType.seconds()) ||
               type.isSupported(DurationFieldType.millis());
    }
}
 
Example #4
Source File: TestGJChronology.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public void testCutoverAddMonths() {
    testAdd("1582-01-01", DurationFieldType.months(), 1, "1582-02-01");
    testAdd("1582-01-01", DurationFieldType.months(), 6, "1582-07-01");
    testAdd("1582-01-01", DurationFieldType.months(), 12, "1583-01-01");
    testAdd("1582-11-15", DurationFieldType.months(), 1, "1582-12-15");

    testAdd("1582-09-04", DurationFieldType.months(), 2, "1582-11-04");
    testAdd("1582-09-05", DurationFieldType.months(), 2, "1582-11-05");
    testAdd("1582-09-10", DurationFieldType.months(), 2, "1582-11-10");
    testAdd("1582-09-15", DurationFieldType.months(), 2, "1582-11-15");


    // Leap years...
    testAdd("1580-01-01", DurationFieldType.months(), 48, "1584-01-01");
    testAdd("1580-02-29", DurationFieldType.months(), 48, "1584-02-29");
    testAdd("1580-10-01", DurationFieldType.months(), 48, "1584-10-01");
    testAdd("1580-10-10", DurationFieldType.months(), 48, "1584-10-10");
    testAdd("1580-10-15", DurationFieldType.months(), 48, "1584-10-15");
    testAdd("1580-12-31", DurationFieldType.months(), 48, "1584-12-31");
}
 
Example #5
Source File: BasePeriod.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Adds the fields from another period.
 * 
 * @param values  the array of values to update
 * @param period  the period to add from, not null
 * @return the updated values
 * @throws IllegalArgumentException if an unsupported field's value is non-zero
 */
protected int[] addPeriodInto(int[] values, ReadablePeriod period) {
    for (int i = 0, isize = period.size(); i < isize; i++) {
        DurationFieldType type = period.getFieldType(i);
        int value = period.getValue(i);
        if (value != 0) {
            int index = indexOf(type);
            if (index == -1) {
                throw new IllegalArgumentException(
                    "Period does not support field '" + type.getName() + "'");
            } else {
                values[index] = FieldUtils.safeAdd(getValue(index), value);
            }
        }
    }
    return values;
}
 
Example #6
Source File: Time_13_PeriodFormatterBuilder_t.java    From coming with MIT License 6 votes vote down vote up
boolean isSupported(PeriodType type, int field) {
    switch (field) {
    default:
        return false;
    case YEARS:
        return type.isSupported(DurationFieldType.years());
    case MONTHS:
        return type.isSupported(DurationFieldType.months());
    case WEEKS:
        return type.isSupported(DurationFieldType.weeks());
    case DAYS:
        return type.isSupported(DurationFieldType.days());
    case HOURS:
        return type.isSupported(DurationFieldType.hours());
    case MINUTES:
        return type.isSupported(DurationFieldType.minutes());
    case SECONDS:
        return type.isSupported(DurationFieldType.seconds());
    case MILLIS:
        return type.isSupported(DurationFieldType.millis());
    case SECONDS_MILLIS: // drop through
    case SECONDS_OPTIONAL_MILLIS:
        return type.isSupported(DurationFieldType.seconds()) ||
               type.isSupported(DurationFieldType.millis());
    }
}
 
Example #7
Source File: TestISOChronology.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public void testAddMonths() {
    testAdd("1582-01-01", DurationFieldType.months(), 1, "1582-02-01");
    testAdd("1582-01-01", DurationFieldType.months(), 6, "1582-07-01");
    testAdd("1582-01-01", DurationFieldType.months(), 12, "1583-01-01");
    testAdd("1582-11-15", DurationFieldType.months(), 1, "1582-12-15");
    testAdd("1582-09-04", DurationFieldType.months(), 2, "1582-11-04");
    testAdd("1582-09-05", DurationFieldType.months(), 2, "1582-11-05");
    testAdd("1582-09-10", DurationFieldType.months(), 2, "1582-11-10");
    testAdd("1582-09-15", DurationFieldType.months(), 2, "1582-11-15");
    testAdd("1580-01-01", DurationFieldType.months(), 48, "1584-01-01");
    testAdd("1580-02-29", DurationFieldType.months(), 48, "1584-02-29");
    testAdd("1580-10-01", DurationFieldType.months(), 48, "1584-10-01");
    testAdd("1580-10-10", DurationFieldType.months(), 48, "1584-10-10");
    testAdd("1580-10-15", DurationFieldType.months(), 48, "1584-10-15");
    testAdd("1580-12-31", DurationFieldType.months(), 48, "1584-12-31");
}
 
Example #8
Source File: DateTimeUtils.java    From presto with Apache License 2.0 6 votes vote down vote up
private static Period parsePeriod(PeriodFormatter periodFormatter, String value)
{
    boolean negative = value.startsWith("-");
    if (negative) {
        value = value.substring(1);
    }

    Period period = periodFormatter.parsePeriod(value);
    for (DurationFieldType type : period.getFieldTypes()) {
        checkArgument(period.get(type) >= 0, "Period field %s is negative", type);
    }

    if (negative) {
        period = period.negated();
    }
    return period;
}
 
Example #9
Source File: TestGJChronology.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public void testCutoverAddYears() {
    testAdd("1582-01-01", DurationFieldType.years(), 1, "1583-01-01");
    testAdd("1582-02-15", DurationFieldType.years(), 1, "1583-02-15");
    testAdd("1582-02-28", DurationFieldType.years(), 1, "1583-02-28");
    testAdd("1582-03-01", DurationFieldType.years(), 1, "1583-03-01");
    testAdd("1582-09-30", DurationFieldType.years(), 1, "1583-09-30");
    testAdd("1582-10-01", DurationFieldType.years(), 1, "1583-10-01");
    testAdd("1582-10-04", DurationFieldType.years(), 1, "1583-10-04");
    testAdd("1582-10-15", DurationFieldType.years(), 1, "1583-10-15");
    testAdd("1582-10-16", DurationFieldType.years(), 1, "1583-10-16");

    // Leap years...
    testAdd("1580-01-01", DurationFieldType.years(), 4, "1584-01-01");
    testAdd("1580-02-29", DurationFieldType.years(), 4, "1584-02-29");
    testAdd("1580-10-01", DurationFieldType.years(), 4, "1584-10-01");
    testAdd("1580-10-10", DurationFieldType.years(), 4, "1584-10-10");
    testAdd("1580-10-15", DurationFieldType.years(), 4, "1584-10-15");
    testAdd("1580-12-31", DurationFieldType.years(), 4, "1584-12-31");
}
 
Example #10
Source File: TestGJChronology.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
private void testAdd(String start, DurationFieldType type, int amt, String end) {
    DateTime dtStart = new DateTime(start, GJChronology.getInstance(DateTimeZone.UTC));
    DateTime dtEnd = new DateTime(end, GJChronology.getInstance(DateTimeZone.UTC));
    assertEquals(dtEnd, dtStart.withFieldAdded(type, amt));
    assertEquals(dtStart, dtEnd.withFieldAdded(type, -amt));

    DurationField field = type.getField(GJChronology.getInstance(DateTimeZone.UTC));
    int diff = field.getDifference(dtEnd.getMillis(), dtStart.getMillis());
    assertEquals(amt, diff);
    
    if (type == DurationFieldType.years() ||
        type == DurationFieldType.months() ||
        type == DurationFieldType.days()) {
        YearMonthDay ymdStart = new YearMonthDay(start, GJChronology.getInstance(DateTimeZone.UTC));
        YearMonthDay ymdEnd = new YearMonthDay(end, GJChronology.getInstance(DateTimeZone.UTC));
        assertEquals(ymdEnd, ymdStart.withFieldAdded(type, amt));
        assertEquals(ymdStart, ymdEnd.withFieldAdded(type, -amt));
    }
}
 
Example #11
Source File: TestScaledDurationField.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void test_hashCode() {
    assertEquals(iField.hashCode(), iField.hashCode());
    assertEquals(false, iField.hashCode() == ISOChronology.getInstance().minutes().hashCode());
    DurationField dummy = new ScaledDurationField(MillisDurationField.INSTANCE, DurationFieldType.minutes(), 2);
    assertEquals(false, iField.hashCode() == dummy.hashCode());
    dummy = new ScaledDurationField(MillisDurationField.INSTANCE, DurationFieldType.minutes(), 90);
    assertEquals(true, iField.hashCode() == dummy.hashCode());
    dummy = new ScaledDurationField(MillisDurationField.INSTANCE, DurationFieldType.millis(), 90);
    assertEquals(false, iField.hashCode() == dummy.hashCode());
}
 
Example #12
Source File: ConfigUtilsTest.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
@Test
public void testPeriodParser() {
  Assert.assertEquals(ConfigUtils.parsePeriod("3600"), new Period().withField(DurationFieldType.millis(), 3600));
  Assert.assertEquals(ConfigUtils.parsePeriod("1d"), new Period().withField(DurationFieldType.days(), 1));
  Assert.assertEquals(ConfigUtils.parsePeriod("2hours"), new Period().withField(DurationFieldType.hours(), 2));
  Assert.assertEquals(ConfigUtils.parsePeriod("24 hrs"), new Period().withField(DurationFieldType.hours(), 24));
  Assert.assertEquals(ConfigUtils.parsePeriod("1 year"), new Period().withField(DurationFieldType.years(), 1));
  Assert.assertEquals(ConfigUtils.parsePeriod("  3   w  "), new Period().withField(DurationFieldType.weeks(), 3));
}
 
Example #13
Source File: BasePeriod.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Merges the fields from another period.
 * 
 * @param values  the array of values to update
 * @param period  the period to add from, not null
 * @return the updated values
 * @throws IllegalArgumentException if an unsupported field's value is non-zero
 */
protected int[] mergePeriodInto(int[] values, ReadablePeriod period) {
    for (int i = 0, isize = period.size(); i < isize; i++) {
        DurationFieldType type = period.getFieldType(i);
        int value = period.getValue(i);
        checkAndUpdate(type, values, value);
    }
    return values;
}
 
Example #14
Source File: Time_22_BasePeriod_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Merges the fields from another period.
 * 
 * @param values  the array of values to update
 * @param period  the period to add from, not null
 * @return the updated values
 * @throws IllegalArgumentException if an unsupported field's value is non-zero
 */
protected int[] mergePeriodInto(int[] values, ReadablePeriod period) {
     for (int i = 0, isize = period.size(); i < isize; i++) {
         DurationFieldType type = period.getFieldType(i);
         int value = period.getValue(i);
         checkAndUpdate(type, values, value);
     }
     return values;
}
 
Example #15
Source File: BasePeriod.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the value of a field in this period.
 * 
 * @param values  the array of values to update
 * @param field  the field to set
 * @param value  the value to set
 * @throws IllegalArgumentException if field is null or not supported.
 */
protected void setFieldInto(int[] values, DurationFieldType field, int value) {
    int index = indexOf(field);
    if (index == -1) {
        if (value != 0 || field == null) {
            throw new IllegalArgumentException(
                "Period does not support field '" + field + "'");
        }
    } else {
        values[index] = value;
    }
}
 
Example #16
Source File: BasePeriod.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Private method called from constructor.
 */
private void setPeriodInternal(ReadablePeriod period) {
    int[] newValues = new int[size()];
    for (int i = 0, isize = period.size(); i < isize; i++) {
        DurationFieldType type = period.getFieldType(i);
        int value = period.getValue(i);
        checkAndUpdate(type, newValues, value);
    }
    setValues(newValues);
}
 
Example #17
Source File: TestPreciseDurationField.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void test_hashCode() {
    assertEquals(true, iField.hashCode() == iField.hashCode());
    assertEquals(false, iField.hashCode() == ISOChronology.getInstance().minutes().hashCode());
    DurationField dummy = new PreciseDurationField(DurationFieldType.seconds(), 0);
    assertEquals(false, iField.hashCode() == dummy.hashCode());
    dummy = new PreciseDurationField(DurationFieldType.seconds(), 1000);
    assertEquals(true, iField.hashCode() == dummy.hashCode());
    dummy = new PreciseDurationField(DurationFieldType.millis(), 1000);
    assertEquals(false, iField.hashCode() == dummy.hashCode());
}
 
Example #18
Source File: UnsupportedDurationField.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets an instance of UnsupportedDurationField for a specific named field.
 * The returned instance is cached.
 * 
 * @param type  the type to obtain
 * @return the instance
 */
public static synchronized UnsupportedDurationField getInstance(DurationFieldType type) {
    UnsupportedDurationField field;
    if (cCache == null) {
        cCache = new HashMap<DurationFieldType, UnsupportedDurationField>(7);
        field = null;
    } else {
        field = cCache.get(type);
    }
    if (field == null) {
        field = new UnsupportedDurationField(type);
        cCache.put(type, field);
    }
    return field;
}
 
Example #19
Source File: TestScaledDurationField.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void test_compareTo() {
        assertEquals(0, iField.compareTo(iField));
        assertEquals(-1, iField.compareTo(ISOChronology.getInstance().minutes()));
        DurationField dummy = new PreciseDurationField(DurationFieldType.minutes(), 0);
        assertEquals(1, iField.compareTo(dummy));
//        try {
//            iField.compareTo("");
//            fail();
//        } catch (ClassCastException ex) {}
        try {
            iField.compareTo(null);
            fail();
        } catch (NullPointerException ex) {}
    }
 
Example #20
Source File: TestPreciseDurationField.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void test_equals() {
    assertEquals(true, iField.equals(iField));
    assertEquals(false, iField.equals(ISOChronology.getInstance().minutes()));
    DurationField dummy = new PreciseDurationField(DurationFieldType.seconds(), 0);
    assertEquals(false, iField.equals(dummy));
    dummy = new PreciseDurationField(DurationFieldType.seconds(), 1000);
    assertEquals(true, iField.equals(dummy));
    dummy = new PreciseDurationField(DurationFieldType.millis(), 1000);
    assertEquals(false, iField.equals(dummy));
    assertEquals(false, iField.equals(""));
    assertEquals(false, iField.equals(null));
}
 
Example #21
Source File: Time_2_UnsupportedDurationField_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Gets an instance of UnsupportedDurationField for a specific named field.
 * The returned instance is cached.
 * 
 * @param type  the type to obtain
 * @return the instance
 */
public static synchronized UnsupportedDurationField getInstance(DurationFieldType type) {
    UnsupportedDurationField field;
    if (cCache == null) {
        cCache = new HashMap<DurationFieldType, UnsupportedDurationField>(7);
        field = null;
    } else {
        field = cCache.get(type);
    }
    if (field == null) {
        field = new UnsupportedDurationField(type);
        cCache.put(type, field);
    }
    return field;
}
 
Example #22
Source File: FixedYearLengthChronology.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @param daysInYear The number of days in each year
 */
protected FixedYearLengthChronology(int daysInYear) {
  this.daysInYear = daysInYear;

  this.yearDuration = new PreciseDurationField(DurationFieldType.years(), daysInYear * dayDuration.getUnitMillis());
  this.centuryDuration = new PreciseDurationField(DurationFieldType.centuries(), 100 * yearDuration.getUnitMillis());

  this.dayOfYear = new OneBasedPreciseDateTimeField(DateTimeFieldType.dayOfYear(), dayDuration, this.yearDuration);
  this.yearOfCentury =
      new PreciseDateTimeField(DateTimeFieldType.yearOfCentury(), this.yearDuration, this.centuryDuration);
  this.year = new YearField(this.yearDuration);
}
 
Example #23
Source File: Time_22_BasePeriod_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example #24
Source File: TestGJChronology.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testCutoverAddDays() {
    testAdd("1582-10-03", DurationFieldType.days(), 1, "1582-10-04");
    testAdd("1582-10-04", DurationFieldType.days(), 1, "1582-10-15");
    testAdd("1582-10-15", DurationFieldType.days(), 1, "1582-10-16");

    testAdd("1582-09-30", DurationFieldType.days(), 10, "1582-10-20");
    testAdd("1582-10-04", DurationFieldType.days(), 10, "1582-10-24");
    testAdd("1582-10-15", DurationFieldType.days(), 10, "1582-10-25");
}
 
Example #25
Source File: UnsupportedDurationField.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets an instance of UnsupportedDurationField for a specific named field.
 * The returned instance is cached.
 * 
 * @param type  the type to obtain
 * @return the instance
 */
public static synchronized UnsupportedDurationField getInstance(DurationFieldType type) {
    UnsupportedDurationField field;
    if (cCache == null) {
        cCache = new HashMap<DurationFieldType, UnsupportedDurationField>(7);
        field = null;
    } else {
        field = cCache.get(type);
    }
    if (field == null) {
        field = new UnsupportedDurationField(type);
        cCache.put(type, field);
    }
    return field;
}
 
Example #26
Source File: TestPreciseDurationField.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void test_equals() {
    assertEquals(true, iField.equals(iField));
    assertEquals(false, iField.equals(ISOChronology.getInstance().minutes()));
    DurationField dummy = new PreciseDurationField(DurationFieldType.seconds(), 0);
    assertEquals(false, iField.equals(dummy));
    dummy = new PreciseDurationField(DurationFieldType.seconds(), 1000);
    assertEquals(true, iField.equals(dummy));
    dummy = new PreciseDurationField(DurationFieldType.millis(), 1000);
    assertEquals(false, iField.equals(dummy));
    assertEquals(false, iField.equals(""));
    assertEquals(false, iField.equals(null));
}
 
Example #27
Source File: Time_22_BasePeriod_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Merges the fields from another period.
 * 
 * @param values  the array of values to update
 * @param period  the period to add from, not null
 * @return the updated values
 * @throws IllegalArgumentException if an unsupported field's value is non-zero
 */
protected int[] mergePeriodInto(int[] values, ReadablePeriod period) {
     for (int i = 0, isize = period.size(); i < isize; i++) {
         DurationFieldType type = period.getFieldType(i);
         int value = period.getValue(i);
         checkAndUpdate(type, values, value);
     }
     return values;
}
 
Example #28
Source File: TestIslamicChronology.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public void testSampleDate3() {
    DateTime dt = new DateTime(1426, 12, 24, 0, 0, 0, 0, ISLAMIC_UTC);
    assertEquals(IslamicChronology.AH, dt.getEra());
    
    assertEquals(1426, dt.getYear());
    Property fld = dt.year();
    assertEquals(true, fld.isLeap());
    assertEquals(1, fld.getLeapAmount());
    assertEquals(DurationFieldType.days(), fld.getLeapDurationField().getType());
    
    assertEquals(12, dt.getMonthOfYear());
    fld = dt.monthOfYear();
    assertEquals(true, fld.isLeap());
    assertEquals(1, fld.getLeapAmount());
    assertEquals(DurationFieldType.days(), fld.getLeapDurationField().getType());
    assertEquals(1, fld.getMinimumValue());
    assertEquals(1, fld.getMinimumValueOverall());
    assertEquals(12, fld.getMaximumValue());
    assertEquals(12, fld.getMaximumValueOverall());
    
    assertEquals(24, dt.getDayOfMonth());
    fld = dt.dayOfMonth();
    assertEquals(false, fld.isLeap());
    assertEquals(0, fld.getLeapAmount());
    assertEquals(null, fld.getLeapDurationField());
    assertEquals(1, fld.getMinimumValue());
    assertEquals(1, fld.getMinimumValueOverall());
    assertEquals(30, fld.getMaximumValue());
    assertEquals(30, fld.getMaximumValueOverall());
    
    assertEquals(DateTimeConstants.TUESDAY, dt.getDayOfWeek());
    fld = dt.dayOfWeek();
    assertEquals(false, fld.isLeap());
    assertEquals(0, fld.getLeapAmount());
    assertEquals(null, fld.getLeapDurationField());
    assertEquals(1, fld.getMinimumValue());
    assertEquals(1, fld.getMinimumValueOverall());
    assertEquals(7, fld.getMaximumValue());
    assertEquals(7, fld.getMaximumValueOverall());
    
    assertEquals(6 * 30 + 5 * 29 + 24, dt.getDayOfYear());
    fld = dt.dayOfYear();
    assertEquals(false, fld.isLeap());
    assertEquals(0, fld.getLeapAmount());
    assertEquals(null, fld.getLeapDurationField());
    assertEquals(1, fld.getMinimumValue());
    assertEquals(1, fld.getMinimumValueOverall());
    assertEquals(355, fld.getMaximumValue());
    assertEquals(355, fld.getMaximumValueOverall());
    
    assertEquals(0, dt.getHourOfDay());
    assertEquals(0, dt.getMinuteOfHour());
    assertEquals(0, dt.getSecondOfMinute());
    assertEquals(0, dt.getMillisOfSecond());
}
 
Example #29
Source File: TestPreciseDurationDateTimeField.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public void test_toString() {
    BaseDateTimeField field = new MockPreciseDurationDateTimeField(
        DateTimeFieldType.secondOfDay(), new MockCountingDurationField(DurationFieldType.minutes()));
    assertEquals("DateTimeField[secondOfDay]", field.toString());
}
 
Example #30
Source File: TestPreciseDurationDateTimeField.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
protected MockZeroDurationField(DurationFieldType type) {
    super(type);
}