Merge "Fix error index of unparsed timezone name."
diff --git a/luni/src/test/java/libcore/java/util/GregorianCalendarTest.java b/luni/src/test/java/libcore/java/util/GregorianCalendarTest.java
index 750b8db..3345ed5 100644
--- a/luni/src/test/java/libcore/java/util/GregorianCalendarTest.java
+++ b/luni/src/test/java/libcore/java/util/GregorianCalendarTest.java
@@ -16,6 +16,9 @@
package libcore.java.util;
+import java.time.Instant;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Calendar;
import java.util.Date;
@@ -297,6 +300,21 @@
assertEquals(3600 * 1000, calendar.getTimeZone().getRawOffset()); // in milliseconds
}
+ public void test_fromZonedDateTime_invalidValues() {
+ ZoneId gmt = ZoneId.of("GMT");
+ ZonedDateTime[] invalidValues = {
+ ZonedDateTime.of(LocalDateTime.MAX, gmt),
+ ZonedDateTime.ofInstant(Instant.ofEpochMilli(Long.MAX_VALUE).plusMillis(1), gmt),
+ ZonedDateTime.ofInstant(Instant.ofEpochMilli(Long.MIN_VALUE).minusMillis(1), gmt),
+ ZonedDateTime.of(LocalDateTime.MAX, gmt) };
+ for (ZonedDateTime invalidValue : invalidValues) {
+ try {
+ GregorianCalendar.from(invalidValue);
+ fail("GregorianCalendar.from() should have failed with " + invalidValue);
+ } catch (IllegalArgumentException expected) {}
+ }
+ }
+
public void test_toZonedDateTime() {
TimeZone timeZone = TimeZone.getTimeZone("Europe/Paris");
GregorianCalendar calendar = new GregorianCalendar(timeZone);
diff --git a/ojluni/src/main/java/java/time/Instant.java b/ojluni/src/main/java/java/time/Instant.java
index 9b9efa5..91a177c 100644
--- a/ojluni/src/main/java/java/time/Instant.java
+++ b/ojluni/src/main/java/java/time/Instant.java
@@ -1229,14 +1229,8 @@
* @throws ArithmeticException if numeric overflow occurs
*/
public long toEpochMilli() {
- if (seconds < 0 && nanos > 0) {
- long millis = Math.multiplyExact(seconds+1, 1000);
- long adjustment = nanos / 1000_000 - 1000;
- return Math.addExact(millis, adjustment);
- } else {
- long millis = Math.multiplyExact(seconds, 1000);
- return Math.addExact(millis, nanos / 1000_000);
- }
+ long millis = Math.multiplyExact(seconds, 1000);
+ return millis + nanos / 1000_000;
}
//-----------------------------------------------------------------------
diff --git a/ojluni/src/test/java/time/tck/java/time/TCKInstant.java b/ojluni/src/test/java/time/tck/java/time/TCKInstant.java
index 1b8fea7..3d89db5 100644
--- a/ojluni/src/test/java/time/tck/java/time/TCKInstant.java
+++ b/ojluni/src/test/java/time/tck/java/time/TCKInstant.java
@@ -1931,16 +1931,6 @@
Instant.ofEpochSecond(Long.MIN_VALUE / 1000 - 1).toEpochMilli();
}
- @Test(expectedExceptions=ArithmeticException.class)
- public void test_toEpochMillis_overflow() {
- Instant.ofEpochSecond(Long.MAX_VALUE / 1000, 809_000_000).toEpochMilli();
- }
-
- @Test(expectedExceptions=ArithmeticException.class)
- public void test_toEpochMillis_overflow2() {
- Instant.ofEpochSecond(-9223372036854776L, 1).toEpochMilli();
- }
-
//-----------------------------------------------------------------------
// compareTo()
//-----------------------------------------------------------------------
diff --git a/ojluni/src/test/java/time/test/java/time/TestInstant.java b/ojluni/src/test/java/time/test/java/time/TestInstant.java
index 203bb57..cf135a1 100644
--- a/ojluni/src/test/java/time/test/java/time/TestInstant.java
+++ b/ojluni/src/test/java/time/test/java/time/TestInstant.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -62,8 +62,6 @@
import java.time.Instant;
import org.testng.annotations.Test;
-import org.testng.annotations.DataProvider;
-import static org.testng.Assert.assertEquals;
/**
* Test Instant.
@@ -76,24 +74,4 @@
assertImmutable(Instant.class);
}
- @DataProvider(name="sampleEpochMillis")
- private Object[][] provider_sampleEpochMillis() {
- return new Object[][] {
- {"Long.MAX_VALUE", Long.MAX_VALUE},
- {"Long.MAX_VALUE-1", Long.MAX_VALUE - 1},
- {"1", 1L},
- {"0", 0L},
- {"-1", -1L},
- {"Long.MIN_VALUE+1", Long.MIN_VALUE + 1},
- {"Long.MIN_VALUE", Long.MIN_VALUE}
- };
- }
-
- @Test(dataProvider="sampleEpochMillis")
- public void test_epochMillis(String name, long millis) {
- Instant t1 = Instant.ofEpochMilli(millis);
- long m = t1.toEpochMilli();
- assertEquals(millis, m, name);
- }
-
}