Skip to content

Commit 4e4ce6c

Browse files
authored
Removing joda (#4471)
* Removing joda * Updating examples to use threeten it looks like the examples were using joda, but there was not an explicit dependency in the pom.xml file.
1 parent 77d1841 commit 4e4ce6c

File tree

19 files changed

+189
-118
lines changed

19 files changed

+189
-118
lines changed

google-cloud-clients/google-cloud-compute/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@
3131
<artifactId>google-api-services-compute</artifactId>
3232
<scope>compile</scope>
3333
</dependency>
34-
<dependency>
35-
<groupId>joda-time</groupId>
36-
<artifactId>joda-time</artifactId>
37-
<scope>compile</scope>
38-
</dependency>
3934

4035
<!-- Test dependencies -->
4136
<dependency>

google-cloud-clients/google-cloud-compute/src/main/java/com/google/cloud/compute/deprecated/AddressInfo.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@
2727
import java.math.BigInteger;
2828
import java.util.List;
2929
import java.util.Objects;
30-
import org.joda.time.format.DateTimeFormatter;
31-
import org.joda.time.format.ISODateTimeFormat;
30+
import org.threeten.bp.Instant;
31+
import org.threeten.bp.ZoneOffset;
32+
import org.threeten.bp.format.DateTimeFormatter;
3233

3334
/**
3435
* A Google Compute Engine address. With Compute Engine you can create static external IP addresses
@@ -61,7 +62,8 @@ public Address apply(AddressInfo addressInfo) {
6162
};
6263

6364
private static final long serialVersionUID = 7678434703520207500L;
64-
private static final DateTimeFormatter TIMESTAMP_FORMATTER = ISODateTimeFormat.dateTime();
65+
private static final DateTimeFormatter TIMESTAMP_FORMATTER =
66+
DateTimeFormatter.ISO_DATE_TIME.withZone(ZoneOffset.UTC);
6567

6668
private final String address;
6769
private final Long creationTimestamp;
@@ -324,7 +326,10 @@ static final class BuilderImpl extends Builder {
324326
}
325327
address = addressPb.getAddress();
326328
if (addressPb.getCreationTimestamp() != null) {
327-
creationTimestamp = TIMESTAMP_FORMATTER.parseMillis(addressPb.getCreationTimestamp());
329+
creationTimestamp =
330+
TIMESTAMP_FORMATTER
331+
.parse(addressPb.getCreationTimestamp(), Instant.FROM)
332+
.toEpochMilli();
328333
}
329334
description = addressPb.getDescription();
330335
if (addressPb.getId() != null) {
@@ -485,7 +490,8 @@ Address toPb() {
485490
Address addressPb = usage != null ? usage.toPb() : new Address();
486491
addressPb.setAddress(address);
487492
if (creationTimestamp != null) {
488-
addressPb.setCreationTimestamp(TIMESTAMP_FORMATTER.print(creationTimestamp));
493+
addressPb.setCreationTimestamp(
494+
TIMESTAMP_FORMATTER.format(Instant.ofEpochMilli(creationTimestamp)));
489495
}
490496
addressPb.setDescription(description);
491497
if (generatedId != null) {

google-cloud-clients/google-cloud-compute/src/main/java/com/google/cloud/compute/deprecated/DeprecationStatus.java

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222
import com.google.common.base.MoreObjects;
2323
import java.io.Serializable;
2424
import java.util.Objects;
25-
import org.joda.time.format.DateTimeFormatter;
26-
import org.joda.time.format.ISODateTimeFormat;
25+
import org.threeten.bp.Instant;
26+
import org.threeten.bp.ZoneOffset;
27+
import org.threeten.bp.format.DateTimeFormatter;
28+
import org.threeten.bp.format.DateTimeParseException;
2729

2830
/**
2931
* The deprecation status associated to a Google Compute Engine resource.
@@ -33,8 +35,8 @@
3335
public final class DeprecationStatus<T extends ResourceId> implements Serializable {
3436

3537
private static final long serialVersionUID = -2695077634793679794L;
36-
private static final DateTimeFormatter TIMESTAMP_FORMATTER = ISODateTimeFormat.dateTime();
37-
private static final DateTimeFormatter TIMESTAMP_PARSER = ISODateTimeFormat.dateTimeParser();
38+
private static final DateTimeFormatter TIMESTAMP_FORMATTER =
39+
DateTimeFormatter.ISO_DATE_TIME.withZone(ZoneOffset.UTC);
3840

3941
private final String deleted;
4042
private final String deprecated;
@@ -127,7 +129,7 @@ Builder<T> setObsolete(String obsolete) {
127129
* to {@link Status#DELETED}. In milliseconds since epoch.
128130
*/
129131
public Builder<T> setDeleted(long deleted) {
130-
this.deleted = TIMESTAMP_FORMATTER.print(deleted);
132+
this.deleted = TIMESTAMP_FORMATTER.format(Instant.ofEpochMilli(deleted));
131133
return this;
132134
}
133135

@@ -136,7 +138,7 @@ public Builder<T> setDeleted(long deleted) {
136138
* to {@link Status#DEPRECATED}. In milliseconds since epoch.
137139
*/
138140
public Builder<T> setDeprecated(long deprecated) {
139-
this.deprecated = TIMESTAMP_FORMATTER.print(deprecated);
141+
this.deprecated = TIMESTAMP_FORMATTER.format(Instant.ofEpochMilli(deprecated));
140142
return this;
141143
}
142144

@@ -145,7 +147,7 @@ public Builder<T> setDeprecated(long deprecated) {
145147
* to {@link Status#OBSOLETE}. In milliseconds since epoch.
146148
*/
147149
public Builder<T> setObsolete(long obsolete) {
148-
this.obsolete = TIMESTAMP_FORMATTER.print(obsolete);
150+
this.obsolete = TIMESTAMP_FORMATTER.format(Instant.ofEpochMilli(obsolete));
149151
return this;
150152
}
151153

@@ -222,8 +224,10 @@ public String getObsolete() {
222224
*/
223225
public Long getDeletedMillis() {
224226
try {
225-
return deleted != null ? TIMESTAMP_PARSER.parseMillis(deleted) : null;
226-
} catch (IllegalArgumentException ex) {
227+
return deleted != null
228+
? TIMESTAMP_FORMATTER.parse(deleted, Instant.FROM).toEpochMilli()
229+
: null;
230+
} catch (DateTimeParseException ex) {
227231
throw new IllegalStateException(ex.getMessage(), ex);
228232
}
229233
}
@@ -236,8 +240,10 @@ public Long getDeletedMillis() {
236240
*/
237241
public Long getDeprecatedMillis() {
238242
try {
239-
return deprecated != null ? TIMESTAMP_PARSER.parseMillis(deprecated) : null;
240-
} catch (IllegalArgumentException ex) {
243+
return deprecated != null
244+
? TIMESTAMP_FORMATTER.parse(deprecated, Instant.FROM).toEpochMilli()
245+
: null;
246+
} catch (DateTimeParseException ex) {
241247
throw new IllegalStateException(ex.getMessage(), ex);
242248
}
243249
}
@@ -250,8 +256,10 @@ public Long getDeprecatedMillis() {
250256
*/
251257
public Long getObsoleteMillis() {
252258
try {
253-
return obsolete != null ? TIMESTAMP_PARSER.parseMillis(obsolete) : null;
254-
} catch (IllegalArgumentException ex) {
259+
return obsolete != null
260+
? TIMESTAMP_FORMATTER.parse(obsolete, Instant.FROM).toEpochMilli()
261+
: null;
262+
} catch (DateTimeParseException ex) {
255263
throw new IllegalStateException(ex.getMessage(), ex);
256264
}
257265
}

google-cloud-clients/google-cloud-compute/src/main/java/com/google/cloud/compute/deprecated/DiskInfo.java

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@
2727
import java.math.BigInteger;
2828
import java.util.List;
2929
import java.util.Objects;
30-
import org.joda.time.format.DateTimeFormatter;
31-
import org.joda.time.format.ISODateTimeFormat;
30+
import org.threeten.bp.Instant;
31+
import org.threeten.bp.ZoneOffset;
32+
import org.threeten.bp.format.DateTimeFormatter;
3233

3334
/**
3435
* A Google Compute Engine persistent disk. A disk can be used as primary storage for your virtual
@@ -54,7 +55,8 @@ public Disk apply(DiskInfo diskType) {
5455
};
5556

5657
private static final long serialVersionUID = -7173418340679279619L;
57-
private static final DateTimeFormatter TIMESTAMP_FORMATTER = ISODateTimeFormat.dateTime();
58+
private static final DateTimeFormatter TIMESTAMP_FORMATTER =
59+
DateTimeFormatter.ISO_DATE_TIME.withZone(ZoneOffset.UTC);
5860

5961
private final String generatedId;
6062
private final DiskId diskId;
@@ -149,7 +151,8 @@ static final class BuilderImpl extends Builder {
149151
}
150152
this.configuration = DiskConfiguration.fromPb(diskPb);
151153
if (diskPb.getCreationTimestamp() != null) {
152-
this.creationTimestamp = TIMESTAMP_FORMATTER.parseMillis(diskPb.getCreationTimestamp());
154+
this.creationTimestamp =
155+
TIMESTAMP_FORMATTER.parse(diskPb.getCreationTimestamp(), Instant.FROM).toEpochMilli();
153156
}
154157
if (diskPb.getStatus() != null) {
155158
this.creationStatus = CreationStatus.valueOf(diskPb.getStatus());
@@ -163,10 +166,12 @@ static final class BuilderImpl extends Builder {
163166
this.attachedInstances = Lists.transform(diskPb.getUsers(), InstanceId.FROM_URL_FUNCTION);
164167
}
165168
if (diskPb.getLastAttachTimestamp() != null) {
166-
this.lastAttachTimestamp = TIMESTAMP_FORMATTER.parseMillis(diskPb.getLastAttachTimestamp());
169+
this.lastAttachTimestamp =
170+
TIMESTAMP_FORMATTER.parse(diskPb.getLastAttachTimestamp(), Instant.FROM).toEpochMilli();
167171
}
168172
if (diskPb.getLastDetachTimestamp() != null) {
169-
this.lastDetachTimestamp = TIMESTAMP_FORMATTER.parseMillis(diskPb.getLastDetachTimestamp());
173+
this.lastDetachTimestamp =
174+
TIMESTAMP_FORMATTER.parse(diskPb.getLastDetachTimestamp(), Instant.FROM).toEpochMilli();
170175
}
171176
}
172177

@@ -377,7 +382,8 @@ Disk toPb() {
377382
diskPb.setId(new BigInteger(generatedId));
378383
}
379384
if (creationTimestamp != null) {
380-
diskPb.setCreationTimestamp(TIMESTAMP_FORMATTER.print(creationTimestamp));
385+
diskPb.setCreationTimestamp(
386+
TIMESTAMP_FORMATTER.format(Instant.ofEpochMilli(creationTimestamp)));
381387
}
382388
diskPb.setZone(diskId.getZoneId().getSelfLink());
383389
if (creationStatus != null) {
@@ -393,10 +399,12 @@ Disk toPb() {
393399
diskPb.setUsers(Lists.transform(attachedInstances, InstanceId.TO_URL_FUNCTION));
394400
}
395401
if (lastAttachTimestamp != null) {
396-
diskPb.setLastAttachTimestamp(TIMESTAMP_FORMATTER.print(lastAttachTimestamp));
402+
diskPb.setLastAttachTimestamp(
403+
TIMESTAMP_FORMATTER.format(Instant.ofEpochMilli(lastAttachTimestamp)));
397404
}
398405
if (lastDetachTimestamp != null) {
399-
diskPb.setLastDetachTimestamp(TIMESTAMP_FORMATTER.print(lastDetachTimestamp));
406+
diskPb.setLastDetachTimestamp(
407+
TIMESTAMP_FORMATTER.format(Instant.ofEpochMilli(lastDetachTimestamp)));
400408
}
401409
return diskPb;
402410
}

google-cloud-clients/google-cloud-compute/src/main/java/com/google/cloud/compute/deprecated/DiskType.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121
import java.io.Serializable;
2222
import java.math.BigInteger;
2323
import java.util.Objects;
24-
import org.joda.time.format.DateTimeFormatter;
25-
import org.joda.time.format.ISODateTimeFormat;
24+
import org.threeten.bp.Instant;
25+
import org.threeten.bp.ZoneOffset;
26+
import org.threeten.bp.format.DateTimeFormatter;
2627

2728
/**
2829
* A Google Compute Engine disk type. A disk type represents the type of disk to use, such as {@code
@@ -48,7 +49,8 @@ public com.google.api.services.compute.model.DiskType apply(DiskType diskType) {
4849
};
4950

5051
private static final long serialVersionUID = -944042261695072026L;
51-
private static final DateTimeFormatter TIMESTAMP_FORMATTER = ISODateTimeFormat.dateTime();
52+
private static final DateTimeFormatter TIMESTAMP_FORMATTER =
53+
DateTimeFormatter.ISO_DATE_TIME.withZone(ZoneOffset.UTC);
5254

5355
private final String generatedId;
5456
private final DiskTypeId diskTypeId;
@@ -191,7 +193,8 @@ com.google.api.services.compute.model.DiskType toPb() {
191193
diskTypePb.setId(new BigInteger(generatedId));
192194
}
193195
if (creationTimestamp != null) {
194-
diskTypePb.setCreationTimestamp(TIMESTAMP_FORMATTER.print(creationTimestamp));
196+
diskTypePb.setCreationTimestamp(
197+
TIMESTAMP_FORMATTER.format(Instant.ofEpochMilli(creationTimestamp)));
195198
}
196199
diskTypePb.setDescription(description);
197200
diskTypePb.setValidDiskSize(validDiskSize);
@@ -215,7 +218,9 @@ static DiskType fromPb(com.google.api.services.compute.model.DiskType diskTypePb
215218
}
216219
if (diskTypePb.getCreationTimestamp() != null) {
217220
builder.setCreationTimestamp(
218-
TIMESTAMP_FORMATTER.parseMillis(diskTypePb.getCreationTimestamp()));
221+
TIMESTAMP_FORMATTER
222+
.parse(diskTypePb.getCreationTimestamp(), Instant.FROM)
223+
.toEpochMilli());
219224
}
220225
builder.setDiskTypeId(DiskTypeId.fromUrl(diskTypePb.getSelfLink()));
221226
builder.setDescription(diskTypePb.getDescription());

google-cloud-clients/google-cloud-compute/src/main/java/com/google/cloud/compute/deprecated/ImageInfo.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@
2727
import java.math.BigInteger;
2828
import java.util.List;
2929
import java.util.Objects;
30-
import org.joda.time.format.DateTimeFormatter;
31-
import org.joda.time.format.ISODateTimeFormat;
30+
import org.threeten.bp.Instant;
31+
import org.threeten.bp.ZoneOffset;
32+
import org.threeten.bp.format.DateTimeFormatter;
3233

3334
/**
3435
* A Google Compute Engine Image. An image contains a boot loader, an operating system and a root
@@ -59,7 +60,8 @@ public Image apply(ImageInfo image) {
5960
};
6061

6162
private static final long serialVersionUID = -1061916352807358977L;
62-
private static final DateTimeFormatter TIMESTAMP_FORMATTER = ISODateTimeFormat.dateTime();
63+
private static final DateTimeFormatter TIMESTAMP_FORMATTER =
64+
DateTimeFormatter.ISO_DATE_TIME.withZone(ZoneOffset.UTC);
6365

6466
private final String generatedId;
6567
private final ImageId imageId;
@@ -149,7 +151,8 @@ static final class BuilderImpl extends Builder {
149151
this.generatedId = imagePb.getId().toString();
150152
}
151153
if (imagePb.getCreationTimestamp() != null) {
152-
this.creationTimestamp = TIMESTAMP_FORMATTER.parseMillis(imagePb.getCreationTimestamp());
154+
this.creationTimestamp =
155+
TIMESTAMP_FORMATTER.parse(imagePb.getCreationTimestamp(), Instant.FROM).toEpochMilli();
153156
}
154157
this.imageId = ImageId.fromUrl(imagePb.getSelfLink());
155158
this.description = imagePb.getDescription();
@@ -350,7 +353,8 @@ Image toPb() {
350353
imagePb.setId(new BigInteger(generatedId));
351354
}
352355
if (creationTimestamp != null) {
353-
imagePb.setCreationTimestamp(TIMESTAMP_FORMATTER.print(creationTimestamp));
356+
imagePb.setCreationTimestamp(
357+
TIMESTAMP_FORMATTER.format(Instant.ofEpochMilli(creationTimestamp)));
354358
}
355359
imagePb.setName(imageId.getImage());
356360
imagePb.setDescription(description);

google-cloud-clients/google-cloud-compute/src/main/java/com/google/cloud/compute/deprecated/InstanceInfo.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828
import java.util.Arrays;
2929
import java.util.List;
3030
import java.util.Objects;
31-
import org.joda.time.format.DateTimeFormatter;
32-
import org.joda.time.format.ISODateTimeFormat;
31+
import org.threeten.bp.Instant;
32+
import org.threeten.bp.ZoneOffset;
33+
import org.threeten.bp.format.DateTimeFormatter;
3334

3435
/**
3536
* A Google Compute Engine VM Instance. An instance is a virtual machine (VM) hosted on Google's
@@ -67,7 +68,8 @@ public Instance apply(InstanceInfo instance) {
6768
};
6869

6970
private static final long serialVersionUID = -6601223112628977168L;
70-
private static final DateTimeFormatter TIMESTAMP_FORMATTER = ISODateTimeFormat.dateTime();
71+
private static final DateTimeFormatter TIMESTAMP_FORMATTER =
72+
DateTimeFormatter.ISO_DATE_TIME.withZone(ZoneOffset.UTC);
7173

7274
private final String generatedId;
7375
private final InstanceId instanceId;
@@ -243,7 +245,10 @@ public static final class BuilderImpl extends Builder {
243245
}
244246
this.instanceId = InstanceId.fromUrl(instancePb.getSelfLink());
245247
if (instancePb.getCreationTimestamp() != null) {
246-
this.creationTimestamp = TIMESTAMP_FORMATTER.parseMillis(instancePb.getCreationTimestamp());
248+
this.creationTimestamp =
249+
TIMESTAMP_FORMATTER
250+
.parse(instancePb.getCreationTimestamp(), Instant.FROM)
251+
.toEpochMilli();
247252
}
248253
this.description = instancePb.getDescription();
249254
if (instancePb.getStatus() != null) {
@@ -585,7 +590,8 @@ Instance toPb() {
585590
instancePb.setId(new BigInteger(generatedId));
586591
}
587592
if (creationTimestamp != null) {
588-
instancePb.setCreationTimestamp(TIMESTAMP_FORMATTER.print(creationTimestamp));
593+
instancePb.setCreationTimestamp(
594+
TIMESTAMP_FORMATTER.format(Instant.ofEpochMilli(creationTimestamp)));
589595
}
590596
instancePb.setName(instanceId.getInstance());
591597
instancePb.setDescription(description);

google-cloud-clients/google-cloud-compute/src/main/java/com/google/cloud/compute/deprecated/MachineType.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@
2424
import java.math.BigInteger;
2525
import java.util.List;
2626
import java.util.Objects;
27-
import org.joda.time.format.DateTimeFormatter;
28-
import org.joda.time.format.ISODateTimeFormat;
27+
import org.threeten.bp.Instant;
28+
import org.threeten.bp.ZoneOffset;
29+
import org.threeten.bp.format.DateTimeFormatter;
2930

3031
/**
3132
* A Google Compute Engine machine type. A machine type determine the virtualized hardware
@@ -52,7 +53,8 @@ public com.google.api.services.compute.model.MachineType apply(MachineType type)
5253
return type.toPb();
5354
}
5455
};
55-
private static final DateTimeFormatter TIMESTAMP_FORMATTER = ISODateTimeFormat.dateTime();
56+
private static final DateTimeFormatter TIMESTAMP_FORMATTER =
57+
DateTimeFormatter.ISO_DATE_TIME.withZone(ZoneOffset.UTC);
5658

5759
private static final long serialVersionUID = -4210962597502860450L;
5860

@@ -241,7 +243,8 @@ com.google.api.services.compute.model.MachineType toPb() {
241243
machineTypePb.setId(new BigInteger(generatedId));
242244
}
243245
if (creationTimestamp != null) {
244-
machineTypePb.setCreationTimestamp(TIMESTAMP_FORMATTER.print(creationTimestamp));
246+
machineTypePb.setCreationTimestamp(
247+
TIMESTAMP_FORMATTER.format(Instant.ofEpochMilli(creationTimestamp)));
245248
}
246249
machineTypePb.setName(machineTypeId.getType());
247250
machineTypePb.setDescription(description);
@@ -280,7 +283,9 @@ static MachineType fromPb(com.google.api.services.compute.model.MachineType mach
280283
}
281284
if (machineTypePb.getCreationTimestamp() != null) {
282285
builder.setCreationTimestamp(
283-
TIMESTAMP_FORMATTER.parseMillis(machineTypePb.getCreationTimestamp()));
286+
TIMESTAMP_FORMATTER
287+
.parse(machineTypePb.getCreationTimestamp(), Instant.FROM)
288+
.toEpochMilli());
284289
}
285290
builder.setDescription(machineTypePb.getDescription());
286291
builder.setCpus(machineTypePb.getGuestCpus());

0 commit comments

Comments
 (0)