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);
}
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;
}
}
}
}
}
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) {
}
}
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)));
}
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));
}
Aggregations