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());
}
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) {
}
}
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));
}
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());
}
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());
}
Aggregations