Search in sources :

Example 16 with SimpleTimeZone

use of java.util.SimpleTimeZone in project robovm by robovm.

the class SimpleTimeZoneTest method test_getOffsetJ.

public void test_getOffsetJ() {
    Calendar cal = Calendar.getInstance();
    cal.set(1998, Calendar.NOVEMBER, 11, 0, 0);
    st1 = new SimpleTimeZone(TimeZone.getTimeZone("EST").getRawOffset(), "EST");
    assertTrue("Incorrect offset returned", st1.getOffset(cal.getTimeInMillis()) == -(5 * 60 * 60 * 1000));
    st1 = new SimpleTimeZone(TimeZone.getTimeZone("EST").getRawOffset(), "EST");
    cal.set(1998, Calendar.JUNE, 11, 0, 0);
    assertEquals("Incorrect offset returned", -(5 * 60 * 60 * 1000), st1.getOffset(cal.getTimeInMillis()));
    // Regression for HARMONY-5459
    st1 = new SimpleTimeZone(TimeZone.getDefault().getRawOffset(), TimeZone.getDefault().getID());
    int fourHours = 4 * 60 * 60 * 1000;
    st1.setRawOffset(fourHours);
    cal.set(2099, 01, 1, 0, 0);
    assertEquals(fourHours, st1.getOffset(cal.getTimeInMillis()));
}
Also used : SimpleTimeZone(java.util.SimpleTimeZone) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar)

Example 17 with SimpleTimeZone

use of java.util.SimpleTimeZone in project robovm by robovm.

the class SimpleTimeZoneTest method test_setStartRuleIII.

/**
     * java.util.SimpleTimeZone#setStartRule(int, int, int)
     */
public void test_setStartRuleIII() {
    // Test for method void java.util.SimpleTimeZone.setStartRule(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, 1);
    st.setEndRule(Calendar.DECEMBER, 1, 1);
    assertTrue("StartRule improperly set", st.useDaylightTime());
    assertTrue("StartRule improperly set", st.inDaylightTime((new GregorianCalendar(1998, Calendar.NOVEMBER, 13).getTime())));
    assertTrue("StartRule improperly set", !(st.inDaylightTime(new GregorianCalendar(1998, Calendar.OCTOBER, 13).getTime())));
    try {
        st.setStartRule(13, 20, 0);
        fail("IllegalArgumentException is not thrown.");
    } catch (IllegalArgumentException iae) {
    //expected
    }
    try {
        st.setStartRule(1, 32, 0);
        fail("IllegalArgumentException is not thrown.");
    } catch (IllegalArgumentException iae) {
    //expected
    }
    try {
        st.setStartRule(1, 30, 10);
        fail("IllegalArgumentException is not thrown.");
    } catch (IllegalArgumentException iae) {
    //expected
    }
}
Also used : SimpleTimeZone(java.util.SimpleTimeZone) GregorianCalendar(java.util.GregorianCalendar)

Example 18 with SimpleTimeZone

use of java.util.SimpleTimeZone in project XobotOS by xamarin.

the class DERGeneralizedTime method getDate.

public Date getDate() throws ParseException {
    SimpleDateFormat dateF;
    String d = time;
    if (time.endsWith("Z")) {
        if (hasFractionalSeconds()) {
            dateF = new SimpleDateFormat("yyyyMMddHHmmss.SSS'Z'");
        } else {
            dateF = new SimpleDateFormat("yyyyMMddHHmmss'Z'");
        }
        dateF.setTimeZone(new SimpleTimeZone(0, "Z"));
    } else if (time.indexOf('-') > 0 || time.indexOf('+') > 0) {
        d = this.getTime();
        if (hasFractionalSeconds()) {
            dateF = new SimpleDateFormat("yyyyMMddHHmmss.SSSz");
        } else {
            dateF = new SimpleDateFormat("yyyyMMddHHmmssz");
        }
        dateF.setTimeZone(new SimpleTimeZone(0, "Z"));
    } else {
        if (hasFractionalSeconds()) {
            dateF = new SimpleDateFormat("yyyyMMddHHmmss.SSS");
        } else {
            dateF = new SimpleDateFormat("yyyyMMddHHmmss");
        }
        dateF.setTimeZone(new SimpleTimeZone(0, TimeZone.getDefault().getID()));
    }
    if (hasFractionalSeconds()) {
        // java misinterprets extra digits as being milliseconds...
        String frac = d.substring(14);
        int index;
        for (index = 1; index < frac.length(); index++) {
            char ch = frac.charAt(index);
            if (!('0' <= ch && ch <= '9')) {
                break;
            }
        }
        if (index - 1 > 3) {
            frac = frac.substring(0, 4) + frac.substring(index);
            d = d.substring(0, 14) + frac;
        } else if (index - 1 == 1) {
            frac = frac.substring(0, index) + "00" + frac.substring(index);
            d = d.substring(0, 14) + frac;
        } else if (index - 1 == 2) {
            frac = frac.substring(0, index) + "0" + frac.substring(index);
            d = d.substring(0, 14) + frac;
        }
    }
    return dateF.parse(d);
}
Also used : SimpleTimeZone(java.util.SimpleTimeZone) SimpleDateFormat(java.text.SimpleDateFormat)

