Examples of PeriodBuilder


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

    public void testSetAvailableUnitRange() {
        // 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()) {
View Full Code Here

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

        }
       
        // same issue, but using English and the internal APIs
        {
            PeriodFormatterService pfs = BasicPeriodFormatterService.getInstance();
            PeriodBuilder pb = pfs.newPeriodBuilderFactory()
                .setAllowMilliseconds(false)
                .getSingleUnitBuilder();
            DurationFormatter df = pfs.newDurationFormatterFactory()
                .setPeriodBuilder(pb)
                .getFormatter();
            String result = df.formatDurationFromNow(500);
            assertEquals(
                "english test case",
                "less than 1 second from now",
                result);
          
        }
       
        // if the limit is set on milliseconds, and they are not supported,
        // use an effective limit based on seconds
        {
            PeriodFormatterService pfs = BasicPeriodFormatterService.getInstance();
            PeriodBuilder pb = pfs.newPeriodBuilderFactory()
                .setMinLimit(2500)
                .setAllowMilliseconds(false)
                .getSingleUnitBuilder();
            DurationFormatter df = pfs.newDurationFormatterFactory()
                .setPeriodBuilder(pb)
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.