Skip to content

Commit 9ef60e6

Browse files
Praful Makanisduskis
authored andcommitted
---
yaml --- r: 22005 b: refs/heads/autosynth-video-intelligence c: a671baf h: refs/heads/master i: 22003: 9c0d332
1 parent 88d601a commit 9ef60e6

3 files changed

Lines changed: 23 additions & 2 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ refs/heads/autosynth-compute: 026cea73fde22ec0b40866ac5a7dc144dc465b9b
115115
refs/heads/autosynth-container: d17e1a76a903f9e05eba56a9bf5d12c1b15b67d7
116116
refs/heads/autosynth-monitoring: e66569bd7358a90d17097f90cf8c70dbeeb048cf
117117
refs/heads/autosynth-pubsub: 39d0c11469a8084ece7c1ff58809f24da0316ae6
118-
refs/heads/autosynth-video-intelligence: 04206ac472d8d68dd30c9dd7bbabcc89453b2d72
118+
refs/heads/autosynth-video-intelligence: a671baf76464f1e50e15f193e4c4e8a30309c8ee
119119
refs/heads/autosynth-vision: 7d58f59617722175b83a4583efdb6eb9b5b8e8dd
120120
refs/heads/spanner: b01127f885b4611bf1852abb0ce481eeb7fcc131
121121
refs/tags/v0.68.0: 9cc799fcf68c82ab431d425fefa58ef615ce8e5b

branches/autosynth-video-intelligence/google-cloud-clients/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import org.threeten.bp.LocalDateTime;
2828
import org.threeten.bp.ZoneOffset;
2929
import org.threeten.bp.format.DateTimeFormatter;
30+
import org.threeten.bp.format.DateTimeFormatterBuilder;
31+
import org.threeten.bp.temporal.TemporalAccessor;
3032

3133
/**
3234
* Represents a timestamp with nanosecond precision. Timestamps cover the range [0001-01-01,
@@ -47,6 +49,15 @@ public final class Timestamp implements Comparable<Timestamp>, Serializable {
4749

4850
private static final DateTimeFormatter format = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
4951

52+
private static final DateTimeFormatter timestampParser =
53+
new DateTimeFormatterBuilder()
54+
.appendOptional(DateTimeFormatter.ISO_LOCAL_DATE_TIME)
55+
.optionalStart()
56+
.appendOffsetId()
57+
.optionalEnd()
58+
.toFormatter()
59+
.withZone(ZoneOffset.UTC);
60+
5061
private final long seconds;
5162
private final int nanos;
5263

@@ -170,7 +181,8 @@ public com.google.protobuf.Timestamp toProto() {
170181
* the timezone offset (always ends in "Z").
171182
*/
172183
public static Timestamp parseTimestamp(String timestamp) {
173-
Instant instant = Instant.parse(timestamp);
184+
TemporalAccessor temporalAccessor = timestampParser.parse(timestamp);
185+
Instant instant = Instant.from(temporalAccessor);
174186
return ofTimeSecondsAndNanos(instant.getEpochSecond(), instant.getNano());
175187
}
176188

branches/autosynth-video-intelligence/google-cloud-clients/google-cloud-core/src/test/java/com/google/cloud/TimestampTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,15 @@ public void parseTimestamp() {
185185
.isEqualTo(Timestamp.ofTimeSecondsAndNanos(TEST_TIME_SECONDS, 0));
186186
}
187187

188+
@Test
189+
public void parseTimestampWithoutTimeZoneOffset() {
190+
assertThat(Timestamp.parseTimestamp("0001-01-01T00:00:00")).isEqualTo(Timestamp.MIN_VALUE);
191+
assertThat(Timestamp.parseTimestamp("9999-12-31T23:59:59.999999999"))
192+
.isEqualTo(Timestamp.MAX_VALUE);
193+
assertThat(Timestamp.parseTimestamp("2015-10-12T15:14:54"))
194+
.isEqualTo(Timestamp.ofTimeSecondsAndNanos(TEST_TIME_SECONDS, 0));
195+
}
196+
188197
@Test
189198
public void fromProto() {
190199
com.google.protobuf.Timestamp proto =

0 commit comments

Comments
 (0)