diff --git a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryParameterValue.java b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryParameterValue.java index d74fc005f35c..5bf6b4e9f93a 100644 --- a/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryParameterValue.java +++ b/google-cloud-clients/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryParameterValue.java @@ -27,9 +27,10 @@ import java.util.ArrayList; import java.util.List; import javax.annotation.Nullable; -import org.joda.time.DateTimeZone; -import org.joda.time.format.DateTimeFormat; -import org.joda.time.format.DateTimeFormatter; +import org.threeten.bp.Instant; +import org.threeten.bp.ZoneOffset; +import org.threeten.bp.format.DateTimeFormatter; +import org.threeten.bp.format.DateTimeParseException; /** * A value for a QueryParameter along with its type. @@ -60,12 +61,12 @@ public abstract class QueryParameterValue implements Serializable { private static final DateTimeFormatter timestampFormatter = - DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss.SSSSSSZZ").withZone(DateTimeZone.UTC); - private static final DateTimeFormatter dateFormatter = DateTimeFormat.forPattern("yyyy-MM-dd"); + DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSSxxx").withZone(ZoneOffset.UTC); + private static final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); private static final DateTimeFormatter timeFormatter = - DateTimeFormat.forPattern("HH:mm:ss.SSSSSS"); + DateTimeFormatter.ofPattern("HH:mm:ss.SSSSSS"); private static final DateTimeFormatter datetimeFormatter = - DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss.SSSSSS"); + DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSS"); static final Function< QueryParameterValue, com.google.api.services.bigquery.model.QueryParameterValue> @@ -297,31 +298,31 @@ private static String valueToStringOrNull(T value, StandardSQLTypeName type) throw new IllegalArgumentException("Cannot convert ARRAY to String value"); case TIMESTAMP: if (value instanceof Long) { - return timestampFormatter.print(((Long) value) / 1000); + return timestampFormatter.format(Instant.ofEpochMilli(((Long) value) / 1000)); } else if (value instanceof String) { // verify that the String is in the right format - timestampFormatter.parseMillis((String) value); + checkFormat(value, timestampFormatter); return (String) value; } break; case DATE: if (value instanceof String) { // verify that the String is in the right format - dateFormatter.parseMillis((String) value); + checkFormat(value, dateFormatter); return (String) value; } break; case TIME: if (value instanceof String) { // verify that the String is in the right format - timeFormatter.parseMillis((String) value); + checkFormat(value, timeFormatter); return (String) value; } break; case DATETIME: if (value instanceof String) { // verify that the String is in the right format - datetimeFormatter.parseMillis((String) value); + checkFormat(value, datetimeFormatter); return (String) value; } break; @@ -332,6 +333,14 @@ private static String valueToStringOrNull(T value, StandardSQLTypeName type) "Type " + type + " incompatible with " + value.getClass().getCanonicalName()); } + private static void checkFormat(Object value, DateTimeFormatter formatter) { + try { + formatter.parse((String) value); + } catch (DateTimeParseException e) { + throw new IllegalArgumentException(e.getMessage(), e); + } + } + /** Returns a builder for a QueryParameterValue object with given value. */ public abstract Builder toBuilder(); diff --git a/google-cloud-clients/google-cloud-compute/pom.xml b/google-cloud-clients/google-cloud-compute/pom.xml index dc9fa1c70e3d..3b8f5ff6a716 100644 --- a/google-cloud-clients/google-cloud-compute/pom.xml +++ b/google-cloud-clients/google-cloud-compute/pom.xml @@ -31,6 +31,11 @@ google-api-services-compute compile + + joda-time + joda-time + compile + diff --git a/google-cloud-clients/google-cloud-contrib/google-cloud-nio/pom.xml b/google-cloud-clients/google-cloud-contrib/google-cloud-nio/pom.xml index 8ffa10116405..76d2c3bc9093 100644 --- a/google-cloud-clients/google-cloud-contrib/google-cloud-nio/pom.xml +++ b/google-cloud-clients/google-cloud-contrib/google-cloud-nio/pom.xml @@ -112,7 +112,6 @@ org shaded.cloud_nio.org - org.joda.** org.apache.** org.threeten.** org.codehaus.** diff --git a/google-cloud-clients/google-cloud-core/pom.xml b/google-cloud-clients/google-cloud-core/pom.xml index efdf6565aad0..13ff53638468 100644 --- a/google-cloud-clients/google-cloud-core/pom.xml +++ b/google-cloud-clients/google-cloud-core/pom.xml @@ -27,11 +27,6 @@ junit test - - joda-time - joda-time - compile - com.google.http-client google-http-client diff --git a/google-cloud-clients/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java b/google-cloud-clients/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java index dc44f8abea10..02bb98131366 100644 --- a/google-cloud-clients/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java +++ b/google-cloud-clients/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java @@ -26,7 +26,6 @@ import org.threeten.bp.Instant; import org.threeten.bp.LocalDateTime; import org.threeten.bp.ZoneOffset; -import org.threeten.bp.chrono.IsoChronology; import org.threeten.bp.format.DateTimeFormatter; /** @@ -46,8 +45,7 @@ public final class Timestamp implements Comparable, Serializable { public static final Timestamp MAX_VALUE = new Timestamp(253402300799L, (int) TimeUnit.SECONDS.toNanos(1) - 1); - private static final DateTimeFormatter format = - DateTimeFormatter.ISO_LOCAL_DATE_TIME.withChronology(IsoChronology.INSTANCE); + private static final DateTimeFormatter format = DateTimeFormatter.ISO_LOCAL_DATE_TIME; private final long seconds; private final int nanos; diff --git a/google-cloud-clients/google-cloud-dns/src/main/java/com/google/cloud/dns/ChangeRequestInfo.java b/google-cloud-clients/google-cloud-dns/src/main/java/com/google/cloud/dns/ChangeRequestInfo.java index fa93b4f7c161..a7802045e068 100644 --- a/google-cloud-clients/google-cloud-dns/src/main/java/com/google/cloud/dns/ChangeRequestInfo.java +++ b/google-cloud-clients/google-cloud-dns/src/main/java/com/google/cloud/dns/ChangeRequestInfo.java @@ -30,8 +30,9 @@ import java.util.LinkedList; import java.util.List; import java.util.Objects; -import org.joda.time.DateTime; -import org.joda.time.format.ISODateTimeFormat; +import org.threeten.bp.Instant; +import org.threeten.bp.ZoneOffset; +import org.threeten.bp.format.DateTimeFormatter; /** * A class representing an atomic update to a collection of {@link RecordSet}s within a {@code @@ -328,7 +329,10 @@ Change toPb() { } // set timestamp if (getStartTimeMillis() != null) { - pb.setStartTime(ISODateTimeFormat.dateTime().withZoneUTC().print(getStartTimeMillis())); + pb.setStartTime( + DateTimeFormatter.ISO_DATE_TIME + .withZone(ZoneOffset.UTC) + .format(Instant.ofEpochMilli(getStartTimeMillis()))); } // set status if (status() != null) { @@ -347,7 +351,8 @@ static ChangeRequestInfo fromPb(Change pb) { builder.setGeneratedId(pb.getId()); } if (pb.getStartTime() != null) { - builder.setStartTime(DateTime.parse(pb.getStartTime()).getMillis()); + builder.setStartTime( + DateTimeFormatter.ISO_DATE_TIME.parse(pb.getStartTime(), Instant.FROM).toEpochMilli()); } if (pb.getStatus() != null) { // we are assuming that status indicated in pb is a lower case version of the enum name diff --git a/google-cloud-clients/google-cloud-dns/src/main/java/com/google/cloud/dns/ZoneInfo.java b/google-cloud-clients/google-cloud-dns/src/main/java/com/google/cloud/dns/ZoneInfo.java index bc0592dd3ff4..a66167341793 100644 --- a/google-cloud-clients/google-cloud-dns/src/main/java/com/google/cloud/dns/ZoneInfo.java +++ b/google-cloud-clients/google-cloud-dns/src/main/java/com/google/cloud/dns/ZoneInfo.java @@ -26,8 +26,9 @@ import java.math.BigInteger; import java.util.List; import java.util.Objects; -import org.joda.time.DateTime; -import org.joda.time.format.ISODateTimeFormat; +import org.threeten.bp.Instant; +import org.threeten.bp.ZoneOffset; +import org.threeten.bp.format.DateTimeFormatter; /** * A {@code Zone} represents a DNS zone hosted by the Google Cloud DNS service. A zone is a subtree @@ -38,6 +39,9 @@ public class ZoneInfo implements Serializable { private static final long serialVersionUID = -5313169712036079818L; + private static final DateTimeFormatter DATE_TIME_FORMATTER = + DateTimeFormatter.ISO_DATE_TIME.withZone(ZoneOffset.UTC); + private final String name; private final String generatedId; private final Long creationTimeMillis; @@ -234,7 +238,7 @@ ManagedZone toPb() { pb.setNameServerSet(this.getNameServerSet()); if (this.getCreationTimeMillis() != null) { pb.setCreationTime( - ISODateTimeFormat.dateTime().withZoneUTC().print(this.getCreationTimeMillis())); + DATE_TIME_FORMATTER.format(Instant.ofEpochMilli(this.getCreationTimeMillis()))); } return pb; } @@ -257,7 +261,8 @@ static ZoneInfo fromPb(ManagedZone pb) { builder.setNameServerSet(pb.getNameServerSet()); } if (pb.getCreationTime() != null) { - builder.setCreationTimeMillis(DateTime.parse(pb.getCreationTime()).getMillis()); + builder.setCreationTimeMillis( + DATE_TIME_FORMATTER.parse(pb.getCreationTime(), Instant.FROM).toEpochMilli()); } return builder.build(); } diff --git a/google-cloud-clients/google-cloud-resourcemanager/src/main/java/com/google/cloud/resourcemanager/ProjectInfo.java b/google-cloud-clients/google-cloud-resourcemanager/src/main/java/com/google/cloud/resourcemanager/ProjectInfo.java index 75e2021b6194..d20c3ccd86e3 100644 --- a/google-cloud-clients/google-cloud-resourcemanager/src/main/java/com/google/cloud/resourcemanager/ProjectInfo.java +++ b/google-cloud-clients/google-cloud-resourcemanager/src/main/java/com/google/cloud/resourcemanager/ProjectInfo.java @@ -29,8 +29,9 @@ import java.util.HashMap; import java.util.Map; import java.util.Objects; -import org.joda.time.DateTime; -import org.joda.time.format.ISODateTimeFormat; +import org.threeten.bp.Instant; +import org.threeten.bp.ZoneOffset; +import org.threeten.bp.format.DateTimeFormatter; /** * A Google Cloud Resource Manager project metadata object. A Project is a high-level Google Cloud @@ -39,6 +40,8 @@ */ public class ProjectInfo implements Serializable { + public static final DateTimeFormatter DATE_TIME_FORMATTER = + DateTimeFormatter.ISO_DATE_TIME.withZone(ZoneOffset.UTC); private static final long serialVersionUID = 9148970963697734236L; private final String name; private final String projectId; @@ -390,7 +393,10 @@ com.google.api.services.cloudresourcemanager.model.Project toPb() { projectPb.setLifecycleState(state.toString()); } if (createTimeMillis != null) { - projectPb.setCreateTime(ISODateTimeFormat.dateTime().withZoneUTC().print(createTimeMillis)); + projectPb.setCreateTime( + DateTimeFormatter.ISO_DATE_TIME + .withZone(ZoneOffset.UTC) + .format(Instant.ofEpochMilli(createTimeMillis))); } if (parent != null) { projectPb.setParent(parent.toPb()); @@ -411,7 +417,8 @@ static ProjectInfo fromPb(com.google.api.services.cloudresourcemanager.model.Pro builder.setState(State.valueOf(projectPb.getLifecycleState())); } if (projectPb.getCreateTime() != null) { - builder.setCreateTimeMillis(DateTime.parse(projectPb.getCreateTime()).getMillis()); + builder.setCreateTimeMillis( + DATE_TIME_FORMATTER.parse(projectPb.getCreateTime(), Instant.FROM).toEpochMilli()); } if (projectPb.getParent() != null) { builder.setParent(ResourceId.fromPb(projectPb.getParent())); diff --git a/google-cloud-clients/google-cloud-resourcemanager/src/main/java/com/google/cloud/resourcemanager/testing/LocalResourceManagerHelper.java b/google-cloud-clients/google-cloud-resourcemanager/src/main/java/com/google/cloud/resourcemanager/testing/LocalResourceManagerHelper.java index 70163f00f6a3..bbaa25d72ae8 100644 --- a/google-cloud-clients/google-cloud-resourcemanager/src/main/java/com/google/cloud/resourcemanager/testing/LocalResourceManagerHelper.java +++ b/google-cloud-clients/google-cloud-resourcemanager/src/main/java/com/google/cloud/resourcemanager/testing/LocalResourceManagerHelper.java @@ -61,7 +61,9 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.zip.GZIPInputStream; -import org.joda.time.format.ISODateTimeFormat; +import org.threeten.bp.Instant; +import org.threeten.bp.ZoneOffset; +import org.threeten.bp.format.DateTimeFormatter; /** * Utility to create a local Resource Manager mock for testing. @@ -443,7 +445,10 @@ synchronized Response create(Project project) { } else { project.setLifecycleState("ACTIVE"); project.setProjectNumber(Math.abs(PROJECT_NUMBER_GENERATOR.nextLong() % Long.MAX_VALUE)); - project.setCreateTime(ISODateTimeFormat.dateTime().print(System.currentTimeMillis())); + project.setCreateTime( + DateTimeFormatter.ISO_DATE_TIME + .withZone(ZoneOffset.UTC) + .format(Instant.ofEpochMilli(System.currentTimeMillis()))); if (projects.putIfAbsent(project.getProjectId(), project) != null) { return Error.ALREADY_EXISTS.response( "A project with the same project ID (" + project.getProjectId() + ") already exists."); diff --git a/google-cloud-clients/google-cloud-spanner/pom.xml b/google-cloud-clients/google-cloud-spanner/pom.xml index f4861214f053..cf4075bd5e4f 100644 --- a/google-cloud-clients/google-cloud-spanner/pom.xml +++ b/google-cloud-clients/google-cloud-spanner/pom.xml @@ -129,10 +129,6 @@ com.google.code.findbugs jsr305 - - joda-time - joda-time -