diff --git a/src/InfluxDB.cxx b/src/InfluxDB.cxx index f760b8e5..1ed55b63 100644 --- a/src/InfluxDB.cxx +++ b/src/InfluxDB.cxx @@ -104,7 +104,7 @@ std::vector InfluxDB::query(const std::string& query) std::tm tm = {}; std::stringstream ss; ss << value; - ss >> std::get_time(&tm, "%FT%TZ"); + ss >> std::get_time(&tm, "%Y-%m-%dT%H:%M:%SZ"); point.setTimestamp(std::chrono::system_clock::from_time_t(std::mktime(&tm))); continue; } diff --git a/test/testQuery.cxx b/test/testQuery.cxx index 2b156692..7526ee3c 100644 --- a/test/testQuery.cxx +++ b/test/testQuery.cxx @@ -1,7 +1,6 @@ #define BOOST_TEST_MODULE Test InfluxDB Query #define BOOST_TEST_DYN_LINK #include - #include "../include/InfluxDBFactory.h" #include "../src/InfluxDBException.h" @@ -26,6 +25,21 @@ BOOST_AUTO_TEST_CASE(query1) BOOST_CHECK_EQUAL(points[2].getTags(), "host=localhost"); } +BOOST_AUTO_TEST_CASE(timeStampVerify) +{ + double timeZone = 3600; //+1h + + auto influxdb = influxdb::InfluxDBFactory::Get("http://localhost:8086?db=test"); + Point point = Point{"timestampCheck"}.addField("value", 10); + auto timestamp = point.getTimestamp(); + influxdb->write(std::move(point)); + + auto points = influxdb->query("SELECT * from timestampCheck ORDER BY DESC LIMIT 1"); + std::chrono::duration diff = timestamp - points[0].getTimestamp(); + double diffZone = diff.count() - timeZone; + BOOST_CHECK(diffZone < 1); // 1s +} + BOOST_AUTO_TEST_CASE(failedQuery1) { auto influxdb = influxdb::InfluxDBFactory::Get("http://localhost:8086?db=test");