/* * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/* * @test * @bug 4278609 4761696 * @library /java/text/testlib * @summary Make sure to handle DST transition ending at 0:00 January 1.
*/
Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
// setting a date using GMT zone just after the end rule of tz zone
cal.clear();
cal.set(Calendar.ERA, GregorianCalendar.AD);
cal.set(1998, Calendar.DECEMBER, 31, 23, 01, 00);
Date date = cal.getTime();
int millis = cal.get(Calendar.HOUR_OF_DAY) * 3600000
+ cal.get(Calendar.MINUTE) * 60000
+ cal.get(Calendar.SECOND) * 1000
+ cal.get(Calendar.MILLISECOND); /* we must use standard local time */
millis += tz.getRawOffset();
int offset = tz.getOffset(cal.get(Calendar.ERA),
cal.get(Calendar.YEAR),
cal.get(Calendar.MONTH),
cal.get(Calendar.DATE),
cal.get(Calendar.DAY_OF_WEEK),
millis);
if (offset != 0) {
SimpleDateFormat format = new SimpleDateFormat("dd MMM HH:mm:ss zzz",
Locale.US);
format.setTimeZone(tz);
errln("Wrong DST transition: " + tz
+ "\na date just after DST = " + format.format(date)
+ "\ngetOffset = " + offset);
}
}
/* * 4761696: Rewrite SimpleTimeZone to support correct DST transitions * * Derived from JCK test cases some of which specify wrong day of week values.
*/ publicvoid Test4761696() {
GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
// test#1 int rawOffset = -43200000; int saving = 1800000; int timeOfDay = 84600001;
SimpleTimeZone tz = new SimpleTimeZone(rawOffset, "stz",
Calendar.JULY, 1, 0, 0,
Calendar.JANUARY, 1, 0, 0,
saving); int year = Integer.MIN_VALUE;
tz.setStartYear(year); int offset = tz.getOffset(GregorianCalendar.AD,
year,
Calendar.DECEMBER,
31,
1, // should be SATURDAY
timeOfDay); int y = (int) mod((long)year, 28L); // 28-year cycle
cal.clear();
cal.set(cal.ERA, cal.AD);
cal.set(y, Calendar.DECEMBER, 31);
cal.set(cal.MILLISECOND, timeOfDay); long localtime = cal.getTimeInMillis() + rawOffset; // local standard time
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.