From 26437b72c3d1c816615a83557c8354bd3dc8ffb5 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Thu, 7 Nov 2024 17:15:24 +0000 Subject: [PATCH] chore: demo offset parsing tests in java-core + java.time --- .../src/main/java/com/google/cloud/Timestamp.java | 3 ++- .../test/java/com/google/cloud/TimestampTest.java | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/java-core/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java b/java-core/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java index d24cb2a37e..dbeea88616 100644 --- a/java-core/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java +++ b/java-core/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java @@ -55,7 +55,8 @@ public final class Timestamp implements Comparable, Serializable { new DateTimeFormatterBuilder() .appendOptional(DateTimeFormatter.ISO_LOCAL_DATE_TIME) .optionalStart() - .appendZoneOrOffsetId() + // .appendZoneOrOffsetId() + .appendOffsetId() .optionalEnd() .toFormatter() .withZone(ZoneOffset.UTC); diff --git a/java-core/google-cloud-core/src/test/java/com/google/cloud/TimestampTest.java b/java-core/google-cloud-core/src/test/java/com/google/cloud/TimestampTest.java index f6926f444f..185340ae29 100644 --- a/java-core/google-cloud-core/src/test/java/com/google/cloud/TimestampTest.java +++ b/java-core/google-cloud-core/src/test/java/com/google/cloud/TimestampTest.java @@ -287,6 +287,18 @@ void parseTimestampWithTimeZoneOffset() { () -> Timestamp.parseTimestampDuration("2016-12-31T23:59:60Z")); } + @Test + void demoAssertion1() { + assertThat(Timestamp.parseTimestampDuration("2020-07-10T14:03:00.123-07:00")) + .isEqualTo(Timestamp.ofTimeSecondsAndNanos(1594414980, 123000000)); + } + + @Test + void demoAssertion2() { + assertThat(Timestamp.parseTimestampDuration("2020-12-06T19:21:12.123+05:30")) + .isEqualTo(Timestamp.ofTimeSecondsAndNanos(1607262672, 123000000)); + } + @Test void parseTimestampWithZoneString() { // Valid RFC 3339 timestamps with time zone names