Skip to content
This repository was archived by the owner on Dec 3, 2023. It is now read-only.

fix: docs of com.google.cloud.Timestamp.parseTimestamp #258

Merged
merged 3 commits into from
Jul 24, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
docs: update doc of parseTimestamp
  • Loading branch information
athakor committed Jul 22, 2020
commit c8645bf394f4ba092247b0cc2a7a771f1d5b9d60
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.threeten.bp.ZoneOffset;
import org.threeten.bp.format.DateTimeFormatter;
import org.threeten.bp.format.DateTimeFormatterBuilder;
import org.threeten.bp.format.DateTimeParseException;
import org.threeten.bp.temporal.TemporalAccessor;

/**
Expand Down Expand Up @@ -189,8 +190,11 @@ public com.google.protobuf.Timestamp toProto() {
}

/**
* Creates a Timestamp instance from the given string. String is in the RFC 3339 format with
* timezone offset or without timezone offset.
* Creates a Timestamp instance from the given string.
*
* @param timestamp string is in the RFC 3339 format i.e '2020-12-01T10:15:30.000Z' or with an
* offset, such as '2020-12-01T10:15:30+01:00'
* @throws DateTimeParseException upon failure
*/
public static Timestamp parseTimestamp(String timestamp) {
TemporalAccessor temporalAccessor = timestampParser.parse(timestamp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,16 @@ public void parseTimestampWithoutTimeZoneOffset() {
.isEqualTo(Timestamp.ofTimeSecondsAndNanos(TEST_TIME_SECONDS, 0));
}

@Test
public void parseTimestampWithTimeZoneOffset() {
assertThat(Timestamp.parseTimestamp("0001-01-01T00:00:00-00:00"))
.isEqualTo(Timestamp.MIN_VALUE);
assertThat(Timestamp.parseTimestamp("9999-12-31T23:59:59.999999999-00:00"))
.isEqualTo(Timestamp.MAX_VALUE);
assertThat(Timestamp.parseTimestamp("2020-12-06T19:21:12.123+05:30")).isNotNull();
assertThat(Timestamp.parseTimestamp("2020-07-10T14:03:00-07:00")).isNotNull();
}

@Test
public void fromProto() {
com.google.protobuf.Timestamp proto =
Expand Down