Search in sources :

Example 21 with SimpleTimeZone

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

the class SimpleDateFormat method readObject.

/**
     * After reading an object from the input stream, the format
     * pattern in the object is verified.
     * <p>
     * @exception InvalidObjectException if the pattern is invalid
     */
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
    stream.defaultReadObject();
    try {
        compiledPattern = compile(pattern);
    } catch (Exception e) {
        throw new InvalidObjectException("invalid pattern");
    }
    if (serialVersionOnStream < 1) {
        // didn't have defaultCenturyStart field
        initializeDefaultCentury();
    } else {
        // fill in dependent transient field
        parseAmbiguousDatesAsAfter(defaultCenturyStart);
    }
    serialVersionOnStream = currentSerialVersion;
    // If the deserialized object has a SimpleTimeZone, try
    // to replace it with a ZoneInfo equivalent in order to
    // be compatible with the SimpleTimeZone-based
    // implementation as much as possible.
    TimeZone tz = getTimeZone();
    if (tz instanceof SimpleTimeZone) {
        String id = tz.getID();
        TimeZone zi = TimeZone.getTimeZone(id);
        if (zi != null && zi.hasSameRules(tz) && zi.getID().equals(id)) {
            setTimeZone(zi);
        }
    }
}
Also used : TimeZone(java.util.TimeZone) SimpleTimeZone(java.util.SimpleTimeZone) SimpleTimeZone(java.util.SimpleTimeZone) InvalidObjectException(java.io.InvalidObjectException) IOException(java.io.IOException) InvalidObjectException(java.io.InvalidObjectException)

Example 22 with SimpleTimeZone

use of java.util.SimpleTimeZone in project joda-time by JodaOrg.

the class TestLocalDateTime_Basics method testToDate_springDST_2Hour40Savings.

public void testToDate_springDST_2Hour40Savings() {
    LocalDateTime base = new LocalDateTime(2007, 4, 2, 0, 20, 0, 0);
    SimpleTimeZone testZone = new SimpleTimeZone(3600000, "NoMidnight", Calendar.APRIL, 2, 0, 0, Calendar.OCTOBER, 2, 0, 3600000, (3600000 / 6) * 16);
    TimeZone currentZone = TimeZone.getDefault();
    try {
        TimeZone.setDefault(testZone);
        Date test = base.toDate();
        check(base, 2007, 4, 2, 0, 20, 0, 0);
        assertEquals("Mon Apr 02 02:40:00 GMT+03:40 2007", test.toString());
    } finally {
        TimeZone.setDefault(currentZone);
    }
}
Also used : TimeZone(java.util.TimeZone) SimpleTimeZone(java.util.SimpleTimeZone) SimpleTimeZone(java.util.SimpleTimeZone) Date(java.util.Date)

Example 23 with SimpleTimeZone

use of java.util.SimpleTimeZone in project joda-time by JodaOrg.

the class TestLocalDateTime_Basics method testToDate_springDST.

public void testToDate_springDST() {
    LocalDateTime base = new LocalDateTime(2007, 4, 2, 0, 20, 0, 0);
    SimpleTimeZone testZone = new SimpleTimeZone(3600000, "NoMidnight", Calendar.APRIL, 2, 0, 0, Calendar.OCTOBER, 2, 0, 3600000);
    TimeZone currentZone = TimeZone.getDefault();
    try {
        TimeZone.setDefault(testZone);
        Date test = base.toDate();
        check(base, 2007, 4, 2, 0, 20, 0, 0);
        assertEquals("Mon Apr 02 01:00:00 GMT+02:00 2007", test.toString());
    } finally {
        TimeZone.setDefault(currentZone);
    }
}
Also used : TimeZone(java.util.TimeZone) SimpleTimeZone(java.util.SimpleTimeZone) SimpleTimeZone(java.util.SimpleTimeZone) Date(java.util.Date)

Example 24 with SimpleTimeZone

use of java.util.SimpleTimeZone in project joda-time by JodaOrg.

the class TestLocalDateTime_Basics method testToDate_autumnDST_Zone.

public void testToDate_autumnDST_Zone() {
    LocalDateTime base = new LocalDateTime(2007, 10, 2, 0, 20, 30, 0);
    SimpleTimeZone testZone = new SimpleTimeZone(3600000, "NoMidnight", Calendar.APRIL, 2, 0, 0, Calendar.OCTOBER, 2, 0, 3600000);
    TimeZone currentZone = TimeZone.getDefault();
    try {
        TimeZone.setDefault(testZone);
        Date test = base.toDate(TimeZone.getDefault());
        check(base, 2007, 10, 2, 0, 20, 30, 0);
        assertEquals("Tue Oct 02 00:20:30 GMT+02:00 2007", test.toString());
    } finally {
        TimeZone.setDefault(currentZone);
    }
}
Also used : TimeZone(java.util.TimeZone) SimpleTimeZone(java.util.SimpleTimeZone) SimpleTimeZone(java.util.SimpleTimeZone) Date(java.util.Date)

Example 25 with SimpleTimeZone

use of java.util.SimpleTimeZone in project joda-time by JodaOrg.

the class TestLocalDateTime_Basics method testToDate_springDST_Zone.

public void testToDate_springDST_Zone() {
    LocalDateTime base = new LocalDateTime(2007, 4, 2, 0, 20, 0, 0);
    SimpleTimeZone testZone = new SimpleTimeZone(3600000, "NoMidnight", Calendar.APRIL, 2, 0, 0, Calendar.OCTOBER, 2, 0, 3600000);
    TimeZone currentZone = TimeZone.getDefault();
    try {
        TimeZone.setDefault(testZone);
        Date test = base.toDate(TimeZone.getDefault());
        check(base, 2007, 4, 2, 0, 20, 0, 0);
        assertEquals("Mon Apr 02 01:00:00 GMT+02:00 2007", test.toString());
    } finally {
        TimeZone.setDefault(currentZone);
    }
}
Also used : TimeZone(java.util.TimeZone) SimpleTimeZone(java.util.SimpleTimeZone) SimpleTimeZone(java.util.SimpleTimeZone) Date(java.util.Date)

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