Example 19 with SimpleTimeZone

use of java.util.SimpleTimeZone in project robovm by robovm.

the class TimeZoneTest method testCustomTimeZoneDisplayNames.

// http://b/3049014
public void testCustomTimeZoneDisplayNames() {
    TimeZone tz0001 = new SimpleTimeZone(60000, "ONE MINUTE");
    TimeZone tz0130 = new SimpleTimeZone(5400000, "ONE HOUR, THIRTY");
    TimeZone tzMinus0130 = new SimpleTimeZone(-5400000, "NEG ONE HOUR, THIRTY");
    assertEquals("GMT+00:01", tz0001.getDisplayName(false, TimeZone.SHORT, Locale.US));
    assertEquals("GMT+01:30", tz0130.getDisplayName(false, TimeZone.SHORT, Locale.US));
    assertEquals("GMT-01:30", tzMinus0130.getDisplayName(false, TimeZone.SHORT, Locale.US));
}
Also used : TimeZone(java.util.TimeZone) SimpleTimeZone(java.util.SimpleTimeZone) SimpleTimeZone(java.util.SimpleTimeZone)

Example 20 with SimpleTimeZone

use of java.util.SimpleTimeZone in project jdk8u_jdk by JetBrains.

the class ZoneInfo method getOffsets.

private int getOffsets(long date, int[] offsets, int type) {
    // if dst is never observed, there is no transition.
    if (transitions == null) {
        int offset = getLastRawOffset();
        if (offsets != null) {
            offsets[0] = offset;
            offsets[1] = 0;
        }
        return offset;
    }
    date -= rawOffsetDiff;
    int index = getTransitionIndex(date, type);
    // FIXME: should support LMT.
    if (index < 0) {
        int offset = getLastRawOffset();
        if (offsets != null) {
            offsets[0] = offset;
            offsets[1] = 0;
        }
        return offset;
    }
    if (index < transitions.length) {
        long val = transitions[index];
        int offset = this.offsets[(int) (val & OFFSET_MASK)] + rawOffsetDiff;
        if (offsets != null) {
            int dst = (int) ((val >>> DST_NSHIFT) & 0xfL);
            int save = (dst == 0) ? 0 : this.offsets[dst];
            offsets[0] = offset - save;
            offsets[1] = save;
        }
        return offset;
    }
    // beyond the transitions, delegate to SimpleTimeZone if there
    // is a rule; otherwise, return rawOffset.
    SimpleTimeZone tz = getLastRule();
    if (tz != null) {
        int rawoffset = tz.getRawOffset();
        long msec = date;
        if (type != UTC_TIME) {
            msec -= rawOffset;
        }
        int dstoffset = tz.getOffset(msec) - rawOffset;
        // Check if it's in a standard-to-daylight transition.
        if (dstoffset > 0 && tz.getOffset(msec - dstoffset) == rawoffset) {
            dstoffset = 0;
        }
        if (offsets != null) {
            offsets[0] = rawoffset;
            offsets[1] = dstoffset;
        }
        return rawoffset + dstoffset;
    }
    int offset = getLastRawOffset();
    if (offsets != null) {
        offsets[0] = offset;
        offsets[1] = 0;
    }
    return offset;
}
Also used : SimpleTimeZone(java.util.SimpleTimeZone)

Aggregations

SimpleTimeZone (java.util.SimpleTimeZone)163 TimeZone (java.util.TimeZone)53 SimpleDateFormat (java.text.SimpleDateFormat)47 GregorianCalendar (java.util.GregorianCalendar)43 Date (java.util.Date)38 Calendar (java.util.Calendar)19 Test (org.junit.Test)16 DateFormat (java.text.DateFormat)8 File (java.io.File)5 NativeTimeZoneTest.isNativeTimeZone (com.google.j2objc.util.NativeTimeZoneTest.isNativeTimeZone)4 IOException (java.io.IOException)4 BasicDBObject (com.mongodb.BasicDBObject)3 InvalidObjectException (java.io.InvalidObjectException)3 Timestamp (java.sql.Timestamp)3 ParsePosition (java.text.ParsePosition)3 COSString (org.apache.pdfbox.cos.COSString)3 Support_TimeZone (tests.support.Support_TimeZone)3 DBRef (com.mongodb.DBRef)2 MessageFormat (java.text.MessageFormat)2 ParseException (java.text.ParseException)2