Search in sources :

Example 11 with TimeUnitFormat

use of android.icu.text.TimeUnitFormat in project j2objc by google.

the class TimeUnitTest method TestAPI.

@Test
public void TestAPI() {
    TimeUnitFormat format = new TimeUnitFormat();
    format.setLocale(new ULocale("pt_BR"));
    formatParsing(format);
    format = new TimeUnitFormat(new ULocale("de"));
    formatParsing(format);
    format = new TimeUnitFormat(new ULocale("ja"));
    format.setNumberFormat(NumberFormat.getNumberInstance(new ULocale("en")));
    formatParsing(format);
    format = new TimeUnitFormat();
    ULocale es = new ULocale("es");
    format.setNumberFormat(NumberFormat.getNumberInstance(es));
    format.setLocale(es);
    formatParsing(format);
    format.setLocale(new Locale("pt_BR"));
    formatParsing(format);
    format = new TimeUnitFormat(new Locale("de"));
    formatParsing(format);
    format = new TimeUnitFormat(new Locale("ja"));
    format.setNumberFormat(NumberFormat.getNumberInstance(new Locale("en")));
    formatParsing(format);
}
Also used : ULocale(android.icu.util.ULocale) Locale(java.util.Locale) ULocale(android.icu.util.ULocale) TimeUnitFormat(android.icu.text.TimeUnitFormat) Test(org.junit.Test)

Example 12 with TimeUnitFormat

use of android.icu.text.TimeUnitFormat in project j2objc by google.

the class TimeUnitTest method TestGreek.

/*
     * @bug 7902
     * This tests that requests for short unit names correctly fall back 
     * to long unit names for a locale where the locale data does not 
     * provide short unit names. As of CLDR 1.9, Greek is one such language.
     */
@Test
public void TestGreek() {
    String[] locales = { "el_GR", "el" };
    final TimeUnit[] units = new TimeUnit[] { TimeUnit.SECOND, TimeUnit.MINUTE, TimeUnit.HOUR, TimeUnit.DAY, TimeUnit.WEEK, TimeUnit.MONTH, TimeUnit.YEAR };
    int[] styles = new int[] { TimeUnitFormat.FULL_NAME, TimeUnitFormat.ABBREVIATED_NAME };
    int[] numbers = new int[] { 1, 7 };
    String[] expected = { // "el_GR" 1 wide
    "1 δευτερόλεπτο", "1 λεπτό", "1 ώρα", "1 ημέρα", "1 εβδομάδα", "1 μήνας", "1 έτος", // "el_GR" 1 short
    "1 δευτ.", "1 λεπ.", "1 ώρα", "1 ημέρα", "1 εβδ.", "1 μήν.", // year (one)
    "1 έτ.", // "el_GR" 7 wide
    "7 δευτερόλεπτα", "7 λεπτά", "7 ώρες", "7 ημέρες", "7 εβδομάδες", "7 μήνες", "7 έτη", // "el_GR" 7 short
    "7 δευτ.", "7 λεπ.", // hour (other)
    "7 ώρ.", "7 ημέρες", "7 εβδ.", "7 μήν.", // year (other)
    "7 έτ.", // "el" 1 wide
    "1 δευτερόλεπτο", "1 λεπτό", "1 ώρα", "1 ημέρα", "1 εβδομάδα", "1 μήνας", "1 έτος", // "el" 1 short
    "1 δευτ.", "1 λεπ.", "1 ώρα", "1 ημέρα", "1 εβδ.", "1 μήν.", // year (one)
    "1 έτ.", // "el" 7 wide
    "7 δευτερόλεπτα", "7 λεπτά", "7 ώρες", "7 ημέρες", "7 εβδομάδες", "7 μήνες", "7 έτη", // "el" 7 short
    "7 δευτ.", "7 λεπ.", // hour (other)
    "7 ώρ.", "7 ημέρες", "7 εβδ.", "7 μήν.", // year (other
    "7 έτ." };
    int counter = 0;
    TimeUnitFormat timeUnitFormat;
    TimeUnitAmount timeUnitAmount;
    String formatted;
    for (int locIndex = 0; locIndex < locales.length; ++locIndex) {
        for (int numIndex = 0; numIndex < numbers.length; ++numIndex) {
            for (int styleIndex = 0; styleIndex < styles.length; ++styleIndex) {
                for (int unitIndex = 0; unitIndex < units.length; ++unitIndex) {
                    timeUnitAmount = new TimeUnitAmount(numbers[numIndex], units[unitIndex]);
                    timeUnitFormat = new TimeUnitFormat(new ULocale(locales[locIndex]), styles[styleIndex]);
                    formatted = timeUnitFormat.format(timeUnitAmount);
                    assertEquals("locale: " + locales[locIndex] + ", style: " + styles[styleIndex] + ", units: " + units[unitIndex] + ", value: " + numbers[numIndex], expected[counter], formatted);
                    ++counter;
                }
            }
        }
    }
}
Also used : TimeUnitAmount(android.icu.util.TimeUnitAmount) ULocale(android.icu.util.ULocale) TimeUnitFormat(android.icu.text.TimeUnitFormat) TimeUnit(android.icu.util.TimeUnit) Test(org.junit.Test)

