summaryrefslogtreecommitdiffstats
path: root/luni
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2014-11-07 15:57:43 -0800
committerTakeshi Katae <takeshi.katae.xm@kyocera.jp>2015-10-08 09:46:17 +0000
commitbb97fad751a2a36794f234f21910b084ff63374f (patch)
treecbf88fd866804acaa371e0172207d7e254947b88 /luni
parent70a463cbfe0aac6bc88a46b3b103e40d70ff3abf (diff)
downloadlibcore-bb97fad751a2a36794f234f21910b084ff63374f.tar.gz
libcore-bb97fad751a2a36794f234f21910b084ff63374f.tar.bz2
libcore-bb97fad751a2a36794f234f21910b084ff63374f.zip
Fix TimeZoneTest#testPreHistoricOffsets CTS failures.
This test was more complicated than necessary, and now we have better historical data for Asia/Saigon it's started to fail. I've removed that part of the test (because there are now a lot more transitions) and rely solely on Africa/Bissau. We really only need one transition so we can test two times: one before the first transition and one after the last transition. Bug: 18285300 Change-Id: Ic820e88b319095b89779d271f45f5cb1c90173da (cherry picked from commit d05995d8c7488044352343d5125698795032b937)
Diffstat (limited to 'luni')
-rw-r--r--luni/src/test/java/libcore/java/util/TimeZoneTest.java51
1 files changed, 15 insertions, 36 deletions
diff --git a/luni/src/test/java/libcore/java/util/TimeZoneTest.java b/luni/src/test/java/libcore/java/util/TimeZoneTest.java
index 08d1e697d..39e0af988 100644
--- a/luni/src/test/java/libcore/java/util/TimeZoneTest.java
+++ b/luni/src/test/java/libcore/java/util/TimeZoneTest.java
@@ -73,52 +73,31 @@ public class TimeZoneTest extends TestCase {
}
public void testPreHistoricOffsets() throws Exception {
- // The "Asia/Saigon" time zone has just a few transitions, and hasn't changed in a
- // long time, which is convenient for testing:
- //
- // libcore.util.ZoneInfo[Asia/Saigon,mRawOffset=25200000,mUseDst=false]
- // 0 : time=-2005974400 Fri Jun 08 16:53:20 1906 GMT+00:00 = Fri Jun 08 23:59:40 1906 ICT isDst=0 offset= 380 gmtOffset=25580
- // 1 : time=-1855983920 Fri Mar 10 16:54:40 1911 GMT+00:00 = Fri Mar 10 23:54:40 1911 ICT isDst=0 offset= 0 gmtOffset=25200
- // 2 : time=-1819954800 Tue Apr 30 17:00:00 1912 GMT+00:00 = Wed May 01 01:00:00 1912 ICT isDst=0 offset= 3600 gmtOffset=28800
- // 3 : time=-1220428800 Thu Apr 30 16:00:00 1931 GMT+00:00 = Thu Apr 30 23:00:00 1931 ICT isDst=0 offset= 0 gmtOffset=25200
- TimeZone tz = TimeZone.getTimeZone("Asia/Saigon");
+ // "Africa/Bissau" has just a few transitions and hasn't changed in a long time.
+ // 1912-01-01 00:02:19-0100 ... 1912-01-01 00:02:20-0100
+ // 1974-12-31 23:59:59-0100 ... 1975-01-01 01:00:00+0000
+ TimeZone tz = TimeZone.getTimeZone("Africa/Bissau");
// Times before our first transition should assume we're still following that transition.
- // Note: the RI reports 25600 here because it has more transitions than we do.
- assertNonDaylightOffset(25580, -2005975000L, tz);
+ assertNonDaylightOffset(-3600, parseIsoTime("1911-01-01T00:00:00.0+0000"), tz);
- assertNonDaylightOffset(25580, -2005974400L, tz); // 0
- assertNonDaylightOffset(25580, -2005974000L, tz);
+ assertNonDaylightOffset(-3600, parseIsoTime("1912-01-01T12:00:00.0-0100"), tz);
- assertNonDaylightOffset(25200, -1855983920L, tz); // 1
- assertNonDaylightOffset(25200, -1855983900L, tz);
-
- assertNonDaylightOffset(28800, -1819954800L, tz); // 2
- assertNonDaylightOffset(28800, -1819954000L, tz);
-
- assertNonDaylightOffset(25200, -1220428800L, tz); // 3
-
- // Times after out last transition should assume we're still following that transition.
- assertNonDaylightOffset(25200, -1220428000L, tz);
-
- // There are plenty more examples. "Africa/Bissau" is one:
- //
- // libcore.util.ZoneInfo[Africa/Bissau,mRawOffset=0,mUseDst=false]
- // 0 : time=-1849388260 Fri May 26 01:02:20 1911 GMT+00:00 = Fri May 26 00:02:20 1911 GMT isDst=0 offset=-3600 gmtOffset=-3600
- // 1 : time= 157770000 Wed Jan 01 01:00:00 1975 GMT+00:00 = Wed Jan 01 01:00:00 1975 GMT isDst=0 offset= 0 gmtOffset=0
- tz = TimeZone.getTimeZone("Africa/Bissau");
- assertNonDaylightOffset(-3600, -1849388300L, tz);
- assertNonDaylightOffset(-3600, -1849388260L, tz); // 0
- assertNonDaylightOffset(-3600, -1849388200L, tz);
- assertNonDaylightOffset(0, 157770000L, tz); // 1
- assertNonDaylightOffset(0, 157780000L, tz);
+ // Times after our last transition should assume we're still following that transition.
+ assertNonDaylightOffset(0, parseIsoTime("1980-01-01T00:00:00.0+0000"), tz);
}
private static void assertNonDaylightOffset(int expectedOffsetSeconds, long epochSeconds, TimeZone tz) {
- assertEquals(expectedOffsetSeconds * 1000, tz.getOffset(epochSeconds * 1000));
+ assertEquals(expectedOffsetSeconds, tz.getOffset(epochSeconds * 1000) / 1000);
assertFalse(tz.inDaylightTime(new Date(epochSeconds * 1000)));
}
+ private static long parseIsoTime(String isoTime) throws Exception {
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
+ Date date = sdf.parse(isoTime);
+ return date.getTime() / 1000;
+ }
+
public void testZeroTransitionZones() throws Exception {
// Zones with no transitions historical or future seem ideal for testing.
String[] ids = new String[] { "Africa/Bujumbura", "Indian/Cocos", "Pacific/Wake", "UTC" };