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

Commit 0c32d16

Browse files
committed
test: failing test for parsing a negative timestamp
1 parent ebc0e6c commit 0c32d16

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

google-cloud-core/src/test/java/com/google/cloud/TimestampTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,30 @@ public void ofDate() {
8080
assertThat(timestamp.getNanos()).isEqualTo(expectedNanos);
8181
}
8282

83+
@Test
84+
public void ofSqlTimestamp() {
85+
String expectedTimestamp = "1970-01-01T00:00:12.345000000Z";
86+
java.sql.Timestamp input = new java.sql.Timestamp(12345);
87+
Timestamp timestamp = Timestamp.of(input);
88+
assertThat(timestamp.toString()).isEqualTo(expectedTimestamp);
89+
}
90+
91+
@Test
92+
public void ofSqlTimestampPreEpoch() {
93+
String expectedTimestamp = "1969-12-31T23:59:47.655000000Z";
94+
java.sql.Timestamp input = new java.sql.Timestamp(-12345);
95+
Timestamp timestamp = Timestamp.of(input);
96+
assertThat(timestamp.toString()).isEqualTo(expectedTimestamp);
97+
}
98+
99+
@Test
100+
public void ofSqlTimestampOnEpoch() {
101+
String expectedTimestamp = "1970-01-01T00:00:00Z";
102+
java.sql.Timestamp input = new java.sql.Timestamp(0);
103+
Timestamp timestamp = Timestamp.of(input);
104+
assertThat(timestamp.toString()).isEqualTo(expectedTimestamp);
105+
}
106+
83107
@Test
84108
public void ofDatePreEpoch() {
85109
Timestamp timestamp = Timestamp.of(TEST_DATE_PRE_EPOCH);

0 commit comments

Comments
 (0)