Path: blob/master/test/jdk/sun/util/calendar/zi/Beyond2037.java
41153 views
/*1* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 8073446 826211026* @summary Tests DST related beyond the year 203727* @run testng Beyond203728*/2930import java.text.SimpleDateFormat;31import java.util.TimeZone;3233import org.testng.annotations.DataProvider;34import org.testng.annotations.Test;35import static org.testng.Assert.assertEquals;3637@Test38public class Beyond2037 {3940@DataProvider41Object[][] dstTransition() {42return new Object[][] {43{"2037/03/08 01:59:59:999", "2037/03/08 01:59:59:999"},44{"2037/03/08 02:00:00:000", "2037/03/08 03:00:00:000"},45{"2038/03/14 01:59:59:999", "2038/03/14 01:59:59:999"},46{"2038/03/14 02:00:00:000", "2038/03/14 03:00:00:000"},47{"2099/03/08 01:59:59:999", "2099/03/08 01:59:59:999"},48{"2099/03/08 02:00:00:000", "2099/03/08 03:00:00:000"},49{"2100/03/14 01:59:59:999", "2100/03/14 01:59:59:999"},50{"2100/03/14 02:00:00:000", "2100/03/14 03:00:00:000"},51{"8000/03/12 01:59:59:999", "8000/03/12 01:59:59:999"},52{"8000/03/12 02:00:00:000", "8000/03/12 03:00:00:000"},53};54}5556@Test(dataProvider="dstTransition")57public void testDstTransition(String source, String expected) throws Exception {58var timeZone = TimeZone.getTimeZone("America/New_York");59var sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss:SSS" );60sdf.setTimeZone(timeZone);61assertEquals(sdf.format(sdf.parse(source)), expected);62}6364@Test65public void testGetOffset() throws Exception {66var timeZone = TimeZone.getTimeZone("PST8PDT");67var df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");68df.setTimeZone(timeZone);69var tMilli = df.parse("7681-03-09 03:20:49").getTime();70assertEquals(timeZone.getOffset(tMilli), -25200000);71}72}737475