Search in sources :

Example 1 with DateIntervalInfo

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

the class DateIntervalFormatTest method TestSetIntervalPatternNoSideEffect.

@Test
public void TestSetIntervalPatternNoSideEffect() {
    PatternInfo patternInfo = new DateIntervalInfo(ULocale.ENGLISH).getIntervalPattern("yMd", Calendar.DATE);
    String expectedPattern = patternInfo.getFirstPart() + patternInfo.getSecondPart();
    new DateIntervalInfo(ULocale.ENGLISH).setIntervalPattern("yMd", Calendar.DATE, "M/d/y \u2013 d");
    patternInfo = new DateIntervalInfo(ULocale.ENGLISH).getIntervalPattern("yMd", Calendar.DATE);
    String actualPattern = patternInfo.getFirstPart() + patternInfo.getSecondPart();
    assertEquals("setIntervalPattern should not have side effects", expectedPattern, actualPattern);
}
Also used : DateIntervalInfo(android.icu.text.DateIntervalInfo) PatternInfo(android.icu.text.DateIntervalInfo.PatternInfo) Test(org.junit.Test)

Example 2 with DateIntervalInfo

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

the class DateIntervalFormatTest method TestDateIntervalFormatCoverage.

@Test
public void TestDateIntervalFormatCoverage() throws Exception {
    long date1 = 1299090600000L;
    long date2 = 1299115800000L;
    DateInterval dtitv = new DateInterval(date1, date2);
    DateIntervalFormat dtitvfmt = DateIntervalFormat.getInstance("MMMd", Locale.ENGLISH);
    DateIntervalInfo dtintinf = new DateIntervalInfo(ULocale.ENGLISH);
    // Check the default private constructor
    checkDefaultPrivateConstructor(DateIntervalFormat.class);
    // Check clone
    DateIntervalFormat dtitvfmtClone = (DateIntervalFormat) dtitvfmt.clone();
    assertEquals("DateIntervalFormat.clone() failed", dtitvfmt.format(dtitv), dtitvfmtClone.format(dtitv));
    // Coverage for getInstance
    assertNotNull("Expected DateIntervalFormat object", DateIntervalFormat.getInstance("MMMd", dtintinf));
    assertNotNull("Expected DateIntervalFormat object", DateIntervalFormat.getInstance("MMMdHHmm", Locale.ENGLISH, dtintinf));
    // Coverage for parseObject. Exception expected.
    try {
        dtitvfmt.parseObject("", new ParsePosition(0));
        errln("Exception was expected when calling DateIntervalFormat.parseObject()");
    } catch (Exception e) {
    /* No op */
    }
    // Check getPatterns()
    Output<String> secondPart = new Output<String>();
    Calendar fromCalendar = Calendar.getInstance(Locale.ENGLISH);
    fromCalendar.set(2016, 5, 22);
    Calendar toCalendar = Calendar.getInstance(Locale.ENGLISH);
    toCalendar.set(2016, 5, 23);
    assertEquals("Date interval pattern mismatch.", dtitvfmt.getPatterns(fromCalendar, toCalendar, secondPart), "MMM d – ");
    assertEquals("Date interval pattern mismatch.", secondPart.value, "d");
}
Also used : DateIntervalInfo(android.icu.text.DateIntervalInfo) Output(android.icu.util.Output) Calendar(android.icu.util.Calendar) DateIntervalFormat(android.icu.text.DateIntervalFormat) DateInterval(android.icu.util.DateInterval) ParseException(java.text.ParseException) ParsePosition(java.text.ParsePosition) Test(org.junit.Test)

Example 3 with DateIntervalInfo

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

the class DateIntervalFormatTest method TestClone.

/* Tests the method
     *      public boolean clone()
     */
