Package com.ibm.icu.impl.duration

Examples of com.ibm.icu.impl.duration.Period


  public void testOmitZeros() {
    // zeros are treated as omitted

    PeriodFormatter pf = pff.getFormatter();
    Period p = Period.at(1, MINUTE).and(0, SECOND).and(1, MILLISECOND);
    String s1 = pf.format(p);
    p.omit(SECOND);
    String s2 = pf.format(p);
    assertEquals(null, s1, s2);
  }
View Full Code Here


    public static void main(String[] args) {
        new PeriodTest().run(args);
    }

    public void testIsSet() {
        Period p = Period.at(0, TimeUnit.YEAR);
        assertTrue(null, p.isSet());
        assertTrue(null, p.isSet(TimeUnit.YEAR));
        assertFalse(null, p.isSet(TimeUnit.MONTH));
        assertEquals(null, 0f, p.getCount(TimeUnit.YEAR), .1f);
        p = p.omit(TimeUnit.YEAR);
        assertFalse(null, p.isSet(TimeUnit.YEAR));
    }
View Full Code Here

        p = p.omit(TimeUnit.YEAR);
        assertFalse(null, p.isSet(TimeUnit.YEAR));
    }

    public void testMoreLessThan() {
        Period p = Period.moreThan(1, TimeUnit.YEAR);
        assertTrue(null, p.isMoreThan());
        assertFalse(null, p.isLessThan());
        p = p.at();
        assertFalse(null, p.isMoreThan());
        assertFalse(null, p.isLessThan());
        p = p.lessThan();
        assertFalse(null, p.isMoreThan());
        assertTrue(null, p.isLessThan());
        p = p.moreThan();
        assertTrue(null, p.isMoreThan());
        assertFalse(null, p.isLessThan());

        p = Period.lessThan(1, TimeUnit.YEAR);
        assertFalse(null, p.isMoreThan());
        assertTrue(null, p.isLessThan());

        p = Period.at(1, TimeUnit.YEAR);
        assertFalse(null, p.isMoreThan());
        assertFalse(null, p.isLessThan());

        assertEquals(null, 1f, p.getCount(TimeUnit.YEAR), .1f);
    }
View Full Code Here

        assertEquals(null, 1f, p.getCount(TimeUnit.YEAR), .1f);
    }

    public void testFuturePast() {
        Period p = Period.at(1, TimeUnit.YEAR).inFuture();
        assertTrue(null, p.isInFuture());
        p = p.inPast();
        assertFalse(null, p.isInFuture());
        p = p.inFuture(true);
        assertTrue(null, p.isInFuture());
        p = p.inFuture(false);
        assertFalse(null, p.isInFuture());
    }
View Full Code Here

        p = p.inFuture(false);
        assertFalse(null, p.isInFuture());
    }

    public void testAnd() {
        Period p = Period.at(1, TimeUnit.YEAR).and(3, TimeUnit.MONTH)
                .inFuture();
        assertTrue(null, p.isSet(TimeUnit.YEAR));
        assertTrue(null, p.isSet(TimeUnit.MONTH));
        assertEquals(null, 3f, p.getCount(TimeUnit.MONTH), .1f);
        p = p.and(2, TimeUnit.MONTH);
        assertEquals(null, 2f, p.getCount(TimeUnit.MONTH), .1f);
    }
View Full Code Here

            Period.lessThan(-1, TimeUnit.YEAR);
            fail("lessThan -1");
        } catch (IllegalArgumentException e) {
            // passed
        }
        Period p = Period.at(1, TimeUnit.YEAR);
        try {
            p = p.and(-1, TimeUnit.MONTH);
            fail("and -1");
        } catch (IllegalArgumentException e) {
            // passed
        }
    }
View Full Code Here

        // sanity check, make sure by default all units are set
        pbf = BasicPeriodFormatterService.getInstance().newPeriodBuilderFactory();
        pbf.setLocale("en"); // in en locale, all units always available
        PeriodBuilder b = pbf.getSingleUnitBuilder();
        for (TimeUnit unit = YEAR; unit != null; unit = unit.smaller()) {
            Period p = b.create((long)(approxDurations[unit.ordinal()]*2.5));
            assertTrue(null, p.isSet(unit));
        }

        pbf.setAvailableUnitRange(MINUTE, MONTH);
        // units that are not available are never set
        b = pbf.getSingleUnitBuilder();
        for (TimeUnit unit = YEAR; unit != null; unit = unit.smaller()) {
            Period p = b.create((long)(approxDurations[unit.ordinal()]*2.5));
            assertEquals(null, p.isSet(unit), unit.ordinal() >= MONTH.ordinal() && unit.ordinal() <= MINUTE.ordinal());
        }

        // fixed unit builder returns null when unit is not available
        for (TimeUnit unit = YEAR; unit != null; unit = unit.smaller()) {
            b = pbf.getFixedUnitBuilder(unit);
View Full Code Here

TOP

Related Classes of com.ibm.icu.impl.duration.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.