|
| 1 | +/* |
| 2 | + * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | + * |
| 5 | + * This code is free software; you can redistribute it and/or modify it |
| 6 | + * under the terms of the GNU General Public License version 2 only, as |
| 7 | + * published by the Free Software Foundation. |
| 8 | + * |
| 9 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | + * accompanied this code). |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License version |
| 16 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | + * |
| 19 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | + * or visit www.oracle.com if you need additional information or have any |
| 21 | + * questions. |
| 22 | + */ |
| 23 | + |
| 24 | +/* |
| 25 | + * @test |
| 26 | + * @bug 8073446 8262110 |
| 27 | + * @summary Tests DST related beyond the year 2037 |
| 28 | + * @run testng Beyond2037 |
| 29 | + */ |
| 30 | + |
| 31 | +import java.text.SimpleDateFormat; |
| 32 | +import java.util.TimeZone; |
| 33 | + |
| 34 | +import org.testng.annotations.DataProvider; |
| 35 | +import org.testng.annotations.Test; |
| 36 | +import static org.testng.Assert.assertEquals; |
| 37 | + |
| 38 | +@Test |
| 39 | +public class Beyond2037 { |
| 40 | + |
| 41 | + @DataProvider |
| 42 | + Object[][] dstTransition() { |
| 43 | + return new Object[][] { |
| 44 | + {"2037/03/08 01:59:59:999", "2037/03/08 01:59:59:999"}, |
| 45 | + {"2037/03/08 02:00:00:000", "2037/03/08 03:00:00:000"}, |
| 46 | + {"2038/03/14 01:59:59:999", "2038/03/14 01:59:59:999"}, |
| 47 | + {"2038/03/14 02:00:00:000", "2038/03/14 03:00:00:000"}, |
| 48 | + {"2099/03/08 01:59:59:999", "2099/03/08 01:59:59:999"}, |
| 49 | + {"2099/03/08 02:00:00:000", "2099/03/08 03:00:00:000"}, |
| 50 | + {"2100/03/14 01:59:59:999", "2100/03/14 01:59:59:999"}, |
| 51 | + {"2100/03/14 02:00:00:000", "2100/03/14 03:00:00:000"}, |
| 52 | + {"8000/03/12 01:59:59:999", "8000/03/12 01:59:59:999"}, |
| 53 | + {"8000/03/12 02:00:00:000", "8000/03/12 03:00:00:000"}, |
| 54 | + }; |
| 55 | + } |
| 56 | + |
| 57 | + @Test(dataProvider="dstTransition") |
| 58 | + public void testDstTransition(String source, String expected) throws Exception { |
| 59 | + var timeZone = TimeZone.getTimeZone("America/New_York"); |
| 60 | + var sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss:SSS" ); |
| 61 | + sdf.setTimeZone(timeZone); |
| 62 | + assertEquals(sdf.format(sdf.parse(source)), expected); |
| 63 | + } |
| 64 | + |
| 65 | + @Test |
| 66 | + public void testGetOffset() throws Exception { |
| 67 | + var timeZone = TimeZone.getTimeZone("PST8PDT"); |
| 68 | + var df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| 69 | + df.setTimeZone(timeZone); |
| 70 | + var tMilli = df.parse("7681-03-09 03:20:49").getTime(); |
| 71 | + assertEquals(timeZone.getOffset(tMilli), -25200000); |
| 72 | + } |
| 73 | +} |
0 commit comments