Search in sources :

Example 41 with GregorianCalendar

use of java.util.GregorianCalendar in project j2objc by google.

the class SimpleTimeZoneTest method test_ConstructorILjava_lang_StringIIIIIIIII.

/**
     * java.util.SimpleTimeZone#SimpleTimeZone(int, java.lang.String,
     *        int, int, int, int, int, int, int, int, int)
     */
public void test_ConstructorILjava_lang_StringIIIIIIIII() {
    // Test for method java.util.SimpleTimeZone(int, java.lang.String, int,
    // int, int, int, int, int, int, int, int)
    SimpleTimeZone st = new SimpleTimeZone(1000, "TEST", Calendar.NOVEMBER, 1, Calendar.SUNDAY, 0, Calendar.NOVEMBER, -1, Calendar.SUNDAY, 0, 1000 * 60 * 60);
    assertTrue("Incorrect TZ constructed", st.inDaylightTime(new GregorianCalendar(1998, Calendar.NOVEMBER, 13).getTime()));
    assertTrue("Incorrect TZ constructed", !(st.inDaylightTime(new GregorianCalendar(1998, Calendar.OCTOBER, 13).getTime())));
    assertEquals("Incorrect TZ constructed", "TEST", st.getID());
    assertEquals("Incorrect TZ constructed", 1000, st.getRawOffset());
    assertTrue("Incorrect TZ constructed", st.useDaylightTime());
    assertTrue("Incorrect TZ constructed", st.getDSTSavings() == 1000 * 60 * 60);
    try {
        new SimpleTimeZone(1000, "TEST", 12, 1, Calendar.SUNDAY, 0, Calendar.NOVEMBER, -1, Calendar.SUNDAY, 0, 1000 * 60 * 60);
        fail("IllegalArgumentException expected");
    } catch (IllegalArgumentException e) {
    //expected
    }
    try {
        new SimpleTimeZone(1000, "TEST", Calendar.NOVEMBER, 10, Calendar.SUNDAY, 0, Calendar.NOVEMBER, -1, Calendar.SUNDAY, 0, 1000 * 60 * 60);
        fail("IllegalArgumentException expected");
    } catch (IllegalArgumentException e) {
    //expected
    }
    try {
        new SimpleTimeZone(1000, "TEST", Calendar.NOVEMBER, 1, 10, 0, Calendar.NOVEMBER, -1, Calendar.SUNDAY, 0, 1000 * 60 * 60);
        fail("IllegalArgumentException expected");
    } catch (IllegalArgumentException e) {
    //expected
    }
    try {
        new SimpleTimeZone(1000, "TEST", Calendar.DECEMBER, 1, Calendar.SUNDAY, 0, Calendar.NOVEMBER, -10, Calendar.SUNDAY, 0, 1000 * 60 * 60);
        fail("IllegalArgumentException expected");
    } catch (IllegalArgumentException e) {
    //expected
    }
}
Also used : SimpleTimeZone(java.util.SimpleTimeZone) GregorianCalendar(java.util.GregorianCalendar)

Example 42 with GregorianCalendar

use of java.util.GregorianCalendar in project j2objc by google.

the class SimpleTimeZoneTest method test_setEndRuleIII.

/**
     * java.util.SimpleTimeZone#setEndRule(int, int, int)
     */
public void test_setEndRuleIII() {
    SimpleTimeZone st = new SimpleTimeZone(1000, "Test_TZ");
    st.setStartRule(Calendar.NOVEMBER, 1, 0);
    st.setEndRule(Calendar.NOVEMBER, 20, 0);
    assertTrue("StartRule improperly set1", st.useDaylightTime());
    assertTrue("StartRule improperly set2", st.inDaylightTime(new GregorianCalendar(1998, Calendar.NOVEMBER, 13).getTime()));
    assertTrue("StartRule improperly set3", !(st.inDaylightTime(new GregorianCalendar(1998, Calendar.OCTOBER, 13).getTime())));
    try {
        st.setEndRule(13, 20, 0);
        fail("IllegalArgumentException is not thrown.");
    } catch (IllegalArgumentException iae) {
    //expected
    }
    try {
        st.setEndRule(1, 32, 0);
        fail("IllegalArgumentException is not thrown.");
    } catch (IllegalArgumentException iae) {
    //expected
    }
    try {
        st.setEndRule(1, 30, 10);
        fail("IllegalArgumentException is not thrown.");
    } catch (IllegalArgumentException iae) {
    //expected
    }
}
Also used : SimpleTimeZone(java.util.SimpleTimeZone) GregorianCalendar(java.util.GregorianCalendar)

Example 43 with GregorianCalendar

use of java.util.GregorianCalendar in project j2objc by google.

