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

Commit

Permalink
Allow to set custom timestamp (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
awegrzyn authored Nov 4, 2019
1 parent f99273d commit 0c995cb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/Point.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class Point
/// Converts point to Influx Line Protocol
std::string toLineProtocol() const;

/// Sets custom timestamp
Point&& setTimestamp(std::chrono::time_point<std::chrono::system_clock> timestamp);

protected:
/// A value
std::variant<int, std::string, double> mValue;
Expand Down
6 changes: 6 additions & 0 deletions src/Point.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ Point&& Point::addTag(std::string_view key, std::string_view value)
return std::move(*this);
}

Point&& Point::setTimestamp(std::chrono::time_point<std::chrono::system_clock> timestamp)
{
mTimestamp = timestamp;
return std::move(*this);
}

auto Point::getCurrentTimestamp() -> decltype(std::chrono::system_clock::now())
{
return std::chrono::system_clock::now();
Expand Down
9 changes: 9 additions & 0 deletions test/testPoint.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ BOOST_AUTO_TEST_CASE(test3)
BOOST_CHECK_EQUAL(result[1], "value=10i,dvalue=10.1");
}

BOOST_AUTO_TEST_CASE(test4)
{
auto point = Point{"test"}
.addField("value", 10)
.setTimestamp(std::chrono::time_point<std::chrono::system_clock>(std::chrono::milliseconds(1572830914)));

auto result = getVector(point);
BOOST_CHECK_EQUAL(result[2], "1572830914000000");
}

} // namespace test
} // namespace influxdb

0 comments on commit 0c995cb

Please sign in to comment.