Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing non-deprecated uses of joda time. #4351

Merged
merged 6 commits into from
Jan 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -297,31 +298,31 @@ private static <T> 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;
Expand All @@ -332,6 +333,14 @@ private static <T> 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();

Expand Down
5 changes: 5 additions & 0 deletions google-cloud-clients/google-cloud-compute/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
<artifactId>google-api-services-compute</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
chingor13 marked this conversation as resolved.
Show resolved Hide resolved
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<scope>compile</scope>
</dependency>

<!-- Test dependencies -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@
<pattern>org</pattern>
<shadedPattern>shaded.cloud_nio.org</shadedPattern>
<includes>
<include>org.joda.**</include>
<include>org.apache.**</include>
<include>org.threeten.**</include>
<include>org.codehaus.**</include>
Expand Down
5 changes: 0 additions & 5 deletions google-cloud-clients/google-cloud-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -46,8 +45,7 @@ public final class Timestamp implements Comparable<Timestamp>, 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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());
Expand All @@ -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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.");
Expand Down
4 changes: 0 additions & 4 deletions google-cloud-clients/google-cloud-spanner/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,6 @@
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
</dependency>

<!-- Test dependencies -->
<dependency>
Expand Down