Search in sources :

Example 56 with SimpleTimeZone

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

the class SimpleTimeZoneTest method test_setStartRuleIIII.

/**
     * java.util.SimpleTimeZone#setStartRule(int, int, int, int)
     */
public void test_setStartRuleIIII() {
    // Test for method void java.util.SimpleTimeZone.setStartRule(int, int,
    // int, int)
    SimpleTimeZone st = new SimpleTimeZone(1000, "Test_TZ");
    // Spec indicates that both end and start must be set or result is
    // undefined
    st.setStartRule(Calendar.NOVEMBER, 1, Calendar.SUNDAY, 0);
    st.setEndRule(Calendar.NOVEMBER, -1, Calendar.SUNDAY, 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.setStartRule(12, -1, Calendar.SUNDAY, 0);
        fail("IllegalArgumentException is not thrown.");
    } catch (IllegalArgumentException iae) {
    //expected
    }
    try {
        st.setStartRule(Calendar.NOVEMBER, 10, Calendar.SUNDAY, 0);
        fail("IllegalArgumentException is not thrown.");
    } catch (IllegalArgumentException iae) {
    //expected
    }
    try {
        st.setStartRule(Calendar.NOVEMBER, -1, 8, 0);
        fail("IllegalArgumentException is not thrown.");
    } catch (IllegalArgumentException iae) {
    //expected
    }
    try {
        st.setStartRule(Calendar.NOVEMBER, -1, Calendar.SUNDAY, -10);
        fail("IllegalArgumentException is not thrown.");
    } catch (IllegalArgumentException iae) {
    //expected
    }
}
Also used : SimpleTimeZone(java.util.SimpleTimeZone) GregorianCalendar(java.util.GregorianCalendar)

Example 57 with SimpleTimeZone

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

the class SimpleTimeZoneTest method test_setRawOffsetI.

/**
     * java.util.SimpleTimeZone#setRawOffset(int)
     */
public void test_setRawOffsetI() {
    // Test for method void java.util.SimpleTimeZone.setRawOffset(int)
    st1 = new SimpleTimeZone(TimeZone.getTimeZone("EST").getRawOffset(), "EST");
    int off = st1.getRawOffset();
    st1.setRawOffset(1000);
    boolean val = st1.getRawOffset() == 1000;
    st1.setRawOffset(off);
    assertTrue("Incorrect offset set", val);
}
Also used : SimpleTimeZone(java.util.SimpleTimeZone)

Example 58 with SimpleTimeZone

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

the class SimpleTimeZoneTest method test_setStartRuleIIIIZ.

/**
     * java.util.SimpleTimeZone#setStartRule(int, int, int, int, boolean)
     */
public void test_setStartRuleIIIIZ() {
    TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
    // Test for method void java.util.SimpleTimeZone.setStartRule(int, int,
    // int, int, boolean)
    SimpleTimeZone st = new SimpleTimeZone(TimeZone.getTimeZone("EST").getRawOffset(), "EST");
    // Spec indicates that both end and start must be set or result is
    // undefined
    st.setStartRule(Calendar.NOVEMBER, 1, Calendar.SUNDAY, 1, true);
    st.setEndRule(Calendar.NOVEMBER, 15, Calendar.SUNDAY, 1, false);
    assertTrue("StartRule improperly set1", st.useDaylightTime());
    assertTrue("StartRule improperly set2", st.inDaylightTime((new GregorianCalendar(1999, Calendar.NOVEMBER, 7, 12, 0).getTime())));
    assertTrue("StartRule improperly set3", st.inDaylightTime((new GregorianCalendar(1999, Calendar.NOVEMBER, 13, 12, 0).getTime())));
    assertTrue("StartRule improperly set4", !(st.inDaylightTime(new GregorianCalendar(1999, Calendar.NOVEMBER, 6, 12, 0).getTime())));
    assertTrue("StartRule improperly set5", !(st.inDaylightTime(new GregorianCalendar(1999, Calendar.NOVEMBER, 14, 12, 0).getTime())));
    try {
        st.setStartRule(20, 15, Calendar.SUNDAY, 1, true);
        fail("IllegalArgumentException is not thrown.");
    } catch (IllegalArgumentException iae) {
    //expected
    }
    try {
        st.setStartRule(Calendar.NOVEMBER, 35, Calendar.SUNDAY, 1, true);
        fail("IllegalArgumentException is not thrown.");
    } catch (IllegalArgumentException iae) {
    //expected
    }
    try {
        st.setStartRule(Calendar.NOVEMBER, 15, 12, 1, true);
        fail("IllegalArgumentException is not thrown.");
    } catch (IllegalArgumentException iae) {
    //expected
    }
    try {
        st.setStartRule(Calendar.NOVEMBER, 15, Calendar.SUNDAY, -1, true);
        fail("IllegalArgumentException is not thrown.");
    } catch (IllegalArgumentException iae) {
    //expected
    }
}
Also used : SimpleTimeZone(java.util.SimpleTimeZone) GregorianCalendar(java.util.GregorianCalendar)

