Package com.ibm.icu.util

Examples of com.ibm.icu.util.VTimeZone


            if (skipIfBeforeICU(4, 3, 1) && tzids[i].equals("Asia/Amman")) {
                // See #7008
                return;
            }
            BasicTimeZone olsontz = (BasicTimeZone)TimeZone.getTimeZone(tzids[i], TimeZone.TIMEZONE_ICU);
            VTimeZone vtz_org = VTimeZone.create(tzids[i]);
            vtz_org.setTZURL("http://source.icu-project.org/timezone");
            vtz_org.setLastModified(new Date());
            VTimeZone vtz_new = null;
            try {
                // Write out VTIMEZONE
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                OutputStreamWriter writer = new OutputStreamWriter(baos);
                vtz_org.write(writer);
                writer.close();
                byte[] vtzdata = baos.toByteArray();
                // Read VTIMEZONE
                ByteArrayInputStream bais = new ByteArrayInputStream(vtzdata);
                InputStreamReader reader = new InputStreamReader(bais);
                vtz_new = VTimeZone.create(reader);
                reader.close();

                // Write out VTIMEZONE one more time
                ByteArrayOutputStream baos1 = new ByteArrayOutputStream();
                OutputStreamWriter writer1 = new OutputStreamWriter(baos1);
                vtz_new.write(writer1);
                writer1.close();
                byte[] vtzdata1 = baos1.toByteArray();

                // Make sure VTIMEZONE data is exactly same with the first one
                if (vtzdata.length != vtzdata1.length) {
                    errln("FAIL: different VTIMEZONE data length");
                }
                for (int j = 0; j < vtzdata.length; j++) {
                    if (vtzdata[j] != vtzdata1[j]) {
                        errln("FAIL: different VTIMEZONE data");
                        break;
                    }
                }
            } catch (IOException ioe) {
                errln("FAIL: IO error while writing/reading VTIMEZONE data");
            }
            // Check equivalency after the first transition.
            // The DST information before the first transition might be lost
            // because there is no good way to represent the initial time with
            // VTIMEZONE.
            if (vtz_new.getOffset(startTime) != olsontz.getOffset(startTime)) {
                errln("FAIL: VTimeZone for " + tzids[i]
                         + " is not equivalent to its OlsonTimeZone corresponding at " + startTime);
            }
            TimeZoneTransition tzt = olsontz.getNextTransition(startTime, false);
            if (tzt != null) {
                if (!vtz_new.hasEquivalentTransitions(olsontz, tzt.getTime(), endTime, true)) {
                    errln("FAIL: VTimeZone for " + tzids[i] + " is not equivalent to its OlsonTimeZone corresponding.");
                }
                if (!vtz_new.hasEquivalentTransitions(olsontz, tzt.getTime(), endTime, false)) {
                    logln("VTimeZone for " + tzids[i] + " is not equivalent to its OlsonTimeZone corresponding in strict comparison mode.");
                }
            }
        }
    }
View Full Code Here


                if (skipIfBeforeICU(4, 3, 1) && tzids[i].equals("Asia/Amman")) {
                    // See #7008
                    return;
                }
                BasicTimeZone olsontz = (BasicTimeZone)TimeZone.getTimeZone(tzids[i], TimeZone.TIMEZONE_ICU);
                VTimeZone vtz_org = VTimeZone.create(tzids[i]);
                VTimeZone vtz_new = null;
                try {
                    // Write out VTIMEZONE
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    OutputStreamWriter writer = new OutputStreamWriter(baos);
                    vtz_org.write(writer, startTime);
                    writer.close();
                    byte[] vtzdata = baos.toByteArray();
                    // Read VTIMEZONE
                    ByteArrayInputStream bais = new ByteArrayInputStream(vtzdata);
                    InputStreamReader reader = new InputStreamReader(bais);
                    vtz_new = VTimeZone.create(reader);
                    reader.close();

                } catch (IOException ioe) {
                    errln("FAIL: IO error while writing/reading VTIMEZONE data");
                }
                // Check equivalency after the first transition.
                // The DST information before the first transition might be lost
                // because there is no good way to represent the initial time with
                // VTIMEZONE.
                if (vtz_new.getOffset(startTime) != olsontz.getOffset(startTime)) {
                    errln("FAIL: VTimeZone for " + tzids[i]
                             + " is not equivalent to its OlsonTimeZone corresponding at " + startTime);
                }
                TimeZoneTransition tzt = olsontz.getNextTransition(startTime, false);
                if (tzt != null) {
                    if (!vtz_new.hasEquivalentTransitions(olsontz, tzt.getTime(), endTime, true)) {
                        errln("FAIL: VTimeZone for " + tzids[i] + "(>=" + startTime + ") is not equivalent to its OlsonTimeZone corresponding.");
                    }
                }
            }           
        }
