From e42572a24e64f8511dbbf2e83f79fb08303de1a0 Mon Sep 17 00:00:00 2001 From: Almaz Mingaleev Date: Fri, 29 Oct 2021 14:55:30 +0000 Subject: DO NOT MERGE Fix tests which relied on Pacific/Apia DST offset [S CTS] tzdata module prebuilts were updated to 2021a1 (2021b) in ag/16249425 and ag/16282952 enabled them. That caused failures in tests which expected explicit offset in certain time zones. java.util.TimeZone APIs allow to check offsets on specifc time, but DateFormatSymbols always returns data as of now. So I've changed them to be consistent with java.util.TimeZone. Bug: 201301255 Bug: 204279800 Bug: 211073707 Test: atest luni/src/test/java/libcore/java/test/DateFormatSymbolsTest.java Test: atest luni/src/test/java/libcore/java/util/TimeZoneTest.java Change-Id: I9e13e6c4552697957f8eb3e3b0327fe7d321bef9 Merged-In: I9e13e6c4552697957f8eb3e3b0327fe7d321bef9 --- .../libcore/java/text/DateFormatSymbolsTest.java | 25 +++++++++++++++++++--- .../test/java/libcore/java/util/TimeZoneTest.java | 10 ++++++--- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/luni/src/test/java/libcore/java/text/DateFormatSymbolsTest.java b/luni/src/test/java/libcore/java/text/DateFormatSymbolsTest.java index 3ea43784ccd..baa3344efe5 100644 --- a/luni/src/test/java/libcore/java/text/DateFormatSymbolsTest.java +++ b/luni/src/test/java/libcore/java/text/DateFormatSymbolsTest.java @@ -156,21 +156,40 @@ public class DateFormatSymbolsTest extends junit.framework.TestCase { } // http://b/7955614 - public void test_getZoneStrings_Apia() throws Exception { + public void test_getZoneStrings_Apia() { String[][] array = DateFormatSymbols.getInstance(Locale.US).getZoneStrings(); + for (int i = 0; i < array.length; ++i) { String[] row = array[i]; // Pacific/Apia is somewhat arbitrary; we just want a zone we have to generate // "GMT" strings for the short names. if (row[0].equals("Pacific/Apia")) { + TimeZone apiaTz = TimeZone.getTimeZone("Pacific/Apia"); assertEquals("Apia Standard Time", row[1]); - assertEquals("GMT+13:00", row[2]); + assertEquals(formattedStandardTimeOffset(apiaTz), row[2]); assertEquals("Apia Daylight Time", row[3]); - assertEquals("GMT+14:00", row[4]); + assertEquals(formattedDstOffset(apiaTz), row[4]); } } } + private static String formattedStandardTimeOffset(TimeZone tz) { + return formattedOffset(tz.getRawOffset()); + } + + private static String formattedDstOffset(TimeZone tz) { + return formattedOffset(tz.getRawOffset() + tz.getDSTSavings()); + } + + private static String formattedOffset(int offset) { + String pattern = "GMT%+d:%02d"; + int millisInHour = 60 * 60 * 1_000; + int hours = offset / millisInHour; + int minutes = (offset - hours * millisInHour) / 1_000 / 60; + + return String.format(pattern, hours, minutes); + } + public void test_setZoneStrings_checks_dimensions() throws Exception { DateFormatSymbols dfs = DateFormatSymbols.getInstance(); String[][] zoneStrings = dfs.getZoneStrings(); diff --git a/luni/src/test/java/libcore/java/util/TimeZoneTest.java b/luni/src/test/java/libcore/java/util/TimeZoneTest.java index a6865343d99..9b8ea4723b1 100644 --- a/luni/src/test/java/libcore/java/util/TimeZoneTest.java +++ b/luni/src/test/java/libcore/java/util/TimeZoneTest.java @@ -319,12 +319,16 @@ public class TimeZoneTest extends TestCase { } // http://b/7955614 - public void testApia() throws Exception { + public void testApia() { TimeZone tz = TimeZone.getTimeZone("Pacific/Apia"); assertEquals("Apia Daylight Time", tz.getDisplayName(true, TimeZone.LONG, Locale.US)); assertEquals("Apia Standard Time", tz.getDisplayName(false, TimeZone.LONG, Locale.US)); - assertEquals("GMT+14:00", tz.getDisplayName(true, TimeZone.SHORT, Locale.US)); - assertEquals("GMT+13:00", tz.getDisplayName(false, TimeZone.SHORT, Locale.US)); + + long samoaStandardTime = 1630315635000L; // 30 Aug 2021 + long samoaDst = 1614504435000L; // 28 Feb 2021 + + assertEquals(13 * 60 * 60 * 1_000, tz.getOffset(samoaStandardTime)); + assertEquals(14 * 60 * 60 * 1_000, tz.getOffset(samoaDst)); } private static boolean isGmtString(String s) { -- cgit v1.2.3