Example 59 with SimpleTimeZone

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

the class SimpleTimeZoneTest method test_getOffsetIIIIII.

/**
     * java.util.SimpleTimeZone#getOffset(int, int, int, int, int, int)
     */
public void test_getOffsetIIIIII() {
    // Test for method int java.util.SimpleTimeZone.getOffset(int, int, int,
    // int, int, int)
    //        TimeZone st1 = TimeZone.getTimeZone("EST");
    st1 = new SimpleTimeZone(TimeZone.getTimeZone("EST").getRawOffset(), "EST");
    assertTrue("Incorrect offset returned", st1.getOffset(GregorianCalendar.AD, 1998, Calendar.NOVEMBER, 11, Calendar.WEDNESDAY, 0) == -(5 * 60 * 60 * 1000));
    st1 = new SimpleTimeZone(TimeZone.getTimeZone("EST").getRawOffset(), "EST");
    assertEquals("Incorrect offset returned", -(5 * 60 * 60 * 1000), st1.getOffset(GregorianCalendar.AD, 1998, Calendar.JUNE, 11, Calendar.THURSDAY, 0));
    // Regression for HARMONY-5459
    st1 = new SimpleTimeZone(TimeZone.getDefault().getRawOffset(), TimeZone.getDefault().getID());
    int fourHours = 4 * 60 * 60 * 1000;
    st1.setRawOffset(fourHours);
    assertEquals(fourHours, st1.getOffset(1, 2099, 01, 1, 5, 0));
    try {
        st1.getOffset(-1, 2099, 01, 1, 5, 0);
        fail("IllegalArgumentException expected");
    } catch (IllegalArgumentException e) {
    //expected
    }
    try {
        st1.getOffset(1, 2099, 15, 1, 5, 0);
        fail("IllegalArgumentException expected");
    } catch (IllegalArgumentException e) {
    //expected
    }
    try {
        st1.getOffset(1, 2099, 01, 100, 5, 0);
        fail("IllegalArgumentException expected");
    } catch (IllegalArgumentException e) {
    //expected
    }
    try {
        st1.getOffset(1, 2099, 01, 1, 50, 0);
        fail("IllegalArgumentException expected");
    } catch (IllegalArgumentException e) {
    //expected
    }
    try {
        st1.getOffset(1, 2099, 01, 1, 5, -10);
        fail("IllegalArgumentException expected");
    } catch (IllegalArgumentException e) {
    //expected
    }
}
Also used : SimpleTimeZone(java.util.SimpleTimeZone)

Example 60 with SimpleTimeZone

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

the class SimpleTimeZoneTest method test_getRawOffset.

/**
     * java.util.SimpleTimeZone#getRawOffset()
     */
public void test_getRawOffset() {
    // Test for method int java.util.SimpleTimeZone.getRawOffset()
    st1 = new SimpleTimeZone(TimeZone.getTimeZone("EST").getRawOffset(), "EST");
    assertTrue("Incorrect offset returned", st1.getRawOffset() == -(5 * 60 * 60 * 1000));
}
Also used : SimpleTimeZone(java.util.SimpleTimeZone)

Aggregations

SimpleTimeZone (java.util.SimpleTimeZone)114 TimeZone (java.util.TimeZone)42 GregorianCalendar (java.util.GregorianCalendar)34 Date (java.util.Date)25 SimpleDateFormat (java.text.SimpleDateFormat)20 Calendar (java.util.Calendar)8 Test (org.junit.Test)7 BasicDBObject (com.mongodb.BasicDBObject)3 BSONTimestamp (org.bson.types.BSONTimestamp)3 Code (org.bson.types.Code)3 CodeWScope (org.bson.types.CodeWScope)3 ObjectId (org.bson.types.ObjectId)3 Support_TimeZone (tests.support.Support_TimeZone)3 DBRef (com.mongodb.DBRef)2 IOException (java.io.IOException)2 InvalidObjectException (java.io.InvalidObjectException)2 DateFormat (java.text.DateFormat)2 ParsePosition (java.text.ParsePosition)2 Binary (org.bson.types.Binary)2 MaxKey (org.bson.types.MaxKey)2