use of org.joda.time.Period in project joda-time by JodaOrg.
the class TestPeriodFormatterBuilder method testFormatPrefixPlural4IgnoringPrefix.
public void testFormatPrefixPlural4IgnoringPrefix() {
PeriodFormatter f = builder.appendPrefix("m", "ms").appendMinutes().appendSeparator(" ").appendPrefix("mss", "msss").appendMillis().toFormatter();
String oneMS = Period.millis(1).toString(f);
assertEquals("mss1", oneMS);
Period period = f.parsePeriod(oneMS);
assertEquals(Period.millis(1), period);
period = f.parsePeriod(oneMS.toUpperCase(Locale.ENGLISH));
assertEquals(Period.millis(1), period);
String twoMS = Period.millis(2).toString(f);
assertEquals("msss2", twoMS);
Period period2 = f.parsePeriod(twoMS);
assertEquals(Period.millis(2), period2);
period = f.parsePeriod(twoMS.toUpperCase(Locale.ENGLISH));
assertEquals(Period.millis(2), period2);
}
use of org.joda.time.Period in project joda-time by JodaOrg.
the class TestPeriodFormatterBuilder method testFormatDays.
public void testFormatDays() {
PeriodFormatter f = builder.appendDays().toFormatter();
assertEquals("4", f.print(PERIOD));
assertEquals(1, f.getPrinter().calculatePrintedLength(PERIOD, null));
assertEquals(1, f.getPrinter().countFieldsToPrint(PERIOD, Integer.MAX_VALUE, null));
Period p = new Period(0, 0, 0, 0, 0, 0, 0, 0);
assertEquals("0", f.print(p));
assertEquals(1, f.getPrinter().calculatePrintedLength(p, null));
assertEquals(1, f.getPrinter().countFieldsToPrint(p, Integer.MAX_VALUE, null));
}
use of org.joda.time.Period in project joda-time by JodaOrg.
the class TestPeriodFormatterBuilder method testFormatPrefixSimple2.
public void testFormatPrefixSimple2() {
PeriodFormatter f = builder.appendPrefix("Hours:").appendHours().toFormatter();
assertEquals("Hours:5", f.print(PERIOD));
assertEquals(7, f.getPrinter().calculatePrintedLength(PERIOD, null));
assertEquals(1, f.getPrinter().countFieldsToPrint(PERIOD, Integer.MAX_VALUE, null));
Period p = new Period(0, 0, 0, 0, 0, 0, 0, 0);
assertEquals("Hours:0", f.print(p));
assertEquals(7, f.getPrinter().calculatePrintedLength(p, null));
assertEquals(1, f.getPrinter().countFieldsToPrint(p, Integer.MAX_VALUE, null));
}
use of org.joda.time.Period in project joda-time by JodaOrg.
the class TestPeriodFormatterBuilder method testFormatYears.
//-----------------------------------------------------------------------
public void testFormatYears() {
PeriodFormatter f = builder.appendYears().toFormatter();
assertEquals("1", f.print(PERIOD));
assertEquals(1, f.getPrinter().calculatePrintedLength(PERIOD, null));
assertEquals(1, f.getPrinter().countFieldsToPrint(PERIOD, Integer.MAX_VALUE, null));
Period p = new Period(0, 0, 0, 0, 0, 0, 0, 0);
assertEquals("0", f.print(p));
assertEquals(1, f.getPrinter().calculatePrintedLength(p, null));
assertEquals(1, f.getPrinter().countFieldsToPrint(p, Integer.MAX_VALUE, null));
}
use of org.joda.time.Period in project joda-time by JodaOrg.
the class TestPeriodFormatterBuilder method testFormatPrefixComposite1.
//-----------------------------------------------------------------------
public void testFormatPrefixComposite1() {
PeriodFormatter f = builder.appendPrefix("d").appendPrefix("a", "ay").appendPrefix(new String[] { "^1$", "^.*$" }, new String[] { "y:", "s:" }).appendDays().toFormatter();
String oneMS = Period.days(2).toString(f);
assertEquals("days:2", oneMS);
Period period = f.parsePeriod(oneMS);
assertEquals(Period.days(2), period);
period = f.parsePeriod(oneMS.toUpperCase(Locale.ENGLISH));
assertEquals(Period.days(2), period);
}
Aggregations