Skip to content

Commit c08a8b3

Browse files
authored
fix(spanner): correct chrono arithmetic in Interval integration test (#15810)
* fix(spanner): correct chrono arithmetic in Interval integration test (#15163)
1 parent d0dc97e commit c08a8b3

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

google/cloud/spanner/integration_tests/data_types_integration_test.cc

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -530,16 +530,15 @@ SELECT ARRAY<INTERVAL>[INTERVAL '1-2 3 4:5:6.789123456' YEAR TO SECOND];)sql",
530530

531531
TEST_F(DataTypeIntegrationTest, SelectIntervalFromTimestampDiff) {
532532
if (UsingEmulator()) GTEST_SKIP();
533-
Interval expected_interval{
534-
std::chrono::duration_cast<std::chrono::nanoseconds>(
535-
std::chrono::hours(1))};
536-
std::time_t now_seconds =
537-
std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
538-
std::time_t one_hour_later_seconds = now_seconds + 3600;
539-
540-
std::vector<std::vector<Timestamp>> const data = {std::vector<Timestamp>{
541-
MakeTimestamp(MakeTime(now_seconds, 0)).value(),
542-
MakeTimestamp(MakeTime(one_hour_later_seconds, 0)).value()}};
533+
534+
auto const t0 = std::chrono::system_clock::from_time_t(1234567890);
535+
auto const t1 = t0 + std::chrono::hours(1);
536+
537+
Interval expected_interval{t1 - t0};
538+
539+
std::vector<std::vector<Timestamp>> const data = {
540+
{MakeTimestamp(t0).value(), MakeTimestamp(t1).value()}};
541+
543542
auto result = WriteReadData(*client_, data, "ArrayTimestampValue");
544543
EXPECT_THAT(result, IsOkAndHolds(UnorderedElementsAreArray(data)));
545544

0 commit comments

Comments
 (0)