use of android.icu.text.RelativeDateTimeFormatter in project j2objc by google.
the class RelativeDateTimeFormatterTest method TestRelativeDateWithQuantitySr.
@Test
public void TestRelativeDateWithQuantitySr() {
Object[][] data = { { 0.0, Direction.NEXT, RelativeUnit.MONTHS, "\u0437\u0430 0 \u043C\u0435\u0441\u0435\u0446\u0438" }, { 1.2, Direction.NEXT, RelativeUnit.MONTHS, "\u0437\u0430 1,2 \u043C\u0435\u0441\u0435\u0446\u0430" }, { 21.0, Direction.NEXT, RelativeUnit.MONTHS, "\u0437\u0430 21 \u043C\u0435\u0441\u0435\u0446" } };
RelativeDateTimeFormatter fmt = RelativeDateTimeFormatter.getInstance(new ULocale("sr"));
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);
}
}
use of android.icu.text.RelativeDateTimeFormatter in project j2objc by google.
the class RelativeDateTimeFormatterTest method TestRelativeDateWithQuantityNarrow.
@Test
public void TestRelativeDateWithQuantityNarrow() {
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.NARROW, 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);
}
}
use of android.icu.text.RelativeDateTimeFormatter in project j2objc by google.
the class RelativeDateTimeFormatterTest method TestCustomNumberFormat.
@Test
public void TestCustomNumberFormat() {
ULocale loc = new ULocale("en_US");
NumberFormat nf = NumberFormat.getInstance(loc);
nf.setMinimumFractionDigits(1);
nf.setMaximumFractionDigits(1);
RelativeDateTimeFormatter fmt = RelativeDateTimeFormatter.getInstance(loc, nf);
// Change nf after the fact to prove that we made a defensive copy
nf.setMinimumFractionDigits(3);
nf.setMaximumFractionDigits(3);
// Change getNumberFormat to prove we made defensive copy going out.
fmt.getNumberFormat().setMinimumFractionDigits(5);
assertEquals("TestCustomNumberformat", 1, fmt.getNumberFormat().getMinimumFractionDigits());
Object[][] data = { { 0.0, Direction.NEXT, RelativeUnit.SECONDS, "in 0.0 seconds" }, { 0.5, Direction.NEXT, RelativeUnit.SECONDS, "in 0.5 seconds" }, { 1.0, Direction.NEXT, RelativeUnit.SECONDS, "in 1.0 seconds" }, { 2.0, Direction.NEXT, RelativeUnit.SECONDS, "in 2.0 seconds" } };
for (Object[] row : data) {
String actual = fmt.format(((Double) row[0]).doubleValue(), (Direction) row[1], (RelativeUnit) row[2]);
assertEquals("Relative date with quantity special NumberFormat", row[3], actual);
}
}
use of android.icu.text.RelativeDateTimeFormatter in project j2objc by google.
the class RelativeDateTimeFormatterTest method TestRelativeDateWithQuantityCaps.
@Test
public void TestRelativeDateWithQuantityCaps() {
Object[][] data = { { 0.0, Direction.NEXT, RelativeUnit.SECONDS, "In 0 seconds" }, { 0.5, Direction.NEXT, RelativeUnit.SECONDS, "In 0.5 seconds" }, { 1.0, Direction.NEXT, RelativeUnit.SECONDS, "In 1 second" }, { 2.0, Direction.NEXT, RelativeUnit.SECONDS, "In 2 seconds" }, { 0.0, Direction.NEXT, RelativeUnit.MINUTES, "In 0 minutes" }, { 0.5, Direction.NEXT, RelativeUnit.MINUTES, "In 0.5 minutes" }, { 1.0, Direction.NEXT, RelativeUnit.MINUTES, "In 1 minute" }, { 2.0, Direction.NEXT, RelativeUnit.MINUTES, "In 2 minutes" }, { 0.0, Direction.NEXT, RelativeUnit.HOURS, "In 0 hours" }, { 0.5, Direction.NEXT, RelativeUnit.HOURS, "In 0.5 hours" }, { 1.0, Direction.NEXT, RelativeUnit.HOURS, "In 1 hour" }, { 2.0, Direction.NEXT, RelativeUnit.HOURS, "In 2 hours" }, { 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 weeks" }, { 0.5, Direction.NEXT, RelativeUnit.WEEKS, "In 0.5 weeks" }, { 1.0, Direction.NEXT, RelativeUnit.WEEKS, "In 1 week" }, { 2.0, Direction.NEXT, RelativeUnit.WEEKS, "In 2 weeks" }, { 0.0, Direction.NEXT, RelativeUnit.MONTHS, "In 0 months" }, { 0.5, Direction.NEXT, RelativeUnit.MONTHS, "In 0.5 months" }, { 1.0, Direction.NEXT, RelativeUnit.MONTHS, "In 1 month" }, { 2.0, Direction.NEXT, RelativeUnit.MONTHS, "In 2 months" }, { 0.0, Direction.NEXT, RelativeUnit.YEARS, "In 0 years" }, { 0.5, Direction.NEXT, RelativeUnit.YEARS, "In 0.5 years" }, { 1.0, Direction.NEXT, RelativeUnit.YEARS, "In 1 year" }, { 2.0, Direction.NEXT, RelativeUnit.YEARS, "In 2 years" }, { 0.0, Direction.LAST, RelativeUnit.SECONDS, "0 seconds ago" }, { 0.5, Direction.LAST, RelativeUnit.SECONDS, "0.5 seconds ago" }, { 1.0, Direction.LAST, RelativeUnit.SECONDS, "1 second ago" }, { 2.0, Direction.LAST, RelativeUnit.SECONDS, "2 seconds ago" }, { 0.0, Direction.LAST, RelativeUnit.MINUTES, "0 minutes ago" }, { 0.5, Direction.LAST, RelativeUnit.MINUTES, "0.5 minutes ago" }, { 1.0, Direction.LAST, RelativeUnit.MINUTES, "1 minute ago" }, { 2.0, Direction.LAST, RelativeUnit.MINUTES, "2 minutes ago" }, { 0.0, Direction.LAST, RelativeUnit.HOURS, "0 hours ago" }, { 0.5, Direction.LAST, RelativeUnit.HOURS, "0.5 hours ago" }, { 1.0, Direction.LAST, RelativeUnit.HOURS, "1 hour ago" }, { 2.0, Direction.LAST, RelativeUnit.HOURS, "2 hours 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 weeks ago" }, { 0.5, Direction.LAST, RelativeUnit.WEEKS, "0.5 weeks ago" }, { 1.0, Direction.LAST, RelativeUnit.WEEKS, "1 week ago" }, { 2.0, Direction.LAST, RelativeUnit.WEEKS, "2 weeks ago" }, { 0.0, Direction.LAST, RelativeUnit.MONTHS, "0 months ago" }, { 0.5, Direction.LAST, RelativeUnit.MONTHS, "0.5 months ago" }, { 1.0, Direction.LAST, RelativeUnit.MONTHS, "1 month ago" }, { 2.0, Direction.LAST, RelativeUnit.MONTHS, "2 months ago" }, { 0.0, Direction.LAST, RelativeUnit.YEARS, "0 years ago" }, { 0.5, Direction.LAST, RelativeUnit.YEARS, "0.5 years ago" }, { 1.0, Direction.LAST, RelativeUnit.YEARS, "1 year ago" }, { 2.0, Direction.LAST, RelativeUnit.YEARS, "2 years ago" } };
RelativeDateTimeFormatter fmt = RelativeDateTimeFormatter.getInstance(new ULocale("en_US"), null, RelativeDateTimeFormatter.Style.LONG, DisplayContext.CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE);
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);
}
}
use of android.icu.text.RelativeDateTimeFormatter in project j2objc by google.
the class RelativeDateTimeFormatterTest method TestGetters.
@Test
public void TestGetters() {
RelativeDateTimeFormatter fmt = RelativeDateTimeFormatter.getInstance(new ULocale("en_US"), null, RelativeDateTimeFormatter.Style.SHORT, DisplayContext.CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE);
assertEquals("", RelativeDateTimeFormatter.Style.SHORT, fmt.getFormatStyle());
assertEquals("", DisplayContext.CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, fmt.getCapitalizationContext());
// test the no-arguments getInstance();
RelativeDateTimeFormatter fmt_default = RelativeDateTimeFormatter.getInstance();
assertEquals("", RelativeDateTimeFormatter.Style.LONG, fmt_default.getFormatStyle());
assertEquals("", DisplayContext.CAPITALIZATION_NONE, fmt_default.getCapitalizationContext());
}
Aggregations