0N/A/*
2362N/A * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A * @test
0N/A * @bug 4558835 4915146
0N/A * @summary Verify timezone offset and fractional seconds are correctly parsed
0N/A */
0N/A
0N/Aimport java.io.*;
0N/Aimport java.util.Date;
0N/A
0N/Aimport sun.security.util.DerInputStream;
0N/A
0N/Apublic class TimeParsing {
0N/A
0N/A // 10 Aug 2001 17:43:51 GMT
0N/A private final static long TIME = 997465431000l;
0N/A private final static long TIME_FRACT1 = 997465431700l;
0N/A private final static long TIME_FRACT2 = 997465431760l;
0N/A private final static long TIME_FRACT3 = 997465431765l;
0N/A
0N/A // 010810174351Z
0N/A private final static byte[] UTC_ZULU =
0N/A {0x17, 0x0d, 0x30, 0x31, 0x30, 0x38, 0x31, 0x30, 0x31, 0x37, 0x34, 0x33, 0x35, 0x31, 0x5a};
0N/A
0N/A // 010810184351+0100
0N/A private final static byte[] UTC_PLUS1 =
0N/A {0x17, 0x11, 0x30, 0x31, 0x30, 0x38, 0x31, 0x30, 0x31, 0x38, 0x34, 0x33, 0x35, 0x31, 0x2b, 0x30, 0x31, 0x30, 0x30};
0N/A
0N/A // 010810164351-0100
0N/A private final static byte[] UTC_MINUS1 =
0N/A {0x17, 0x11, 0x30, 0x31, 0x30, 0x38, 0x31, 0x30, 0x31, 0x36, 0x34, 0x33, 0x35, 0x31, 0x2d, 0x30, 0x31, 0x30, 0x30};
0N/A
0N/A // 20010810174351Z
0N/A private final static byte[] GEN_ZULU =
0N/A {0x18, 0x0f, 0x32, 0x30, 0x30, 0x31, 0x30, 0x38, 0x31, 0x30, 0x31, 0x37, 0x34, 0x33, 0x35, 0x31, 0x5a};
0N/A
0N/A // 20010810184351+0100
0N/A private final static byte[] GEN_PLUS1 =
0N/A {0x18, 0x13, 0x32, 0x30, 0x30, 0x31, 0x30, 0x38, 0x31, 0x30, 0x31, 0x38, 0x34, 0x33, 0x35, 0x31, 0x2b, 0x30, 0x31, 0x30, 0x30};
0N/A
0N/A // 20010810164351-0100
0N/A private final static byte[] GEN_MINUS1 =
0N/A {0x18, 0x13, 0x32, 0x30, 0x30, 0x31, 0x30, 0x38, 0x31, 0x30, 0x31, 0x36, 0x34, 0x33, 0x35, 0x31, 0x2d, 0x30, 0x31, 0x30, 0x30};
0N/A
0N/A // 20010810174351.7Z
0N/A private final static byte[] GEN_FRACT1_ZULU =
0N/A {0x18, 0x11, 0x32, 0x30, 0x30, 0x31, 0x30, 0x38, 0x31, 0x30, 0x31, 0x37, 0x34, 0x33, 0x35, 0x31, 0x2e, 0x37, 0x5a};
0N/A
0N/A // 20010810174351.76Z
0N/A private final static byte[] GEN_FRACT2_ZULU =
0N/A {0x18, 0x12, 0x32, 0x30, 0x30, 0x31, 0x30, 0x38, 0x31, 0x30, 0x31, 0x37, 0x34, 0x33, 0x35, 0x31, 0x2e, 0x37, 0x36, 0x5a};
0N/A
0N/A // 20010810174351.765Z
0N/A private final static byte[] GEN_FRACT3_ZULU =
0N/A {0x18, 0x13, 0x32, 0x30, 0x30, 0x31, 0x30, 0x38, 0x31, 0x30, 0x31, 0x37, 0x34, 0x33, 0x35, 0x31, 0x2e, 0x37, 0x36, 0x35, 0x5a};
0N/A
0N/A // 20010810184351.7+0100
0N/A private final static byte[] GEN_FRACT1_PLUS1 =
0N/A {0x18, 0x15, 0x32, 0x30, 0x30, 0x31, 0x30, 0x38, 0x31, 0x30, 0x31, 0x38, 0x34, 0x33, 0x35, 0x31, 0x2e, 0x37, 0x2b, 0x30, 0x31, 0x30, 0x30};
0N/A
0N/A // 20010810184351.76+0100
0N/A private final static byte[] GEN_FRACT2_PLUS1 =
0N/A {0x18, 0x16, 0x32, 0x30, 0x30, 0x31, 0x30, 0x38, 0x31, 0x30, 0x31, 0x38, 0x34, 0x33, 0x35, 0x31, 0x2e, 0x37, 0x36, 0x2b, 0x30, 0x31, 0x30, 0x30};
0N/A
0N/A // 20010810184351.765+0100
0N/A private final static byte[] GEN_FRACT3_PLUS1 =
0N/A {0x18, 0x17, 0x32, 0x30, 0x30, 0x31, 0x30, 0x38, 0x31, 0x30, 0x31, 0x38, 0x34, 0x33, 0x35, 0x31, 0x2e, 0x37, 0x36, 0x35, 0x2b, 0x30, 0x31, 0x30, 0x30};
0N/A
0N/A // 20010810184351,765+0100
0N/A private final static byte[] GEN_FRACT3_COMMA_PLUS1 =
0N/A {0x18, 0x17, 0x32, 0x30, 0x30, 0x31, 0x30, 0x38, 0x31, 0x30, 0x31, 0x38, 0x34, 0x33, 0x35, 0x31, 0x2c, 0x37, 0x36, 0x35, 0x2b, 0x30, 0x31, 0x30, 0x30};
0N/A
0N/A
0N/A private static Date decodeUTC(byte[] b) throws IOException {
0N/A DerInputStream derin = new DerInputStream(b);
0N/A return derin.getUTCTime();
0N/A }
0N/A
0N/A private static Date decodeGeneralized(byte[] b) throws IOException {
0N/A DerInputStream derin = new DerInputStream(b);
0N/A return derin.getGeneralizedTime();
0N/A }
0N/A
0N/A private static void checkUTC(Date d0, byte[] b, String text) throws Exception {
0N/A Date d1 = decodeUTC(b);
0N/A if( !d0.equals(d1) ) {
0N/A throw new Exception("UTCTime " + text + " failed: " + d1.toGMTString());
0N/A } else {
0N/A System.out.println("UTCTime " + text + " ok");
0N/A }
0N/A }
0N/A
0N/A private static void checkGeneralized(Date d0, byte[] b, String text) throws Exception {
0N/A Date d1 = decodeGeneralized(b);
0N/A if( !d0.equals(d1) ) {
0N/A throw new Exception("GeneralizedTime " + text + " failed: " + d1.toGMTString());
0N/A } else {
0N/A System.out.println("GeneralizedTime " + text + " ok");
0N/A }
0N/A }
0N/A
0N/A public static void main(String args[]) throws Exception {
0N/A Date d0 = new Date(TIME);
0N/A System.out.println(d0.toGMTString());
0N/A
0N/A checkUTC(d0, UTC_ZULU, "Zulu");
0N/A checkUTC(d0, UTC_PLUS1, "+0100");
0N/A checkUTC(d0, UTC_MINUS1, "-0100");
0N/A
0N/A checkGeneralized(d0, GEN_ZULU, "Zulu");
0N/A checkGeneralized(d0, GEN_PLUS1, "+0100");
0N/A checkGeneralized(d0, GEN_MINUS1, "-0100");
0N/A
0N/A Date d1 = new Date(TIME_FRACT1);
0N/A checkGeneralized(d1, GEN_FRACT1_ZULU, "fractional seconds (Zulu)");
0N/A checkGeneralized(d1, GEN_FRACT1_PLUS1, "fractional seconds (+0100)");
0N/A
0N/A Date d2 = new Date(TIME_FRACT2);
0N/A checkGeneralized(d2, GEN_FRACT2_ZULU, "fractional seconds (Zulu)");
0N/A checkGeneralized(d2, GEN_FRACT2_PLUS1, "fractional seconds (+0100)");
0N/A
0N/A Date d3 = new Date(TIME_FRACT3);
0N/A checkGeneralized(d3, GEN_FRACT3_ZULU, "fractional seconds (Zulu)");
0N/A checkGeneralized(d3, GEN_FRACT3_PLUS1, "fractional seconds (+0100)");
0N/A checkGeneralized(d3, GEN_FRACT3_COMMA_PLUS1, "fractional seconds (+0100)");
0N/A }
0N/A
0N/A}