Search in sources :

Example 6 with MutablePeriod

use of org.joda.time.MutablePeriod in project joda-time by JodaOrg.

the class TestStringConverter method testSetIntoPeriod_Object6.

public void testSetIntoPeriod_Object6() throws Exception {
    MutablePeriod m = new MutablePeriod(PeriodType.yearWeekDayTime());
    StringConverter.INSTANCE.setInto(m, "P2Y4W3DT12H24M56.1234567S", null);
    assertEquals(2, m.getYears());
    assertEquals(4, m.getWeeks());
    assertEquals(3, m.getDays());
    assertEquals(12, m.getHours());
    assertEquals(24, m.getMinutes());
    assertEquals(56, m.getSeconds());
    assertEquals(123, m.getMillis());
}
Also used : MutablePeriod(org.joda.time.MutablePeriod)

Example 7 with MutablePeriod

use of org.joda.time.MutablePeriod in project joda-time by JodaOrg.

the class TestStringConverter method testSetIntoPeriod_Object8.

public void testSetIntoPeriod_Object8() throws Exception {
    MutablePeriod m = new MutablePeriod();
    try {
        StringConverter.INSTANCE.setInto(m, "", null);
        fail();
    } catch (IllegalArgumentException ex) {
    }
    try {
        StringConverter.INSTANCE.setInto(m, "PXY", null);
        fail();
    } catch (IllegalArgumentException ex) {
    }
    try {
        StringConverter.INSTANCE.setInto(m, "PT0SXY", null);
        fail();
    } catch (IllegalArgumentException ex) {
    }
    try {
        StringConverter.INSTANCE.setInto(m, "P2Y4W3DT12H24M48SX", null);
        fail();
    } catch (IllegalArgumentException ex) {
    }
}
Also used : MutablePeriod(org.joda.time.MutablePeriod)

Example 8 with MutablePeriod

use of org.joda.time.MutablePeriod in project joda-time by JodaOrg.

the class PeriodFormatter method parseMutablePeriod.

/**
     * Parses a period from the given text, returning a new MutablePeriod.
     *
     * @param text  text to parse
     * @return parsed value in a MutablePeriod object
     * @throws IllegalArgumentException if any field is out of range
     */
public MutablePeriod parseMutablePeriod(String text) {
    checkParser();
    MutablePeriod period = new MutablePeriod(0, iParseType);
    int newPos = getParser().parseInto(period, text, 0, iLocale);
    if (newPos >= 0) {
        if (newPos >= text.length()) {
            return period;
        }
    } else {
        newPos = ~newPos;
    }
    throw new IllegalArgumentException(FormatUtils.createErrorMessage(text, newPos));
}
Also used : MutablePeriod(org.joda.time.MutablePeriod)

Example 9 with MutablePeriod

use of org.joda.time.MutablePeriod in project joda-time by JodaOrg.

the class TestReadableIntervalConverter method testSetIntoPeriod_Object2.

public void testSetIntoPeriod_Object2() throws Exception {
    Interval i = new Interval(100L, 223L);
    MutablePeriod m = new MutablePeriod(PeriodType.millis());
    ReadableIntervalConverter.INSTANCE.setInto(m, i, CopticChronology.getInstance());
    assertEquals(0, m.getYears());
    assertEquals(0, m.getMonths());
    assertEquals(0, m.getWeeks());
    assertEquals(0, m.getDays());
    assertEquals(0, m.getHours());
    assertEquals(0, m.getMinutes());
    assertEquals(0, m.getSeconds());
    assertEquals(123, m.getMillis());
}
Also used : MutablePeriod(org.joda.time.MutablePeriod) ReadableInterval(org.joda.time.ReadableInterval) Interval(org.joda.time.Interval) MutableInterval(org.joda.time.MutableInterval)

Example 10 with MutablePeriod

use of org.joda.time.MutablePeriod in project joda-time by JodaOrg.

the class TestReadableIntervalConverter method testSetIntoPeriod_Object1.

public void testSetIntoPeriod_Object1() throws Exception {
    Interval i = new Interval(100L, 223L);
    MutablePeriod m = new MutablePeriod(PeriodType.millis());
    ReadableIntervalConverter.INSTANCE.setInto(m, i, null);
    assertEquals(0, m.getYears());
    assertEquals(0, m.getMonths());
    assertEquals(0, m.getWeeks());
    assertEquals(0, m.getDays());
    assertEquals(0, m.getHours());
    assertEquals(0, m.getMinutes());
    assertEquals(0, m.getSeconds());
    assertEquals(123, m.getMillis());
}
Also used : MutablePeriod(org.joda.time.MutablePeriod) ReadableInterval(org.joda.time.ReadableInterval) Interval(org.joda.time.Interval) MutableInterval(org.joda.time.MutableInterval)

Aggregations

MutablePeriod (org.joda.time.MutablePeriod)17 Interval (org.joda.time.Interval)2 MutableInterval (org.joda.time.MutableInterval)2 ReadableInterval (org.joda.time.ReadableInterval)2 Duration (org.joda.time.Duration)1 Period (org.joda.time.Period)1 ReadableDuration (org.joda.time.ReadableDuration)1 ReadablePeriod (org.joda.time.ReadablePeriod)1