Search in sources :

Example 26 with DateTimePatternGenerator

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

the class DateTimeGeneratorTest method TestGetDecimal.

/* Tests the method
     *        public String getDecimal()
     */
@Test
public void TestGetDecimal() {
    DateTimePatternGenerator dtpg = DateTimePatternGenerator.getInstance();
    if (!dtpg.getDecimal().equals(".")) {
        errln("DateTimePatternGenerator.getDecimal() was to return '.' " + "when the object gets a new instance.");
    }
    String[] cases = { ",", "-", "", "*", "&", "a", "0" };
    for (int i = 0; i < cases.length; i++) {
        dtpg.setDecimal(cases[i]);
        if (!dtpg.getDecimal().equals(cases[i])) {
            errln("DateTimePatternGenerator.getDecimal() was to return " + cases[i] + "when setting decimal with " + cases[i]);
        }
    }
}
Also used : DateTimePatternGenerator(android.icu.text.DateTimePatternGenerator) Test(org.junit.Test)

Example 27 with DateTimePatternGenerator

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

the class DateTimeGeneratorTest method TestOptions.

@Test
public void TestOptions() {
    final TestOptionsItem[] testOptionsData = { new TestOptionsItem("en", "Hmm", "HH:mm", DateTimePatternGenerator.MATCH_NO_OPTIONS), new TestOptionsItem("en", "HHmm", "HH:mm", DateTimePatternGenerator.MATCH_NO_OPTIONS), new TestOptionsItem("en", "hhmm", "h:mm a", DateTimePatternGenerator.MATCH_NO_OPTIONS), new TestOptionsItem("en", "Hmm", "HH:mm", DateTimePatternGenerator.MATCH_HOUR_FIELD_LENGTH), new TestOptionsItem("en", "HHmm", "HH:mm", DateTimePatternGenerator.MATCH_HOUR_FIELD_LENGTH), new TestOptionsItem("en", "hhmm", "hh:mm a", DateTimePatternGenerator.MATCH_HOUR_FIELD_LENGTH), new TestOptionsItem("da", "Hmm", "HH.mm", DateTimePatternGenerator.MATCH_NO_OPTIONS), new TestOptionsItem("da", "HHmm", "HH.mm", DateTimePatternGenerator.MATCH_NO_OPTIONS), new TestOptionsItem("da", "hhmm", "h.mm a", DateTimePatternGenerator.MATCH_NO_OPTIONS), new TestOptionsItem("da", "Hmm", "H.mm", DateTimePatternGenerator.MATCH_HOUR_FIELD_LENGTH), new TestOptionsItem("da", "HHmm", "HH.mm", DateTimePatternGenerator.MATCH_HOUR_FIELD_LENGTH), new TestOptionsItem("da", "hhmm", "hh.mm a", DateTimePatternGenerator.MATCH_HOUR_FIELD_LENGTH), // 
    new TestOptionsItem("en", "yyyy", "yyyy", DateTimePatternGenerator.MATCH_NO_OPTIONS), new TestOptionsItem("en", "YYYY", "YYYY", DateTimePatternGenerator.MATCH_NO_OPTIONS), new TestOptionsItem("en", "U", "y", DateTimePatternGenerator.MATCH_NO_OPTIONS), new TestOptionsItem("en@calendar=japanese", "yyyy", "y G", DateTimePatternGenerator.MATCH_NO_OPTIONS), new TestOptionsItem("en@calendar=japanese", "YYYY", "Y G", DateTimePatternGenerator.MATCH_NO_OPTIONS), new TestOptionsItem("en@calendar=japanese", "U", "y G", DateTimePatternGenerator.MATCH_NO_OPTIONS), new TestOptionsItem("en@calendar=chinese", "yyyy", "r(U)", DateTimePatternGenerator.MATCH_NO_OPTIONS), // not a good result, want r(Y) or r(U)
    new TestOptionsItem("en@calendar=chinese", "YYYY", "Y(Y)", DateTimePatternGenerator.MATCH_NO_OPTIONS), new TestOptionsItem("en@calendar=chinese", "U", "r(U)", DateTimePatternGenerator.MATCH_NO_OPTIONS), new TestOptionsItem("en@calendar=chinese", "Gy", "r(U)", DateTimePatternGenerator.MATCH_NO_OPTIONS), new TestOptionsItem("en@calendar=chinese", "GU", "r(U)", DateTimePatternGenerator.MATCH_NO_OPTIONS), new TestOptionsItem("en@calendar=chinese", "ULLL", "MMM U", DateTimePatternGenerator.MATCH_NO_OPTIONS), new TestOptionsItem("en@calendar=chinese", "yMMM", "MMM r(U)", DateTimePatternGenerator.MATCH_NO_OPTIONS), new TestOptionsItem("en@calendar=chinese", "GUMMM", "MMM r(U)", DateTimePatternGenerator.MATCH_NO_OPTIONS), new TestOptionsItem("zh@calendar=chinese", "yyyy", "rU\u5E74", DateTimePatternGenerator.MATCH_NO_OPTIONS), // not a good result, want r(Y) or r(U)
    new TestOptionsItem("zh@calendar=chinese", "YYYY", "YY\u5E74", DateTimePatternGenerator.MATCH_NO_OPTIONS), new TestOptionsItem("zh@calendar=chinese", "U", "rU\u5E74", DateTimePatternGenerator.MATCH_NO_OPTIONS), new TestOptionsItem("zh@calendar=chinese", "Gy", "rU\u5E74", DateTimePatternGenerator.MATCH_NO_OPTIONS), new TestOptionsItem("zh@calendar=chinese", "GU", "rU\u5E74", DateTimePatternGenerator.MATCH_NO_OPTIONS), new TestOptionsItem("zh@calendar=chinese", "ULLL", "U\u5E74MMM", DateTimePatternGenerator.MATCH_NO_OPTIONS), new TestOptionsItem("zh@calendar=chinese", "yMMM", "rU\u5E74MMM", DateTimePatternGenerator.MATCH_NO_OPTIONS), new TestOptionsItem("zh@calendar=chinese", "GUMMM", "rU\u5E74MMM", DateTimePatternGenerator.MATCH_NO_OPTIONS) };
    for (int i = 0; i < testOptionsData.length; ++i) {
        ULocale uloc = new ULocale(testOptionsData[i].locale);
        DateTimePatternGenerator dtpgen = DateTimePatternGenerator.getInstance(uloc);
        String pattern = dtpgen.getBestPattern(testOptionsData[i].skeleton, testOptionsData[i].options);
        if (pattern.compareTo(testOptionsData[i].expectedPattern) != 0) {
            errln("Locale " + testOptionsData[i].locale + ", skeleton " + testOptionsData[i].skeleton + ", options " + ((testOptionsData[i].options != 0) ? "!=0" : "==0") + ", expected pattern " + testOptionsData[i].expectedPattern + ", got " + pattern);
        }
    }
}
Also used : ULocale(android.icu.util.ULocale) DateTimePatternGenerator(android.icu.text.DateTimePatternGenerator) Test(org.junit.Test)

