Search in sources :

Example 1 with RelativeDateTimeFormatter

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

the class RelativeDateTimeFormatterTest method TestFormatWithoutQuantityIllegalArgument.

@Test
public void TestFormatWithoutQuantityIllegalArgument() {
    RelativeDateTimeFormatter fmt = RelativeDateTimeFormatter.getInstance(new ULocale("en_US"));
    try {
        fmt.format(Direction.LAST, AbsoluteUnit.NOW);
        fail("Expected IllegalArgumentException.");
    } catch (IllegalArgumentException e) {
    // Expected
    }
    try {
        fmt.format(Direction.NEXT, AbsoluteUnit.NOW);
        fail("Expected IllegalArgumentException.");
    } catch (IllegalArgumentException e) {
    // Expected
    }
    try {
        fmt.format(Direction.THIS, AbsoluteUnit.NOW);
        fail("Expected IllegalArgumentException.");
    } catch (IllegalArgumentException e) {
    // Expected
    }
}
Also used : ULocale(android.icu.util.ULocale) RelativeDateTimeFormatter(android.icu.text.RelativeDateTimeFormatter) Test(org.junit.Test)

Example 2 with RelativeDateTimeFormatter

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

the class RelativeDateTimeFormatterTest method TestCombineDateAndTime.

@Test
public void TestCombineDateAndTime() {
    RelativeDateTimeFormatter fmt = RelativeDateTimeFormatter.getInstance(new ULocale("en_US"));
    assertEquals("TestcombineDateAndTime", "yesterday, 3:50", fmt.combineDateAndTime("yesterday", "3:50"));
}
Also used : ULocale(android.icu.util.ULocale) RelativeDateTimeFormatter(android.icu.text.RelativeDateTimeFormatter) Test(org.junit.Test)

Example 3 with RelativeDateTimeFormatter

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

the class RelativeDateTimeFormatterTest method TestTwoBeforeTwoAfter.

@Test
public void TestTwoBeforeTwoAfter() {
    Object[][] data = { { Direction.NEXT_2, AbsoluteUnit.DAY, "pasado ma\u00F1ana" }, { Direction.LAST_2, AbsoluteUnit.DAY, "anteayer" } };
    RelativeDateTimeFormatter fmt = RelativeDateTimeFormatter.getInstance(new ULocale("es"));
    for (Object[] row : data) {
        String actual = fmt.format((Direction) row[0], (AbsoluteUnit) row[1]);
        assertEquals("Two before two after", row[2], actual);
    }
}
Also used : ULocale(android.icu.util.ULocale) RelativeDateTimeFormatter(android.icu.text.RelativeDateTimeFormatter) Test(org.junit.Test)

Example 4 with RelativeDateTimeFormatter

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

the class RelativeDateTimeFormatterTest method TestFormatWithQuantityIllegalArgument.

@Test
public void TestFormatWithQuantityIllegalArgument() {
    RelativeDateTimeFormatter fmt = RelativeDateTimeFormatter.getInstance(new ULocale("en_US"));
    try {
        fmt.format(1.0, Direction.PLAIN, RelativeUnit.DAYS);
        fail("Expected IllegalArgumentException.");
    } catch (IllegalArgumentException e) {
    // Expected
    }
    try {
        fmt.format(1.0, Direction.THIS, RelativeUnit.DAYS);
        fail("Expected IllegalArgumentException.");
    } catch (IllegalArgumentException e) {
    // Expected
    }
}
Also used : ULocale(android.icu.util.ULocale) RelativeDateTimeFormatter(android.icu.text.RelativeDateTimeFormatter) Test(org.junit.Test)

Example 5 with RelativeDateTimeFormatter

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

the class RelativeDateTimeFormatterTest method TestRelativeDateWithQuantityShort.

