Add j2cl and j2objc targets for protobuf/current/javatests/com/google/protobuf/util TIME_SRCS

Because not everything is supported in j2cl and j2objc some of the methods had to be marked as incompatible (reflection , String.format...)

PiperOrigin-RevId: 691368238
pull/18896/head
Protobuf Team Bot 4 weeks ago committed by Copybara-Service
parent 1f5df18680
commit afb20af442
  1. 1
      java/util/BUILD.bazel
  2. 15
      java/util/src/main/java/com/google/protobuf/util/Durations.java
  3. 41
      java/util/src/main/java/com/google/protobuf/util/Timestamps.java
  4. 20
      java/util/src/test/java/com/google/protobuf/util/DurationsTest.java
  5. 62
      java/util/src/test/java/com/google/protobuf/util/TimestampsTest.java

@ -92,6 +92,7 @@ junit_tests(
"//java/core:generic_test_protos_java_proto", "//java/core:generic_test_protos_java_proto",
"@protobuf_maven//:com_google_code_gson_gson", "@protobuf_maven//:com_google_code_gson_gson",
"@protobuf_maven//:com_google_guava_guava", "@protobuf_maven//:com_google_guava_guava",
"@protobuf_maven//:com_google_j2objc_j2objc_annotations",
"@protobuf_maven//:com_google_truth_truth", "@protobuf_maven//:com_google_truth_truth",
"@protobuf_maven//:junit_junit", "@protobuf_maven//:junit_junit",
], ],