Example 28 with DateTimePatternGenerator

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

the class DateTimeGeneratorTest method TestFreezeAndCloneAsThawed.

/* Tests the method
     *    public Object freeze()
     *    public Object cloneAsThawed()
     */
@Test
public void TestFreezeAndCloneAsThawed() {
    DateTimePatternGenerator dtpg = DateTimePatternGenerator.getInstance();
    if (dtpg.isFrozen() != false) {
        errln("DateTimePatternGenerator.isFrozen() is suppose to return false " + "for a DateTimePatternGenerator object that was just " + "created.");
    }
    dtpg.freeze();
    if (dtpg.isFrozen() != true) {
        errln("DateTimePatternGenerator.isFrozen() is suppose to return true " + "for a DateTimePatternGenerator object that was just " + "created and freeze.");
    }
    DateTimePatternGenerator dtpg2 = dtpg.cloneAsThawed();
    if (dtpg.isFrozen() != false) {
        errln("DateTimePatternGenerator.isFrozen() is suppose to return false " + "for a DateTimePatternGenerator object that was just " + "clone as thawed.");
    }
    if (dtpg2.isFrozen() != false) {
        errln("DateTimePatternGenerator.isFrozen() is suppose to return false " + "for a second DateTimePatternGenerator object that was just " + "clone as thawed.");
    }
}
Also used : DateTimePatternGenerator(android.icu.text.DateTimePatternGenerator) Test(org.junit.Test)

Aggregations

DateTimePatternGenerator (android.icu.text.DateTimePatternGenerator)28 Test (org.junit.Test)27 SimpleDateFormat (android.icu.text.SimpleDateFormat)6 ULocale (android.icu.util.ULocale)6 SimpleTimeZone (android.icu.util.SimpleTimeZone)3 TimeZone (android.icu.util.TimeZone)3 Date (java.util.Date)3 LinkedHashSet (java.util.LinkedHashSet)2 Calendar (android.icu.util.Calendar)1 GregorianCalendar (android.icu.util.GregorianCalendar)1 ParsePosition (java.text.ParsePosition)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1