the class GregorianCalendarTest method test_ConstructorLjava_util_TimeZoneLjava_util_Locale.

/**
     * java.util.GregorianCalendar#GregorianCalendar(java.util.TimeZone,
     *java.util.Locale)
     */
public void test_ConstructorLjava_util_TimeZoneLjava_util_Locale() {
    // Test for method java.util.GregorianCalendar(java.util.TimeZone,
    // java.util.Locale)
    Date date = new Date(2008, 1, 1);
    TimeZone.getDefault();
    GregorianCalendar gc1 = new GregorianCalendar(AMERICA_NEW_YORK, Locale.JAPAN);
    gc1.setTime(date);
    GregorianCalendar gc2 = new GregorianCalendar(AMERICA_NEW_YORK, Locale.JAPAN);
    gc2.setTime(date);
    GregorianCalendar gc3 = new GregorianCalendar(AMERICA_CHICAGO, Locale.ITALY);
    gc3.setTime(date);
    // Chicago is 1 hour before New York, add 1 to the Chicago time and convert to 0-12 value
    assertEquals("Incorrect calendar returned", gc1.get(Calendar.HOUR), ((gc3.get(Calendar.HOUR) + 1) % 12));
    assertTrue("Locales not created correctly", gc1.equals(gc2) && !gc1.equals(gc3));
}
Also used : GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date)

Example 44 with GregorianCalendar

use of java.util.GregorianCalendar in project j2objc by google.

the class GregorianCalendarTest method test_getGregorianChange.

/**
     * java.util.GregorianCalendar#getGregorianChange()
     */
public void test_getGregorianChange() {
    // Test for method java.util.Date
    // java.util.GregorianCalendar.getGregorianChange()
    GregorianCalendar gc = new GregorianCalendar();
    GregorianCalendar returnedChange = new GregorianCalendar(AMERICA_NEW_YORK);
    returnedChange.setTime(gc.getGregorianChange());
    assertEquals("Returned incorrect year", 1582, returnedChange.get(Calendar.YEAR));
    assertTrue("Returned incorrect month", returnedChange.get(Calendar.MONTH) == Calendar.OCTOBER);
    assertEquals("Returned incorrect day of month", 4, returnedChange.get(Calendar.DAY_OF_MONTH));
}
Also used : GregorianCalendar(java.util.GregorianCalendar)

Example 45 with GregorianCalendar

use of java.util.GregorianCalendar in project j2objc by google.

the class GregorianCalendarTest method test_getGreatestMinimumI.

/**
     * java.util.GregorianCalendar#getGreatestMinimum(int)
     */
public void test_getGreatestMinimumI() {
    // Test for method int
    // java.util.GregorianCalendar.getGreatestMinimum(int)
    GregorianCalendar gc = new GregorianCalendar();
    assertEquals("Wrong greatest minimum value for DAY_OF_MONTH", 1, gc.getGreatestMinimum(Calendar.DAY_OF_MONTH));
    assertTrue("Wrong greatest minimum value for MONTH", gc.getGreatestMinimum(Calendar.MONTH) == Calendar.JANUARY);
    assertEquals("Wrong greatest minimum value for HOUR_OF_DAY", 0, gc.getGreatestMinimum(Calendar.HOUR_OF_DAY));
    assertEquals("Wrong greatest minimum value for HOUR", 0, gc.getGreatestMinimum(Calendar.HOUR));
    BitSet result = new BitSet();
    int[] min = { 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, -46800000, 0 };
    for (int i = 0; i < min.length; i++) {
        if (gc.getGreatestMinimum(i) != min[i])
            result.set(i);
    }
    assertTrue("Wrong greatest min for " + result, result.length() == 0);
}
Also used : GregorianCalendar(java.util.GregorianCalendar) BitSet(java.util.BitSet)

Aggregations

GregorianCalendar (java.util.GregorianCalendar)1278 Calendar (java.util.Calendar)603 Date (java.util.Date)377 Test (org.junit.Test)247 SimpleDateFormat (java.text.SimpleDateFormat)104 Timestamp (java.sql.Timestamp)54 ScheduleExpression (javax.ejb.ScheduleExpression)51 ArrayList (java.util.ArrayList)48 EJBCronTrigger (org.apache.openejb.core.timer.EJBCronTrigger)42 HashMap (java.util.HashMap)41 ParseException (java.text.ParseException)39 TimeZone (java.util.TimeZone)38 SimpleTimeZone (java.util.SimpleTimeZone)35 BigDecimal (java.math.BigDecimal)32 Date (java.sql.Date)30 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)28 SQLException (java.sql.SQLException)20 DateFormat (java.text.DateFormat)18 IOException (java.io.IOException)16 Map (java.util.Map)16