Search in sources :

Example 6 with SimpleTimeZone

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

the class DERUTCTime method getAdjustedDate.

/**
     * return the time as an adjusted date
     * in the range of 1950 - 2049.
     *
     * @return a date in the range of 1950 to 2049.
     * @exception ParseException if the date string cannot be parsed.
     */
public Date getAdjustedDate() throws ParseException {
    SimpleDateFormat dateF = new SimpleDateFormat("yyyyMMddHHmmssz");
    dateF.setTimeZone(new SimpleTimeZone(0, "Z"));
    return dateF.parse(getAdjustedTime());
}
Also used : SimpleTimeZone(java.util.SimpleTimeZone) SimpleDateFormat(java.text.SimpleDateFormat)

Example 7 with SimpleTimeZone

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

the class SimpleDateFormat method parseTimeZone.

private int parseTimeZone(String string, int offset) {
    boolean foundGMT = string.regionMatches(offset, "GMT", 0, 3);
    if (foundGMT) {
        offset += 3;
    }
    char sign;
    if (offset < string.length() && ((sign = string.charAt(offset)) == '+' || sign == '-')) {
        ParsePosition position = new ParsePosition(offset + 1);
        Number result = numberFormat.parse(string, position);
        if (result == null) {
            return -position.getErrorIndex() - 1;
        }
        int hour = result.intValue();
        int raw = hour * 3600000;
        int index = position.getIndex();
        if (index < string.length() && string.charAt(index) == ':') {
            position.setIndex(index + 1);
            result = numberFormat.parse(string, position);
            if (result == null) {
                return -position.getErrorIndex() - 1;
            }
            int minute = result.intValue();
            raw += minute * 60000;
        } else if (hour >= 24) {
            raw = (hour / 100 * 3600000) + (hour % 100 * 60000);
        }
        if (sign == '-') {
            raw = -raw;
        }
        calendar.setTimeZone(new SimpleTimeZone(raw, ""));
        return position.getIndex();
    }
    if (foundGMT) {
        calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
        return offset;
    }
    for (String[] row : formatData.internalZoneStrings()) {
        for (int i = TimeZoneNames.LONG_NAME; i < TimeZoneNames.NAME_COUNT; ++i) {
            if (row[i] == null) {
                // above, so we can just ignore these cases. http://b/8128460.
                continue;
            }
            if (string.regionMatches(true, offset, row[i], 0, row[i].length())) {
                TimeZone zone = TimeZone.getTimeZone(row[TimeZoneNames.OLSON_NAME]);
                if (zone == null) {
                    return -offset - 1;
                }
                int raw = zone.getRawOffset();
                if (i == TimeZoneNames.LONG_NAME_DST || i == TimeZoneNames.SHORT_NAME_DST) {
                    // Not all time zones use a one-hour difference, so we need to query
                    // the TimeZone. (Australia/Lord_Howe is the usual example of this.)
                    int dstSavings = zone.getDSTSavings();
                    // the past. In that case, assume the default.
                    if (dstSavings == 0) {
                        // TODO: we should change this to use TimeZone.getOffset(long),
                        // but that requires the complete date to be parsed first.
                        dstSavings = 3600000;
                    }
                    raw += dstSavings;
                }
                calendar.setTimeZone(new SimpleTimeZone(raw, ""));
                return offset + row[i].length();
            }
        }
    }
    return -offset - 1;
}
Also used : TimeZone(java.util.TimeZone) SimpleTimeZone(java.util.SimpleTimeZone) SimpleTimeZone(java.util.SimpleTimeZone)

Example 8 with SimpleTimeZone

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

the class OldSimpleDateFormatTest method testFormattingTimezones.

