Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
Make sure timestamp is read back correctly (#68)
Browse files Browse the repository at this point in the history
* Make sure timestamp is read back correctly

* Add fix to parsing timestamp when query
  • Loading branch information
awegrzyn committed Apr 10, 2020
1 parent 472a752 commit 4f74b9a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/InfluxDB.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ std::vector<Point> 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;
}
Expand Down
16 changes: 15 additions & 1 deletion test/testQuery.cxx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#define BOOST_TEST_MODULE Test InfluxDB Query
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>

#include "../include/InfluxDBFactory.h"
#include "../src/InfluxDBException.h"

Expand All @@ -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<double> 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");
Expand Down

0 comments on commit 4f74b9a

Please sign in to comment.