@Test
public void TestClone() {
    DateIntervalInfo dii = new DateIntervalInfo(new ULocale("en_US"));
    DateIntervalInfo dii_clone = (DateIntervalInfo) dii.clone();
    dii_clone.freeze();
    // Tests when "if ( frozen )" is true
    if (!dii.equals(dii_clone)) {
        errln("DateIntervalInfo.clone() is suppose to return true for " + "an original DateIntervalInfo object and a clone of the " + "original DateIntervalInfo object.");
    }
}
Also used : ULocale(android.icu.util.ULocale) DateIntervalInfo(android.icu.text.DateIntervalInfo) Test(org.junit.Test)

Example 4 with DateIntervalInfo

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

the class DateIntervalFormatTest method TestSetIntervalPattern.

/* Tests the method
     *      public void setIntervalPattern(String skeleton, int lrgDiffCalUnit, String intervalPattern)
     */
@Test
public void TestSetIntervalPattern() {
    DateIntervalInfo dii = new DateIntervalInfo();
    // Tests when "if ( frozen )" is true
    try {
        dii.freeze();
        dii.setIntervalPattern("", 0, "");
        errln("DateIntervalInfo.setIntervalPattern(String,int,String) " + "was suppose to return an exception when the " + "DateIntervalInfo object is frozen.");
    } catch (Exception e) {
    }
    // MINIMUM_SUPPORTED_CALENDAR_FIELD = Calendar.SECOND;
    try {
        dii = (DateIntervalInfo) dii.cloneAsThawed();
        dii.setIntervalPattern("", Calendar.SECOND + 1, "");
        errln("DateIntervalInfo.setIntervalPattern(String,int,String) " + "was suppose to return an exception when the " + "variable 'lrgDiffCalUnit' is greater than " + "MINIMUM_SUPPORTED_CALENDAR_FIELD.");
    } catch (Exception e) {
    }
}
Also used : DateIntervalInfo(android.icu.text.DateIntervalInfo) ParseException(java.text.ParseException) Test(org.junit.Test)

Example 5 with DateIntervalInfo

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

the class DateIntervalFormatTest method testGetInstance_String_DateIntervalInfo.

@Test
public void testGetInstance_String_DateIntervalInfo() {
    DateIntervalInfo dateIntervalInfo = new DateIntervalInfo(new ULocale("ca"));
    DateIntervalFormat dateIntervalFormat = DateIntervalFormat.getInstance(DateFormat.YEAR_MONTH, Locale.ENGLISH, dateIntervalInfo);
    Calendar from = Calendar.getInstance();
    from.set(2000, Calendar.JANUARY, 1, 12, 0);
    Calendar to = Calendar.getInstance();
    to.set(2001, Calendar.FEBRUARY, 1, 12, 0);
    DateInterval interval = new DateInterval(from.getTimeInMillis(), to.getTimeInMillis());
    dateIntervalFormat.setTimeZone(from.getTimeZone());
    // Month names are default (English), format is Catalan
    assertEquals("Wrong date interval", "January de 2000 – February de 2001", dateIntervalFormat.format(interval));
}
Also used : ULocale(android.icu.util.ULocale) DateIntervalInfo(android.icu.text.DateIntervalInfo) Calendar(android.icu.util.Calendar) DateIntervalFormat(android.icu.text.DateIntervalFormat) DateInterval(android.icu.util.DateInterval) Test(org.junit.Test)

Aggregations

DateIntervalInfo (android.icu.text.DateIntervalInfo)17 Test (org.junit.Test)15 DateIntervalFormat (android.icu.text.DateIntervalFormat)9 ULocale (android.icu.util.ULocale)8 Calendar (android.icu.util.Calendar)7 ParseException (java.text.ParseException)7 DateInterval (android.icu.util.DateInterval)6 FieldPosition (java.text.FieldPosition)4 SimpleDateFormat (android.icu.text.SimpleDateFormat)3 DateFormat (android.icu.text.DateFormat)2 PatternInfo (android.icu.text.DateIntervalInfo.PatternInfo)2 Date (java.util.Date)2 Output (android.icu.util.Output)1 ParsePosition (java.text.ParsePosition)1