diff options
author | Daniel Xie <dxie@google.com> | 2015-12-06 05:40:11 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2015-12-06 05:40:11 +0000 |
commit | 0b8078f8b9cd096e6d104a04e9e381c94fe3c106 (patch) | |
tree | 6117c295131540d6cae92b159e8cf0f48d4ed554 | |
parent | bcd9db7050124d4d8bbd9b732f43efd3291b4aa4 (diff) | |
parent | 1d1abc5b0ccf31e79aa7173b2e592b7e52b3e519 (diff) | |
download | libcore-0b8078f8b9cd096e6d104a04e9e381c94fe3c106.zip libcore-0b8078f8b9cd096e6d104a04e9e381c94fe3c106.tar.gz libcore-0b8078f8b9cd096e6d104a04e9e381c94fe3c106.tar.bz2 |
Merge "Fix TimeZoneTest#testPreHistoricOffsets CTS failures." into kitkat-cts-dev
am: 1d1abc5b0c
* commit '1d1abc5b0ccf31e79aa7173b2e592b7e52b3e519':
Fix TimeZoneTest#testPreHistoricOffsets CTS failures.
-rw-r--r-- | luni/src/test/java/libcore/java/util/TimeZoneTest.java | 51 |
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 0bc02b0..caf635c 100644 --- a/luni/src/test/java/libcore/java/util/TimeZoneTest.java +++ b/luni/src/test/java/libcore/java/util/TimeZoneTest.java @@ -74,52 +74,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" }; |