@ -19,8 +19,11 @@ import static com.google.protobuf.util.Timestamps.NANOS_PER_MICROSECOND;
import static com.google.protobuf.util.Timestamps.NANOS_PER_MILLISECOND; import static com.google.protobuf.util.Timestamps.NANOS_PER_MILLISECOND;
import static com.google.protobuf.util.Timestamps.NANOS_PER_SECOND; import static com.google.protobuf.util.Timestamps.NANOS_PER_SECOND;
import com.google.common.annotations.GwtIncompatible;
import com.google.common.base.Strings;
import com.google.errorprone.annotations.CanIgnoreReturnValue; import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.CompileTimeConstant; import com.google.errorprone.annotations.CompileTimeConstant;
import com.google.j2objc.annotations.J2ObjCIncompatible;
import com.google.protobuf.Duration; import com.google.protobuf.Duration;
import java.io.Serializable; import java.io.Serializable;
import java.text.ParseException; import java.text.ParseException;
@ -140,6 +143,8 @@ public final class Durations {
* @throws NullPointerException if {@code duration} is {@code null} * @throws NullPointerException if {@code duration} is {@code null}
*/ */
@CanIgnoreReturnValue @CanIgnoreReturnValue
@GwtIncompatible("Depends on String.format which is not supported in Xplat.")
@J2ObjCIncompatible
public static Duration checkNotNegative(Duration duration) { public static Duration checkNotNegative(Duration duration) {
checkArgument(!isNegative(duration), "duration (%s) must not be negative", toString(duration)); checkArgument(!isNegative(duration), "duration (%s) must not be negative", toString(duration));
return duration; return duration;
@ -152,6 +157,8 @@ public final class Durations {
* @throws NullPointerException if {@code duration} is {@code null} * @throws NullPointerException if {@code duration} is {@code null}
*/ */
@CanIgnoreReturnValue @CanIgnoreReturnValue
@GwtIncompatible("Depends on String.format which is not supported in Xplat.")
@J2ObjCIncompatible
public static Duration checkPositive(Duration duration) { public static Duration checkPositive(Duration duration) {
checkArgument(isPositive(duration), "duration (%s) must be positive", toString(duration)); checkArgument(isPositive(duration), "duration (%s) must be positive", toString(duration));
return duration; return duration;
@ -164,7 +171,7 @@ public final class Durations {
int nanos = duration.getNanos(); int nanos = duration.getNanos();
if (!isValid(seconds, nanos)) { if (!isValid(seconds, nanos)) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
String.format( Strings.lenientFormat(
"Duration is not valid. See proto definition for valid values. " "Duration is not valid. See proto definition for valid values. "
+ "Seconds (%s) must be in range [-315,576,000,000, +315,576,000,000]. " + "Seconds (%s) must be in range [-315,576,000,000, +315,576,000,000]. "
+ "Nanos (%s) must be in range [-999,999,999, +999,999,999]. " + "Nanos (%s) must be in range [-999,999,999, +999,999,999]. "
@ -193,6 +200,8 @@ public final class Durations {
* @return The string representation of the given duration. * @return The string representation of the given duration.
* @throws IllegalArgumentException if the given duration is not in the valid range. * @throws IllegalArgumentException if the given duration is not in the valid range.
*/ */
@GwtIncompatible("Depends on String.format which is not supported in Xplat.")
@J2ObjCIncompatible
public static String toString(Duration duration) { public static String toString(Duration duration) {
checkValid(duration); checkValid(duration);
@ -220,6 +229,8 @@ public final class Durations {
* @return a Duration parsed from the string * @return a Duration parsed from the string
* @throws ParseException if the string is not in the duration format * @throws ParseException if the string is not in the duration format
*/ */
@GwtIncompatible("ParseException is not supported in Xplat")
@J2ObjCIncompatible
public static Duration parse(String value) throws ParseException { public static Duration parse(String value) throws ParseException {
// Must end with "s". // Must end with "s".
if (value.isEmpty() || value.charAt(value.length() - 1) != 's') { if (value.isEmpty() || value.charAt(value.length() - 1) != 's') {
@ -269,6 +280,8 @@ public final class Durations {
* @return a {@link Duration} parsed from the string * @return a {@link Duration} parsed from the string
* @throws IllegalArgumentException if parsing fails * @throws IllegalArgumentException if parsing fails
*/ */
@GwtIncompatible("ParseException is not supported in Xplat")
@J2ObjCIncompatible
public static Duration parseUnchecked(@CompileTimeConstant String value) { public static Duration parseUnchecked(@CompileTimeConstant String value) {
try { try {
return parse(value); return parse(value);

@ -13,6 +13,8 @@ import static com.google.common.math.LongMath.checkedAdd;
import static com.google.common.math.LongMath.checkedMultiply; import static com.google.common.math.LongMath.checkedMultiply;
import static com.google.common.math.LongMath.checkedSubtract; import static com.google.common.math.LongMath.checkedSubtract;
import com.google.common.annotations.GwtIncompatible;
import com.google.common.base.Strings;
import com.google.errorprone.annotations.CanIgnoreReturnValue; import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.CompileTimeConstant; import com.google.errorprone.annotations.CompileTimeConstant;
import com.google.j2objc.annotations.J2ObjCIncompatible; import com.google.j2objc.annotations.J2ObjCIncompatible;
@ -62,6 +64,8 @@ public final class Timestamps {
*/ */
public static final Timestamp EPOCH = Timestamp.newBuilder().setSeconds(0).setNanos(0).build(); public static final Timestamp EPOCH = Timestamp.newBuilder().setSeconds(0).setNanos(0).build();
@GwtIncompatible("Date formatting is not supported in non JVM java.time")
@J2ObjCIncompatible
private static final ThreadLocal<SimpleDateFormat> timestampFormat = private static final ThreadLocal<SimpleDateFormat> timestampFormat =
new ThreadLocal<SimpleDateFormat>() { new ThreadLocal<SimpleDateFormat>() {
@Override @Override
@ -70,6 +74,8 @@ public final class Timestamps {
} }
}; };
@GwtIncompatible("Date formatting is not supported in non JVM java.time")
@J2ObjCIncompatible
private static SimpleDateFormat createTimestampFormat() { private static SimpleDateFormat createTimestampFormat() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ENGLISH); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ENGLISH);
GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC")); GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
@ -163,7 +169,7 @@ public final class Timestamps {
int nanos = timestamp.getNanos(); int nanos = timestamp.getNanos();
if (!isValid(seconds, nanos)) { if (!isValid(seconds, nanos)) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
String.format( Strings.lenientFormat(
"Timestamp is not valid. See proto definition for valid values. " "Timestamp is not valid. See proto definition for valid values. "
+ "Seconds (%s) must be in range [-62,135,596,800, +253,402,300,799]. " + "Seconds (%s) must be in range [-62,135,596,800, +253,402,300,799]. "
+ "Nanos (%s) must be in range [0, +999,999,999].", + "Nanos (%s) must be in range [0, +999,999,999].",
@ -193,6 +199,8 @@ public final class Timestamps {
* @return The string representation of the given timestamp. * @return The string representation of the given timestamp.
* @throws IllegalArgumentException if the given timestamp is not in the valid range. * @throws IllegalArgumentException if the given timestamp is not in the valid range.
*/ */
@GwtIncompatible("Depends on String.format which is not supported in Xplat.")
@J2ObjCIncompatible
public static String toString(Timestamp timestamp) { public static String toString(Timestamp timestamp) {
checkValid(timestamp); checkValid(timestamp);
@ -222,6 +230,8 @@ public final class Timestamps {
* @return a Timestamp parsed from the string * @return a Timestamp parsed from the string
* @throws ParseException if parsing fails * @throws ParseException if parsing fails
*/ */
@GwtIncompatible("ParseException is not supported in Xplat")
@J2ObjCIncompatible
public static Timestamp parse(String value) throws ParseException { public static Timestamp parse(String value) throws ParseException {
int dayOffset = value.indexOf('T'); int dayOffset = value.indexOf('T');
if (dayOffset == -1) { if (dayOffset == -1) {
@ -287,6 +297,8 @@ public final class Timestamps {
* @return a {@link Timestamp} parsed from the string * @return a {@link Timestamp} parsed from the string
* @throws IllegalArgumentException if parsing fails * @throws IllegalArgumentException if parsing fails
*/ */
@GwtIncompatible("Depends on String.format which is not supported in Xplat.")
@J2ObjCIncompatible
public static Timestamp parseUnchecked(@CompileTimeConstant String value) { public static Timestamp parseUnchecked(@CompileTimeConstant String value) {
try { try {
return parse(value); return parse(value);
@ -299,12 +311,23 @@ public final class Timestamps {
// the following 3 constants contain references to java.time.Instant methods (if that class is // the following 3 constants contain references to java.time.Instant methods (if that class is
// available at runtime); otherwise, they are null. // available at runtime); otherwise, they are null.
@Nullable private static final Method INSTANT_NOW = instantMethod("now"); @GwtIncompatible("Uses reflection to access methods of java.time.Instant")
@J2ObjCIncompatible
@Nullable
private static final Method INSTANT_NOW = instantMethod("now");
@Nullable private static final Method INSTANT_GET_EPOCH_SECOND = instantMethod("getEpochSecond"); @GwtIncompatible("Uses reflection to access methods of java.time.Instant")
@J2ObjCIncompatible
@Nullable
private static final Method INSTANT_GET_EPOCH_SECOND = instantMethod("getEpochSecond");
@Nullable private static final Method INSTANT_GET_NANO = instantMethod("getNano"); @GwtIncompatible("Uses reflection to access methods of java.time.Instant")
@J2ObjCIncompatible
@Nullable
private static final Method INSTANT_GET_NANO = instantMethod("getNano");
@GwtIncompatible("Uses reflection to access methods of java.time.Instant")
@J2ObjCIncompatible
@Nullable @Nullable
private static Method instantMethod(String methodName) { private static Method instantMethod(String methodName) {
try { try {
@ -321,6 +344,8 @@ public final class Timestamps {
* you're unable to mock the current time. Instead, you may want to consider injecting a clock * you're unable to mock the current time. Instead, you may want to consider injecting a clock
* instance to read the current time. * instance to read the current time.
*/ */
@GwtIncompatible("Uses reflection to access methods of java.time.Instant")
@J2ObjCIncompatible
public static Timestamp now() { public static Timestamp now() {
if (INSTANT_NOW != null) { if (INSTANT_NOW != null) {
try { try {
@ -469,7 +494,7 @@ public final class Timestamps {
// when normalized. // when normalized.
if (!isValidSeconds(seconds)) { if (!isValidSeconds(seconds)) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
String.format( Strings.lenientFormat(
"Timestamp is not valid. Input seconds is too large. " "Timestamp is not valid. Input seconds is too large. "
+ "Seconds (%s) must be in range [-62,135,596,800, +253,402,300,799]. ", + "Seconds (%s) must be in range [-62,135,596,800, +253,402,300,799]. ",
seconds)); seconds));
@ -488,6 +513,8 @@ public final class Timestamps {
return checkValid(timestamp); return checkValid(timestamp);
} }
@GwtIncompatible("Depends on String.format which is not supported in Xplat.")
@J2ObjCIncompatible
private static long parseTimezoneOffset(String value) throws ParseException { private static long parseTimezoneOffset(String value) throws ParseException {
int pos = value.indexOf(':'); int pos = value.indexOf(':');
if (pos == -1) { if (pos == -1) {
@ -504,6 +531,8 @@ public final class Timestamps {
} }
} }
@GwtIncompatible("Depends on String.format which is not supported in Xplat.")
@J2ObjCIncompatible
static int parseNanos(String value) throws ParseException { static int parseNanos(String value) throws ParseException {
int result = 0; int result = 0;
for (int i = 0; i < 9; ++i) { for (int i = 0; i < 9; ++i) {
@ -519,6 +548,8 @@ public final class Timestamps {
} }
/** Format the nano part of a timestamp or a duration. */ /** Format the nano part of a timestamp or a duration. */
@GwtIncompatible("Depends on String.format which is not supported in Xplat.")
@J2ObjCIncompatible
static String formatNanos(int nanos) { static String formatNanos(int nanos) {
// Determine whether to use 3, 6, or 9 digits for the nano part. // Determine whether to use 3, 6, or 9 digits for the nano part.
if (nanos % NANOS_PER_MILLISECOND == 0) { if (nanos % NANOS_PER_MILLISECOND == 0) {

@ -12,7 +12,9 @@ import static com.google.common.truth.Truth.assertWithMessage;
import static com.google.protobuf.util.Durations.toSecondsAsDouble; import static com.google.protobuf.util.Durations.toSecondsAsDouble;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import com.google.common.annotations.GwtIncompatible;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.j2objc.annotations.J2ObjCIncompatible;
import com.google.protobuf.Duration; import com.google.protobuf.Duration;
import com.google.protobuf.Timestamp; import com.google.protobuf.Timestamp;
import java.text.ParseException; import java.text.ParseException;
@ -47,6 +49,8 @@ public class DurationsTest {
} }
@Test @Test
@GwtIncompatible("Depends on String.format which is not supported in Xplat.")
@J2ObjCIncompatible
public void testCheckNotNegative() { public void testCheckNotNegative() {
Durations.checkNotNegative(Durations.ZERO); Durations.checkNotNegative(Durations.ZERO);
Durations.checkNotNegative(Durations.fromNanos(1)); Durations.checkNotNegative(Durations.fromNanos(1));
@ -68,6 +72,8 @@ public class DurationsTest {
} }
@Test @Test
@GwtIncompatible("Depends on String.format which is not supported in Xplat.")
@J2ObjCIncompatible
public void testCheckPositive() { public void testCheckPositive() {
Durations.checkPositive(Durations.fromNanos(1)); Durations.checkPositive(Durations.fromNanos(1));
Durations.checkPositive(Durations.fromSeconds(1)); Durations.checkPositive(Durations.fromSeconds(1));
@ -163,6 +169,8 @@ public class DurationsTest {
} }
@Test @Test
@GwtIncompatible("ParseException is not supported in Xplat")
@J2ObjCIncompatible
public void testParse_outOfRange() throws ParseException { public void testParse_outOfRange() throws ParseException {
try { try {
Durations.parse("316576000000.123456789123456789s"); Durations.parse("316576000000.123456789123456789s");
@ -174,6 +182,8 @@ public class DurationsTest {
} }
@Test @Test
@GwtIncompatible("Depends on String.format which is not supported in Xplat.")
@J2ObjCIncompatible
public void testDurationStringFormat() throws Exception { public void testDurationStringFormat() throws Exception {
Timestamp start = Timestamps.parse("0001-01-01T00:00:00Z"); Timestamp start = Timestamps.parse("0001-01-01T00:00:00Z");
Timestamp end = Timestamps.parse("9999-12-31T23:59:59.999999999Z"); Timestamp end = Timestamps.parse("9999-12-31T23:59:59.999999999Z");
@ -226,6 +236,8 @@ public class DurationsTest {
} }
@Test @Test
@GwtIncompatible("ParseException is not supported in Xplat")
@J2ObjCIncompatible
public void testDurationInvalidFormat() { public void testDurationInvalidFormat() {
// Value too small. // Value too small.
try { try {
@ -346,6 +358,8 @@ public class DurationsTest {
} }
@Test @Test
@GwtIncompatible("Depends on String.format which is not supported in Xplat.")
@J2ObjCIncompatible
public void testDurationConversion() throws Exception { public void testDurationConversion() throws Exception {
Duration duration = Durations.parse("1.111111111s"); Duration duration = Durations.parse("1.111111111s");
assertThat(Durations.toNanos(duration)).isEqualTo(1111111111); assertThat(Durations.toNanos(duration)).isEqualTo(1111111111);
@ -377,6 +391,8 @@ public class DurationsTest {
} }
@Test @Test
@GwtIncompatible("Depends on String.format which is not supported in Xplat.")
@J2ObjCIncompatible
public void testTimeOperations() throws Exception { public void testTimeOperations() throws Exception {
Timestamp start = Timestamps.parse("0001-01-01T00:00:00Z"); Timestamp start = Timestamps.parse("0001-01-01T00:00:00Z");
Timestamp end = Timestamps.parse("9999-12-31T23:59:59.999999999Z"); Timestamp end = Timestamps.parse("9999-12-31T23:59:59.999999999Z");
@ -406,6 +422,8 @@ public class DurationsTest {
} }
@Test @Test
@GwtIncompatible("Depends on String.format which is not supported in Xplat.")
@J2ObjCIncompatible
public void testToString() { public void testToString() {
assertThat(Durations.toString(duration(1, 1))).isEqualTo("1.000000001s"); assertThat(Durations.toString(duration(1, 1))).isEqualTo("1.000000001s");
assertThat(Durations.toString(duration(-1, -1))).isEqualTo("-1.000000001s"); assertThat(Durations.toString(duration(-1, -1))).isEqualTo("-1.000000001s");
@ -504,6 +522,8 @@ public class DurationsTest {
} }
@Test @Test
@GwtIncompatible("Depends on String.format which is not supported in Xplat.")
@J2ObjCIncompatible
public void testOverflows() throws Exception { public void testOverflows() throws Exception {
try { try {
Durations.toNanos(duration(315576000000L, 999999999)); Durations.toNanos(duration(315576000000L, 999999999));

@ -11,7 +11,9 @@ import static com.google.common.truth.Truth.assertThat;
import static com.google.protobuf.util.DurationsTest.duration; import static com.google.protobuf.util.DurationsTest.duration;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import com.google.common.annotations.GwtIncompatible;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.j2objc.annotations.J2ObjCIncompatible;
import com.google.protobuf.Duration; import com.google.protobuf.Duration;
import com.google.protobuf.Timestamp; import com.google.protobuf.Timestamp;
import java.text.ParseException; import java.text.ParseException;
@ -51,6 +53,8 @@ public class TimestampsTest {
Timestamp.newBuilder().setSeconds(Long.MIN_VALUE).setNanos(Integer.MIN_VALUE).build(); Timestamp.newBuilder().setSeconds(Long.MIN_VALUE).setNanos(Integer.MIN_VALUE).build();
@Test @Test
@GwtIncompatible("Uses reflection to access methods of java.time.Instant")
@J2ObjCIncompatible
public void testNow() { public void testNow() {
Timestamp now = Timestamps.now(); Timestamp now = Timestamps.now();
long epochSeconds = System.currentTimeMillis() / 1000; long epochSeconds = System.currentTimeMillis() / 1000;
@ -59,6 +63,8 @@ public class TimestampsTest {
} }
@Test @Test
@GwtIncompatible("Uses reflection to access methods of java.time.Instant")
@J2ObjCIncompatible
public void testNowWithSubMillisecondPrecision() { public void testNowWithSubMillisecondPrecision() {
try { try {
// throws if we're not on Java9+ // throws if we're not on Java9+
@ -110,6 +116,8 @@ public class TimestampsTest {
} }
@Test @Test
@GwtIncompatible("Depends on String.format which is not supported in Xplat.")
@J2ObjCIncompatible
public void testTimestampStringFormat() throws Exception { public void testTimestampStringFormat() throws Exception {
Timestamp start = Timestamps.parse("0001-01-01T00:00:00Z"); Timestamp start = Timestamps.parse("0001-01-01T00:00:00Z");
Timestamp end = Timestamps.parse("9999-12-31T23:59:59.999999999Z"); Timestamp end = Timestamps.parse("9999-12-31T23:59:59.999999999Z");
@ -159,6 +167,8 @@ public class TimestampsTest {
private volatile boolean stopParsingThreads = false; private volatile boolean stopParsingThreads = false;
private volatile String errorMessage = ""; private volatile String errorMessage = "";
@GwtIncompatible("ParseException is not supported in Xplat")
@J2ObjCIncompatible
private class ParseTimestampThread extends Thread { private class ParseTimestampThread extends Thread {
private final String[] strings; private final String[] strings;
private final Timestamp[] values; private final Timestamp[] values;
@ -192,6 +202,8 @@ public class TimestampsTest {
} }
@Test @Test
@GwtIncompatible("ParseException is not supported in Xplat")
@J2ObjCIncompatible
public void testTimestampConcurrentParsing() throws Exception { public void testTimestampConcurrentParsing() throws Exception {
String[] timestampStrings = String[] timestampStrings =
new String[] { new String[] {
@ -225,6 +237,8 @@ public class TimestampsTest {
} }
@Test @Test
@GwtIncompatible("Depends on String.format which is not supported in Xplat.")
@J2ObjCIncompatible
public void testTimestampInvalidFormatValueTooSmall() throws Exception { public void testTimestampInvalidFormatValueTooSmall() throws Exception {
try { try {
// Value too small. // Value too small.
@ -237,6 +251,8 @@ public class TimestampsTest {
} }
@Test @Test
@GwtIncompatible("Depends on String.format which is not supported in Xplat.")
@J2ObjCIncompatible
public void testTimestampInvalidFormatValueTooLarge() throws Exception { public void testTimestampInvalidFormatValueTooLarge() throws Exception {
try { try {
// Value too large. // Value too large.
@ -249,6 +265,8 @@ public class TimestampsTest {
} }
@Test @Test
@GwtIncompatible("Depends on String.format which is not supported in Xplat.")
@J2ObjCIncompatible
public void testTimestampInvalidFormatNanosTooSmall() throws Exception { public void testTimestampInvalidFormatNanosTooSmall() throws Exception {
try { try {
// Invalid nanos value. // Invalid nanos value.
@ -260,6 +278,8 @@ public class TimestampsTest {
} }
@Test @Test
@GwtIncompatible("Depends on String.format which is not supported in Xplat.")
@J2ObjCIncompatible
public void testTimestampInvalidFormatNanosTooLarge() throws Exception { public void testTimestampInvalidFormatNanosTooLarge() throws Exception {
try { try {
// Invalid nanos value. // Invalid nanos value.
@ -271,6 +291,8 @@ public class TimestampsTest {
} }
@Test @Test
@GwtIncompatible("ParseException is not supported in Xplat")
@J2ObjCIncompatible
public void testTimestampInvalidFormatDateTooSmall() { public void testTimestampInvalidFormatDateTooSmall() {
try { try {
Timestamps.parse("0000-01-01T00:00:00Z"); Timestamps.parse("0000-01-01T00:00:00Z");
@ -288,6 +310,8 @@ public class TimestampsTest {
} }
@Test @Test
@GwtIncompatible("ParseException is not supported in Xplat")
@J2ObjCIncompatible
public void testTimestampInvalidFormatDateTooLarge() { public void testTimestampInvalidFormatDateTooLarge() {
try { try {
Timestamps.parse("10000-01-01T00:00:00Z"); Timestamps.parse("10000-01-01T00:00:00Z");
@ -304,6 +328,8 @@ public class TimestampsTest {
} }
@Test @Test
@GwtIncompatible("ParseException is not supported in Xplat")
@J2ObjCIncompatible
public void testTimestampInvalidFormatMissingT() { public void testTimestampInvalidFormatMissingT() {
try { try {
Timestamps.parse("1970-01-01 00:00:00Z"); Timestamps.parse("1970-01-01 00:00:00Z");
@ -320,6 +346,8 @@ public class TimestampsTest {
} }
@Test @Test
@GwtIncompatible("ParseException is not supported in Xplat")
@J2ObjCIncompatible
public void testTimestampInvalidFormatMissingZ() { public void testTimestampInvalidFormatMissingZ() {
try { try {
Timestamps.parse("1970-01-01T00:00:00"); Timestamps.parse("1970-01-01T00:00:00");
@ -336,6 +364,8 @@ public class TimestampsTest {
} }
@Test @Test
@GwtIncompatible("ParseException is not supported in Xplat")
@J2ObjCIncompatible
public void testTimestampInvalidOffset() { public void testTimestampInvalidOffset() {
try { try {
Timestamps.parse("1970-01-01T00:00:00+0000"); Timestamps.parse("1970-01-01T00:00:00+0000");
@ -352,6 +382,8 @@ public class TimestampsTest {
} }
@Test @Test
@GwtIncompatible("ParseException is not supported in Xplat")
@J2ObjCIncompatible
public void testTimestampInvalidOffsetWithDot() { public void testTimestampInvalidOffsetWithDot() {
try { try {
Timestamps.parse("2021-08-19T10:24:25-07.:00"); Timestamps.parse("2021-08-19T10:24:25-07.:00");
@ -368,6 +400,8 @@ public class TimestampsTest {
} }
@Test @Test
@GwtIncompatible("ParseException is not supported in Xplat")
@J2ObjCIncompatible
public void testTimestampInvalidTrailingText() { public void testTimestampInvalidTrailingText() {
try { try {
Timestamps.parse("1970-01-01T00:00:00Z0"); Timestamps.parse("1970-01-01T00:00:00Z0");
@ -384,6 +418,8 @@ public class TimestampsTest {
} }
@Test @Test
@GwtIncompatible("ParseException is not supported in Xplat")
@J2ObjCIncompatible
public void testTimestampInvalidNanoSecond() { public void testTimestampInvalidNanoSecond() {
try { try {
Timestamps.parse("1970-01-01T00:00:00.ABCZ"); Timestamps.parse("1970-01-01T00:00:00.ABCZ");
@ -400,6 +436,8 @@ public class TimestampsTest {
} }
@Test @Test
@GwtIncompatible("Depends on String.format which is not supported in Xplat.")
@J2ObjCIncompatible
public void testTimestampConversion() throws Exception { public void testTimestampConversion() throws Exception {
Timestamp timestamp = Timestamps.parse("1970-01-01T00:00:01.111111111Z"); Timestamp timestamp = Timestamps.parse("1970-01-01T00:00:01.111111111Z");
assertThat(Timestamps.toNanos(timestamp)).isEqualTo(1111111111); assertThat(Timestamps.toNanos(timestamp)).isEqualTo(1111111111);
@ -431,6 +469,8 @@ public class TimestampsTest {
} }
@Test @Test
@GwtIncompatible("Depends on String.format which is not supported in Xplat.")
@J2ObjCIncompatible
public void testFromDate() { public void testFromDate() {
Date date = new Date(1111); Date date = new Date(1111);
Timestamp timestamp = Timestamps.fromDate(date); Timestamp timestamp = Timestamps.fromDate(date);
@ -438,6 +478,8 @@ public class TimestampsTest {
} }
@Test @Test
@GwtIncompatible("Calendar is not supported in non JVM java.time")
@J2ObjCIncompatible
public void testFromDate_after9999CE() { public void testFromDate_after9999CE() {
// protobuf still requires Java 7 so no java.time :-( // protobuf still requires Java 7 so no java.time :-(
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
@ -454,6 +496,8 @@ public class TimestampsTest {
} }
@Test @Test
@GwtIncompatible("Calendar is not supported in non JVM java.time")
@J2ObjCIncompatible
public void testFromDate_beforeYear1() { public void testFromDate_beforeYear1() {
// protobuf still requires Java 7 so no java.time :-( // protobuf still requires Java 7 so no java.time :-(
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
@ -470,6 +514,8 @@ public class TimestampsTest {
} }
@Test @Test
@GwtIncompatible("Calendar is not supported in non JVM java.time")
@J2ObjCIncompatible
public void testFromDate_after2262CE() { public void testFromDate_after2262CE() {
// protobuf still requires Java 7 so no java.time :-( // protobuf still requires Java 7 so no java.time :-(
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
@ -484,6 +530,8 @@ public class TimestampsTest {
/* Timestamp only stores integral seconds in the Date parent class and stores the nanosecond /* Timestamp only stores integral seconds in the Date parent class and stores the nanosecond
* adjustment in the Timestamp class. */ * adjustment in the Timestamp class. */
@Test @Test
@GwtIncompatible("Depends on String.format which is not supported in Xplat.")
@J2ObjCIncompatible
public void testFromSqlTimestampSubMillisecondPrecision() { public void testFromSqlTimestampSubMillisecondPrecision() {
java.sql.Timestamp sqlTimestamp = new java.sql.Timestamp(1111); java.sql.Timestamp sqlTimestamp = new java.sql.Timestamp(1111);
sqlTimestamp.setNanos(sqlTimestamp.getNanos() + 234567); sqlTimestamp.setNanos(sqlTimestamp.getNanos() + 234567);
@ -492,6 +540,8 @@ public class TimestampsTest {
} }
@Test @Test
@GwtIncompatible("Depends on String.format which is not supported in Xplat.")
@J2ObjCIncompatible
public void testFromSqlTimestamp() { public void testFromSqlTimestamp() {
Date date = new java.sql.Timestamp(1111); Date date = new java.sql.Timestamp(1111);
Timestamp timestamp = Timestamps.fromDate(date); Timestamp timestamp = Timestamps.fromDate(date);
@ -499,6 +549,8 @@ public class TimestampsTest {
} }
@Test @Test
@GwtIncompatible("Depends on String.format which is not supported in Xplat.")
@J2ObjCIncompatible
public void testFromSqlTimestamp_beforeEpoch() { public void testFromSqlTimestamp_beforeEpoch() {
Date date = new java.sql.Timestamp(-1111); Date date = new java.sql.Timestamp(-1111);
Timestamp timestamp = Timestamps.fromDate(date); Timestamp timestamp = Timestamps.fromDate(date);
@ -506,6 +558,8 @@ public class TimestampsTest {
} }
@Test @Test
@GwtIncompatible("Depends on String.format which is not supported in Xplat.")
@J2ObjCIncompatible
public void testFromSqlTimestamp_beforeEpochWholeSecond() { public void testFromSqlTimestamp_beforeEpochWholeSecond() {
Date date = new java.sql.Timestamp(-2000); Date date = new java.sql.Timestamp(-2000);
Timestamp timestamp = Timestamps.fromDate(date); Timestamp timestamp = Timestamps.fromDate(date);
@ -513,6 +567,8 @@ public class TimestampsTest {
} }
@Test @Test
@GwtIncompatible("ParseException is not supported in Xplat")
@J2ObjCIncompatible
public void testTimeOperations() throws Exception { public void testTimeOperations() throws Exception {
Timestamp start = Timestamps.parse("0001-01-01T00:00:00Z"); Timestamp start = Timestamps.parse("0001-01-01T00:00:00Z");
Timestamp end = Timestamps.parse("9999-12-31T23:59:59.999999999Z"); Timestamp end = Timestamps.parse("9999-12-31T23:59:59.999999999Z");
@ -603,6 +659,8 @@ public class TimestampsTest {
} }
@Test @Test
@GwtIncompatible("ParseException is not supported in Xplat")
@J2ObjCIncompatible
public void testOverflowsArithmeticException() throws Exception { public void testOverflowsArithmeticException() throws Exception {
try { try {
Timestamps.toNanos(Timestamps.parse("9999-12-31T23:59:59.999999999Z")); Timestamps.toNanos(Timestamps.parse("9999-12-31T23:59:59.999999999Z"));
@ -702,6 +760,8 @@ public class TimestampsTest {
} }
@Test @Test
@GwtIncompatible("Depends on String.format which is not supported in Xplat.")
@J2ObjCIncompatible
public void testMaxNanosecondsConversion() { public void testMaxNanosecondsConversion() {
assertThat(Timestamps.toString(Timestamps.fromNanos(Long.MAX_VALUE))) assertThat(Timestamps.toString(Timestamps.fromNanos(Long.MAX_VALUE)))
.isEqualTo("2262-04-11T23:47:16.854775807Z"); .isEqualTo("2262-04-11T23:47:16.854775807Z");
@ -726,6 +786,8 @@ public class TimestampsTest {
} }
@Test @Test
@GwtIncompatible("Depends on String.format which is not supported in Xplat.")
@J2ObjCIncompatible
public void testMinNanosecondsConversion() { public void testMinNanosecondsConversion() {
assertThat(Timestamps.toString(Timestamps.fromNanos(Long.MIN_VALUE))) assertThat(Timestamps.toString(Timestamps.fromNanos(Long.MIN_VALUE)))
.isEqualTo("1677-09-21T00:12:43.145224192Z"); .isEqualTo("1677-09-21T00:12:43.145224192Z");

Loading…
Cancel
Save