This repository was archived by the owner on Dec 3, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed
main/java/com/google/cloud
test/java/com/google/cloud Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change 2828import org .threeten .bp .ZoneOffset ;
2929import org .threeten .bp .format .DateTimeFormatter ;
3030import org .threeten .bp .format .DateTimeFormatterBuilder ;
31+ import org .threeten .bp .format .DateTimeParseException ;
3132import org .threeten .bp .temporal .TemporalAccessor ;
3233
3334/**
@@ -189,8 +190,13 @@ public com.google.protobuf.Timestamp toProto() {
189190 }
190191
191192 /**
192- * Creates a Timestamp instance from the given string. String is in the RFC 3339 format without
193- * the timezone offset (always ends in "Z").
193+ * Creates a Timestamp instance from the given string. Input string should be in the RFC 3339
194+ * format, like '2020-12-01T10:15:30.000Z' or with the timezone offset, such as
195+ * '2020-12-01T10:15:30+01:00'.
196+ *
197+ * @param timestamp string in the RFC 3339 format
198+ * @return created Timestamp
199+ * @throws DateTimeParseException if unable to parse
194200 */
195201 public static Timestamp parseTimestamp (String timestamp ) {
196202 TemporalAccessor temporalAccessor = timestampParser .parse (timestamp );
Original file line number Diff line number Diff line change @@ -257,6 +257,18 @@ public void parseTimestampWithoutTimeZoneOffset() {
257257 .isEqualTo (Timestamp .ofTimeSecondsAndNanos (TEST_TIME_SECONDS , 0 ));
258258 }
259259
260+ @ Test
261+ public void parseTimestampWithTimeZoneOffset () {
262+ assertThat (Timestamp .parseTimestamp ("0001-01-01T00:00:00-00:00" ))
263+ .isEqualTo (Timestamp .MIN_VALUE );
264+ assertThat (Timestamp .parseTimestamp ("9999-12-31T23:59:59.999999999-00:00" ))
265+ .isEqualTo (Timestamp .MAX_VALUE );
266+ assertThat (Timestamp .parseTimestamp ("2020-12-06T19:21:12.123+05:30" ))
267+ .isEqualTo (Timestamp .ofTimeSecondsAndNanos (1607262672 , 123000000 ));
268+ assertThat (Timestamp .parseTimestamp ("2020-07-10T14:03:00-07:00" ))
269+ .isEqualTo (Timestamp .ofTimeSecondsAndNanos (1594414980 , 0 ));
270+ }
271+
260272 @ Test
261273 public void fromProto () {
262274 com .google .protobuf .Timestamp proto =
You can’t perform that action at this time.
0 commit comments