Package org.joda.time

Examples of org.joda.time.Period


                .appendSuffix("a", "ay")
                .appendSuffix(new String[] { "^1$", "^.*$" }, new String[] { "y", "s" })
                .toFormatter();
        String oneMS = Period.days(2).toString(f);
        assertEquals("2days", oneMS);
        Period period = f.parsePeriod(oneMS);
        assertEquals(Period.days(2), period);
    }
View Full Code Here


                .appendSeparator(" ")
                .appendMillis().appendSuffix("m").appendSuffix("s")
                .toFormatter();
        String oneMS = Period.millis(1).toString(f);
        assertEquals("1ms", oneMS);
        Period period = f.parsePeriod(oneMS);
        assertEquals(Period.millis(1), period);
    }
View Full Code Here

        PeriodFormatter f = builder.appendPrefix("P").appendYears().appendSuffix("Y").toFormatter();
        assertEquals("P1Y", f.print(PERIOD));
        assertEquals(3, 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("P0Y", f.print(p));
        assertEquals(3, f.getPrinter().calculatePrintedLength(p, null));
        assertEquals(1, f.getPrinter().countFieldsToPrint(p, Integer.MAX_VALUE, null));
    }
View Full Code Here

        PeriodFormatter f = bld.toFormatter();
        try {
            f.print(PERIOD);
            fail();
        } catch (UnsupportedOperationException ex) {}
        assertEquals(new Period(0, 2, 1, 0, 0, 0, 0, 0), f.parsePeriod("1-2"));
    }
View Full Code Here

        assertNotNull(bld.toPrinter());
        assertNotNull(bld.toParser());
       
        PeriodFormatter f = bld.toFormatter();
        assertEquals("1-2", f.print(PERIOD));
        assertEquals(new Period(0, 2, 1, 0, 0, 0, 0, 0), f.parsePeriod("1-2"));
    }
View Full Code Here

        f = null;
    }

    //-----------------------------------------------------------------------
    public void testPrint_simple() {
        Period p = new Period(1, 2, 3, 4, 5, 6, 7, 8);
        assertEquals("P1Y2M3W4DT5H6M7.008S", f.print(p));
    }
View Full Code Here

        assertEquals("P1Y2M3W4DT5H6M7.008S", f.print(p));
    }

    //-----------------------------------------------------------------------
    public void testPrint_bufferMethods() throws Exception {
        Period p = new Period(1, 2, 3, 4, 5, 6, 7, 8);
        StringBuffer buf = new StringBuffer();
        f.printTo(buf, p);
        assertEquals("P1Y2M3W4DT5H6M7.008S", buf.toString());
       
        buf = new StringBuffer();
View Full Code Here

        } catch (IllegalArgumentException ex) {}
    }

    //-----------------------------------------------------------------------
    public void testPrint_writerMethods() throws Exception {
        Period p = new Period(1, 2, 3, 4, 5, 6, 7, 8);
        CharArrayWriter out = new CharArrayWriter();
        f.printTo(out, p);
        assertEquals("P1Y2M3W4DT5H6M7.008S", out.toString());
       
        out = new CharArrayWriter();
View Full Code Here

        assertEquals(null, f2.getParseType());
        assertSame(f2, f2.withParseType(null));
    }

    public void testPrinterParserMethods() {
        Period p = new Period(1, 2, 3, 4, 5, 6, 7, 8);
        PeriodFormatter f2 = new PeriodFormatter(f.getPrinter(), f.getParser());
        assertEquals(f.getPrinter(), f2.getPrinter());
        assertEquals(f.getParser(), f2.getParser());
        assertEquals(true, f2.isPrinter());
        assertEquals(true, f2.isParser());
View Full Code Here

        assertNotNull(f2.parsePeriod("P1Y2M3W4DT5H6M7.008S"));
    }

    //-----------------------------------------------------------------------
    public void testParsePeriod_simple() {
        Period expect = new Period(1, 2, 3, 4, 5, 6, 7, 8);
        assertEquals(expect, f.parsePeriod("P1Y2M3W4DT5H6M7.008S"));
       
        try {
            f.parsePeriod("ABC");
            fail();
View Full Code Here

TOP

Related Classes of org.joda.time.Period

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.