Skip to content

Commit

Permalink
Removing non-deprecated uses of joda time. (googleapis#4351)
Browse files Browse the repository at this point in the history
* Removing non-deprecated uses of joda time.
This works towards googleapis#3482

* Update pom.xml

* Ran `mvn com.coveo:fmt-maven-plugin:format`

* Fixing a bad merge
  • Loading branch information
sduskis authored Jan 24, 2019
1 parent e23b5c0 commit 9cc9609
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
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

0 comments on commit 9cc9609

Please sign in to comment.