public void testFormattingTimezones() {
    FormatTester test = new FormatTester();
    Calendar cal = new GregorianCalendar(1999, Calendar.JUNE, 2, 15, 3, 6);
    TimeZone tz0001 = new SimpleTimeZone(60000, "ONE MINUTE");
    TimeZone tz0130 = new SimpleTimeZone(5400000, "ONE HOUR, THIRTY");
    TimeZone tzMinus0130 = new SimpleTimeZone(-5400000, "NEG ONE HOUR, THIRTY");
    format.setTimeZone(tz0001);
    test.test(" Z", cal, " +0001", DateFormat.TIMEZONE_FIELD);
    test.test(" ZZZZ", cal, " GMT+00:01", DateFormat.TIMEZONE_FIELD);
    test.test(" ZZZZZ", cal, " +00:01", DateFormat.TIMEZONE_FIELD);
    format.setTimeZone(tz0130);
    test.test(" Z", cal, " +0130", DateFormat.TIMEZONE_FIELD);
    format.setTimeZone(tzMinus0130);
    test.test(" Z", cal, " -0130", DateFormat.TIMEZONE_FIELD);
    format.setTimeZone(tz0001);
    test.test(" z", cal, " GMT+00:01", DateFormat.TIMEZONE_FIELD);
    test.test(" zzzz", cal, " GMT+00:01", DateFormat.TIMEZONE_FIELD);
    format.setTimeZone(tz0130);
    test.test(" z", cal, " GMT+01:30", DateFormat.TIMEZONE_FIELD);
    format.setTimeZone(tzMinus0130);
    test.test(" z", cal, " GMT-01:30", DateFormat.TIMEZONE_FIELD);
    format.setTimeZone(TimeZone.getTimeZone("America/New_York"));
    test.test(" z", cal, " EDT", DateFormat.TIMEZONE_FIELD);
    Calendar temp2 = new GregorianCalendar(1999, Calendar.JANUARY, 12);
    test.test(" z", temp2, " EST", DateFormat.TIMEZONE_FIELD);
    test.test(" zz", cal, " EDT", DateFormat.TIMEZONE_FIELD);
    test.test(" zzz", cal, " EDT", DateFormat.TIMEZONE_FIELD);
    test.test(" zzzz", cal, " Eastern Daylight Time", DateFormat.TIMEZONE_FIELD);
    test.test(" zzzz", temp2, " Eastern Standard Time", DateFormat.TIMEZONE_FIELD);
    test.test(" zzzzz", cal, " Eastern Daylight Time", DateFormat.TIMEZONE_FIELD);
    assertFalse(test.testsFailed);
}
Also used : TimeZone(java.util.TimeZone) SimpleTimeZone(java.util.SimpleTimeZone) SimpleTimeZone(java.util.SimpleTimeZone) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar)

Example 9 with SimpleTimeZone

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

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 10 with SimpleTimeZone

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

the class SimpleTimeZoneTest method test_ConstructorILjava_lang_StringIIIIIIIIIII.

/**
     * java.util.SimpleTimeZone#SimpleTimeZone(int, java.lang.String,
     *        int, int, int, int, int, int, int, int, int, int, int)
     */
public void test_ConstructorILjava_lang_StringIIIIIIIIIII() {
    // Test for method java.util.SimpleTimeZone(int, java.lang.String, int,
    // int, int, int, int, int, int, int, int, int, int)
    // TODO : Implement test
    //Regression for HARMONY-1241
    assertNotNull(new SimpleTimeZone(TimeZone.LONG, "Europe/Paris", SimpleTimeZone.STANDARD_TIME, SimpleTimeZone.STANDARD_TIME, SimpleTimeZone.UTC_TIME, SimpleTimeZone.WALL_TIME, SimpleTimeZone.WALL_TIME, TimeZone.SHORT, SimpleTimeZone.STANDARD_TIME, TimeZone.LONG, SimpleTimeZone.UTC_TIME, SimpleTimeZone.STANDARD_TIME, TimeZone.LONG));
    //seems RI doesn't check the startTimeMode and endTimeMode at all
    //this behavior is contradicts with spec
    assertNotNull(new SimpleTimeZone(TimeZone.LONG, "Europe/Paris", SimpleTimeZone.STANDARD_TIME, SimpleTimeZone.STANDARD_TIME, SimpleTimeZone.UTC_TIME, SimpleTimeZone.WALL_TIME, Integer.MAX_VALUE, TimeZone.SHORT, SimpleTimeZone.STANDARD_TIME, TimeZone.LONG, SimpleTimeZone.UTC_TIME, Integer.MIN_VALUE, TimeZone.LONG));
    try {
        new SimpleTimeZone(1000, "TEST", 12, 1, Calendar.SUNDAY, 0, Integer.MAX_VALUE, Calendar.NOVEMBER, -1, Calendar.SUNDAY, 0, Integer.MAX_VALUE, 1000 * 60 * 60);
        fail("IllegalArgumentException expected");
    } catch (IllegalArgumentException e) {
    //expected
    }
    try {
        new SimpleTimeZone(1000, "TEST", Calendar.NOVEMBER, 10, Calendar.SUNDAY, 0, Integer.MAX_VALUE, Calendar.NOVEMBER, -1, Calendar.SUNDAY, 0, Integer.MAX_VALUE, 1000 * 60 * 60);
        fail("IllegalArgumentException expected");
    } catch (IllegalArgumentException e) {
    //expected
    }
    try {
        new SimpleTimeZone(1000, "TEST", Calendar.NOVEMBER, 1, 10, 0, Calendar.NOVEMBER, Integer.MAX_VALUE, -1, Calendar.SUNDAY, 0, Integer.MAX_VALUE, 1000 * 60 * 60);
        fail("IllegalArgumentException expected");
    } catch (IllegalArgumentException e) {
    //expected
    }
    try {
        new SimpleTimeZone(1000, "TEST", Calendar.DECEMBER, 1, Calendar.SUNDAY, 0, Calendar.NOVEMBER, Integer.MAX_VALUE, -10, Calendar.SUNDAY, 0, Integer.MAX_VALUE, 1000 * 60 * 60);
        fail("IllegalArgumentException expected");
    } catch (IllegalArgumentException e) {
    //expected
    }
}
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