@Test
public void TestRelativeDateWithQuantityShort() {
    Object[][] data = { { 0.0, Direction.NEXT, RelativeUnit.SECONDS, "in 0 sec." }, { 0.5, Direction.NEXT, RelativeUnit.SECONDS, "in 0.5 sec." }, { 1.0, Direction.NEXT, RelativeUnit.SECONDS, "in 1 sec." }, { 2.0, Direction.NEXT, RelativeUnit.SECONDS, "in 2 sec." }, { 0.0, Direction.NEXT, RelativeUnit.MINUTES, "in 0 min." }, { 0.5, Direction.NEXT, RelativeUnit.MINUTES, "in 0.5 min." }, { 1.0, Direction.NEXT, RelativeUnit.MINUTES, "in 1 min." }, { 2.0, Direction.NEXT, RelativeUnit.MINUTES, "in 2 min." }, { 0.0, Direction.NEXT, RelativeUnit.HOURS, "in 0 hr." }, { 0.5, Direction.NEXT, RelativeUnit.HOURS, "in 0.5 hr." }, { 1.0, Direction.NEXT, RelativeUnit.HOURS, "in 1 hr." }, { 2.0, Direction.NEXT, RelativeUnit.HOURS, "in 2 hr." }, { 0.0, Direction.NEXT, RelativeUnit.DAYS, "in 0 days" }, { 0.5, Direction.NEXT, RelativeUnit.DAYS, "in 0.5 days" }, { 1.0, Direction.NEXT, RelativeUnit.DAYS, "in 1 day" }, { 2.0, Direction.NEXT, RelativeUnit.DAYS, "in 2 days" }, { 0.0, Direction.NEXT, RelativeUnit.WEEKS, "in 0 wk." }, { 0.5, Direction.NEXT, RelativeUnit.WEEKS, "in 0.5 wk." }, { 1.0, Direction.NEXT, RelativeUnit.WEEKS, "in 1 wk." }, { 2.0, Direction.NEXT, RelativeUnit.WEEKS, "in 2 wk." }, { 0.0, Direction.NEXT, RelativeUnit.MONTHS, "in 0 mo." }, { 0.5, Direction.NEXT, RelativeUnit.MONTHS, "in 0.5 mo." }, { 1.0, Direction.NEXT, RelativeUnit.MONTHS, "in 1 mo." }, { 2.0, Direction.NEXT, RelativeUnit.MONTHS, "in 2 mo." }, { 0.0, Direction.NEXT, RelativeUnit.YEARS, "in 0 yr." }, { 0.5, Direction.NEXT, RelativeUnit.YEARS, "in 0.5 yr." }, { 1.0, Direction.NEXT, RelativeUnit.YEARS, "in 1 yr." }, { 2.0, Direction.NEXT, RelativeUnit.YEARS, "in 2 yr." }, { 0.0, Direction.LAST, RelativeUnit.SECONDS, "0 sec. ago" }, { 0.5, Direction.LAST, RelativeUnit.SECONDS, "0.5 sec. ago" }, { 1.0, Direction.LAST, RelativeUnit.SECONDS, "1 sec. ago" }, { 2.0, Direction.LAST, RelativeUnit.SECONDS, "2 sec. ago" }, { 0.0, Direction.LAST, RelativeUnit.MINUTES, "0 min. ago" }, { 0.5, Direction.LAST, RelativeUnit.MINUTES, "0.5 min. ago" }, { 1.0, Direction.LAST, RelativeUnit.MINUTES, "1 min. ago" }, { 2.0, Direction.LAST, RelativeUnit.MINUTES, "2 min. ago" }, { 0.0, Direction.LAST, RelativeUnit.HOURS, "0 hr. ago" }, { 0.5, Direction.LAST, RelativeUnit.HOURS, "0.5 hr. ago" }, { 1.0, Direction.LAST, RelativeUnit.HOURS, "1 hr. ago" }, { 2.0, Direction.LAST, RelativeUnit.HOURS, "2 hr. ago" }, { 0.0, Direction.LAST, RelativeUnit.DAYS, "0 days ago" }, { 0.5, Direction.LAST, RelativeUnit.DAYS, "0.5 days ago" }, { 1.0, Direction.LAST, RelativeUnit.DAYS, "1 day ago" }, { 2.0, Direction.LAST, RelativeUnit.DAYS, "2 days ago" }, { 0.0, Direction.LAST, RelativeUnit.WEEKS, "0 wk. ago" }, { 0.5, Direction.LAST, RelativeUnit.WEEKS, "0.5 wk. ago" }, { 1.0, Direction.LAST, RelativeUnit.WEEKS, "1 wk. ago" }, { 2.0, Direction.LAST, RelativeUnit.WEEKS, "2 wk. ago" }, { 0.0, Direction.LAST, RelativeUnit.MONTHS, "0 mo. ago" }, { 0.5, Direction.LAST, RelativeUnit.MONTHS, "0.5 mo. ago" }, { 1.0, Direction.LAST, RelativeUnit.MONTHS, "1 mo. ago" }, { 2.0, Direction.LAST, RelativeUnit.MONTHS, "2 mo. ago" }, { 0.0, Direction.LAST, RelativeUnit.YEARS, "0 yr. ago" }, { 0.5, Direction.LAST, RelativeUnit.YEARS, "0.5 yr. ago" }, { 1.0, Direction.LAST, RelativeUnit.YEARS, "1 yr. ago" }, { 2.0, Direction.LAST, RelativeUnit.YEARS, "2 yr. ago" } };
    RelativeDateTimeFormatter fmt = RelativeDateTimeFormatter.getInstance(new ULocale("en_US"), null, RelativeDateTimeFormatter.Style.SHORT, DisplayContext.CAPITALIZATION_NONE);
    for (Object[] row : data) {
        String actual = fmt.format(((Double) row[0]).doubleValue(), (Direction) row[1], (RelativeUnit) row[2]);
        assertEquals("Relative date with quantity", row[3], actual);
    }
}
Also used : ULocale(android.icu.util.ULocale) RelativeDateTimeFormatter(android.icu.text.RelativeDateTimeFormatter) Test(org.junit.Test)

Aggregations

RelativeDateTimeFormatter (android.icu.text.RelativeDateTimeFormatter)19 ULocale (android.icu.util.ULocale)19 Test (org.junit.Test)19 NumberFormat (android.icu.text.NumberFormat)3 DisplayContext (android.icu.text.DisplayContext)1 RelativeDateTimeUnit (android.icu.text.RelativeDateTimeFormatter.RelativeDateTimeUnit)1 Style (android.icu.text.RelativeDateTimeFormatter.Style)1 Locale (java.util.Locale)1