Example 13 with TimeUnitFormat

use of android.icu.text.TimeUnitFormat in project j2objc by google.

the class TimeUnitTest method TestFormat.

/*
     * Tests the method public StringBuffer format(Object obj, ...
     */
@Test
public void TestFormat() {
    TimeUnitFormat tuf = new TimeUnitFormat();
    try {
        tuf.format(new Integer("1"), null, null);
        errln("TimeUnitFormat.format(Object,StringBuffer,FieldPosition) " + "was suppose to return an exception because the Object " + "parameter was not of type TimeUnitAmount.");
    } catch (Exception e) {
    }
}
Also used : TimeUnitFormat(android.icu.text.TimeUnitFormat) ParseException(java.text.ParseException) Test(org.junit.Test)

Example 14 with TimeUnitFormat

use of android.icu.text.TimeUnitFormat in project j2objc by google.

the class TimeUnitTest method TestClone.

@Test
public void TestClone() {
    TimeUnitFormat tuf = new TimeUnitFormat(ULocale.ENGLISH, TimeUnitFormat.ABBREVIATED_NAME);
    NumberFormat nf = NumberFormat.getInstance();
    tuf.setNumberFormat(nf);
    TimeUnitFormat tufClone = (TimeUnitFormat) tuf.clone();
    tuf.setLocale(Locale.GERMAN);
    assertEquals("", "1 hr", tufClone.format(new TimeUnitAmount(1, TimeUnit.HOUR)));
}
Also used : TimeUnitAmount(android.icu.util.TimeUnitAmount) TimeUnitFormat(android.icu.text.TimeUnitFormat) NumberFormat(android.icu.text.NumberFormat) Test(org.junit.Test)

Example 15 with TimeUnitFormat

use of android.icu.text.TimeUnitFormat in project j2objc by google.

the class TimeUnitTest method TestSetup.

/* Tests the method private void setup() from
     * public Object parseObject(String source, ParsePosition pos)
     * 
     */
@Test
public void TestSetup() {
    TimeUnitFormat tuf = new TimeUnitFormat();
    tuf.parseObject("", new ParsePosition(0));
    TimeUnitFormat tuf1 = new TimeUnitFormat();
    tuf1.setNumberFormat(NumberFormat.getInstance());
    tuf1.parseObject("", new ParsePosition(0));
}
Also used : TimeUnitFormat(android.icu.text.TimeUnitFormat) ParsePosition(java.text.ParsePosition) Test(org.junit.Test)

Aggregations

TimeUnitFormat (android.icu.text.TimeUnitFormat)15 Test (org.junit.Test)15 ULocale (android.icu.util.ULocale)7 TimeUnitAmount (android.icu.util.TimeUnitAmount)5 NumberFormat (android.icu.text.NumberFormat)3 ParseException (java.text.ParseException)3 ParsePosition (java.text.ParsePosition)3 TimeUnit (android.icu.util.TimeUnit)2 Locale (java.util.Locale)2 MeasureFormat (android.icu.text.MeasureFormat)1 Measure (android.icu.util.Measure)1 Ignore (org.junit.Ignore)1