View Full Code Here

            int[] offsets1 = new int[2];
            int[] offsets2 = new int[2];

            for (int i = 0; i < tzids.length; i++) {
                VTimeZone vtz_org = VTimeZone.create(tzids[i]);
                VTimeZone vtz_new = null;
                try {
                    // Write out VTIMEZONE
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    OutputStreamWriter writer = new OutputStreamWriter(baos);
                    vtz_org.writeSimple(writer, time);
                    writer.close();
                    byte[] vtzdata = baos.toByteArray();
                    // Read VTIMEZONE
                    ByteArrayInputStream bais = new ByteArrayInputStream(vtzdata);
                    InputStreamReader reader = new InputStreamReader(bais);
                    vtz_new = VTimeZone.create(reader);
                    reader.close();
                } catch (IOException ioe) {
                    errln("FAIL: IO error while writing/reading VTIMEZONE data");
                }

                // Check equivalency
                vtz_org.getOffset(time, false, offsets1);
                vtz_new.getOffset(time, false, offsets2);
                if (offsets1[0] != offsets2[0] || offsets1[1] != offsets2[1]) {
                    errln("FAIL: VTimeZone writeSimple for " + tzids[i] + " at time " + time + " failed to the round trip.");
                }
            }
        }
View Full Code Here

    public void TestVTimeZoneHeaderProps() {
        String tzid = "America/Chicago";
        String tzurl = "http://source.icu-project.org";
        Date lastmod = new Date(getUTCMillis(2007, Calendar.JUNE, 1));

        VTimeZone vtz = VTimeZone.create(tzid);
        vtz.setTZURL(tzurl);
        vtz.setLastModified(lastmod);

        // Roundtrip conversion
        VTimeZone newvtz1 = null;
        try {
            // Write out VTIMEZONE
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            OutputStreamWriter writer = new OutputStreamWriter(baos);
            vtz.write(writer);
            writer.close();
            byte[] vtzdata = baos.toByteArray();
            // Read VTIMEZONE
            ByteArrayInputStream bais = new ByteArrayInputStream(vtzdata);
            InputStreamReader reader = new InputStreamReader(bais);
            newvtz1 = VTimeZone.create(reader);
            reader.close();

            // Check if TZURL and LAST-MODIFIED headers are preserved
            if (!(tzurl.equals(newvtz1.getTZURL()))) {
                errln("FAIL: TZURL property is not preserved during the roundtrip conversion.  Before:"
                        + tzurl + "/After:" + newvtz1.getTZURL());
            }
            if (!(lastmod.equals(newvtz1.getLastModified()))) {
                errln("FAIL: LAST-MODIFIED property is not preserved during the roundtrip conversion.  Before:"
                        + lastmod.getTime() + "/After:" + newvtz1.getLastModified().getTime());
            }
        } catch (IOException ioe) {
            errln("FAIL: IO error while writing/reading VTIMEZONE data");
        }

        // Second roundtrip, with a cutoff
        VTimeZone newvtz2 = null;
        try {
            // Set different tzurl
            String newtzurl = "http://www.ibm.com";
            newvtz1.setTZURL(newtzurl);
            // Write out VTIMEZONE
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            OutputStreamWriter writer = new OutputStreamWriter(baos);
            newvtz1.write(writer, getUTCMillis(2000, Calendar.JANUARY, 1));
            writer.close();
            byte[] vtzdata = baos.toByteArray();
            // Read VTIMEZONE
            ByteArrayInputStream bais = new ByteArrayInputStream(vtzdata);
            InputStreamReader reader = new InputStreamReader(bais);
            newvtz2 = VTimeZone.create(reader);
            reader.close();

            // Check if TZURL and LAST-MODIFIED headers are preserved
            if (!(newtzurl.equals(newvtz2.getTZURL()))) {
                errln("FAIL: TZURL property is not preserved during the second roundtrip conversion.  Before:"
                        + newtzurl + "/After:" + newvtz2.getTZURL());
            }
            if (!(lastmod.equals(newvtz2.getLastModified()))) {
                errln("FAIL: LAST-MODIFIED property is not preserved during the second roundtrip conversion.  Before:"
                        + lastmod.getTime() + "/After:" + newvtz2.getLastModified().getTime());
            }
        } catch (IOException ioe) {
            errln("FAIL: IO error while writing/reading VTIMEZONE data");
        }
       
View Full Code Here

     * API coverage test for VTimeZone
     */
    public void TestVTimeZoneCoverage() {
        final String TZID = "Europe/Moscow";
        BasicTimeZone otz = (BasicTimeZone)TimeZone.getTimeZone(TZID, TimeZone.TIMEZONE_ICU);
        VTimeZone vtz = VTimeZone.create(TZID);

        // getOffset(era, year, month, day, dayOfWeek, milliseconds)
        int offset1 = otz.getOffset(GregorianCalendar.AD, 2007, Calendar.JULY, 1, Calendar.SUNDAY, 0);
        int offset2 = vtz.getOffset(GregorianCalendar.AD, 2007, Calendar.JULY, 1, Calendar.SUNDAY, 0);
        if (offset1 != offset2) {
            errln("FAIL: getOffset(int,int,int,int,int,int) returned different results in VTimeZone and OlsonTimeZone");
        }

        // getOffset(date, local, offsets)
        int[] offsets1 = new int[2];
        int[] offsets2 = new int[2];
        long t = System.currentTimeMillis();
        otz.getOffset(t, false, offsets1);
        vtz.getOffset(t, false, offsets2);
        if (offsets1[0] != offsets2[0] || offsets1[1] != offsets2[1]) {
            errln("FAIL: getOffset(long,boolean,int[]) returned different results in VTimeZone and OlsonTimeZone");
        }

        // getRawOffset
        if (otz.getRawOffset() != vtz.getRawOffset()) {
            errln("FAIL: getRawOffset returned different results in VTimeZone and OlsonTimeZone");
        }

        // inDaylightTime
        Date d = new Date();
        if (otz.inDaylightTime(d) != vtz.inDaylightTime(d)) {
            errln("FAIL: inDaylightTime returned different results in VTimeZone and OlsonTimeZone");
        }

        // useDaylightTime
        if (otz.useDaylightTime() != vtz.useDaylightTime()) {
            errln("FAIL: useDaylightTime returned different results in VTimeZone and OlsonTimeZone");
        }

        // setRawOffset
        final int RAW = -10*HOUR;
        VTimeZone tmpvtz = (VTimeZone)vtz.clone();
        tmpvtz.setRawOffset(RAW);
        if (tmpvtz.getRawOffset() != RAW) {
            logln("setRawOffset is implemented");
        }

        // hasSameRules
        boolean bSame = otz.hasSameRules(vtz);
View Full Code Here

    }

    public void TestVTimeZoneParse() {
        // Trying to create VTimeZone from empty data
        StringReader r = new StringReader("");
        VTimeZone empty = VTimeZone.create(r);
        if (empty != null) {
            errln("FAIL: Non-null VTimeZone is returned for empty VTIMEZONE data");
        }

        // Create VTimeZone for Asia/Tokyo
        String asiaTokyo =
                "BEGIN:VTIMEZONE\r\n" +
                "TZID:Asia\r\n" +
                "\t/Tokyo\r\n" +
                "BEGIN:STANDARD\r\n" +
                "TZOFFSETFROM:+0900\r\n" +
                "TZOFFSETTO:+0900\r\n" +
                "TZNAME:JST\r\n" +
                "DTSTART:19700101\r\n" +
                " T000000\r\n" +
                "END:STANDARD\r\n" +
                "END:VTIMEZONE";
        r = new StringReader(asiaTokyo);
        VTimeZone tokyo = VTimeZone.create(r);
        if (tokyo == null) {
            errln("FAIL: Failed to create a VTimeZone tokyo");
        } else {
            // Make sure offsets are correct
            int[] offsets = new int[2];
            tokyo.getOffset(System.currentTimeMillis(), false, offsets);
            if (offsets[0] != 9*HOUR || offsets[1] != 0) {
                errln("FAIL: Bad offsets returned by a VTimeZone created for Tokyo");
            }
        }       

        // Create VTimeZone from VTIMEZONE data
        String fooData =
            "BEGIN:VCALENDAR\r\n" +
            "BEGIN:VTIMEZONE\r\n" +
            "TZID:FOO\r\n" +
            "BEGIN:STANDARD\r\n" +
            "TZOFFSETFROM:-0700\r\n" +
            "TZOFFSETTO:-0800\r\n" +
            "TZNAME:FST\r\n" +
            "DTSTART:20071010T010000\r\n" +
            "RRULE:FREQ=YEARLY;BYDAY=WE;BYMONTHDAY=10,11,12,13,14,15,16;BYMONTH=10\r\n" +
            "END:STANDARD\r\n" +
            "BEGIN:DAYLIGHT\r\n" +
            "TZOFFSETFROM:-0800\r\n" +
            "TZOFFSETTO:-0700\r\n" +
            "TZNAME:FDT\r\n" +
            "DTSTART:20070415T010000\r\n" +
            "RRULE:FREQ=YEARLY;BYMONTHDAY=15;BYMONTH=4\r\n" +
            "END:DAYLIGHT\r\n" +
            "END:VTIMEZONE\r\n" +
            "END:VCALENDAR";

        r = new StringReader(fooData);
        VTimeZone foo = VTimeZone.create(r);
        if (foo == null) {
            errln("FAIL: Failed to create a VTimeZone foo");
        } else {
            // Write VTIMEZONE data
            StringWriter w = new StringWriter();
            try {
                foo.write(w, getUTCMillis(2005, Calendar.JANUARY, 1));
            } catch (IOException ioe) {
                errln("FAIL: IOException is thrown while writing VTIMEZONE data for foo");
            }
            logln(w.toString());
        }
View Full Code Here

            times[i] = cal.getTimeInMillis();
        }

        for (int i = 0; i < TestZones.length; i++) {
            try {
                VTimeZone vtz = VTimeZone.create(new StringReader(TestZones[i]));
                for (int j = 0; j < times.length; j++) {
                    int offset = vtz.getOffset(times[j]);
                    if (offset != Expected[i][j]) {
                        errln("FAIL: Invalid offset at time(" + times[j] + "):" + offset + " Expected:" + Expected[i][j]);
                    }
                }
            } catch (Exception e) {
View Full Code Here

TOP

Related Classes of com.ibm.icu.util.VTimeZone

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.