event: timestamp should use chrono types
diff --git a/src/gpioplus/event.cpp b/src/gpioplus/event.cpp
index 88c5c47..58708fc 100644
--- a/src/gpioplus/event.cpp
+++ b/src/gpioplus/event.cpp
@@ -77,8 +77,7 @@
{
throw std::runtime_error("Event read didn't get enough data");
}
-
- return Data{data.timestamp, data.id};
+ return Data{decltype(Data::timestamp)(data.timestamp), data.id};
}
uint8_t Event::getValue() const
diff --git a/src/gpioplus/event.hpp b/src/gpioplus/event.hpp
index 32510a3..02c3cc2 100644
--- a/src/gpioplus/event.hpp
+++ b/src/gpioplus/event.hpp
@@ -1,9 +1,11 @@
#pragma once
+#include <chrono>
#include <cstdint>
#include <gpioplus/chip.hpp>
#include <gpioplus/handle.hpp>
#include <gpioplus/internal/fd.hpp>
#include <optional>
+#include <ratio>
#include <string_view>
namespace gpioplus
@@ -52,8 +54,8 @@
/** @brief Event data read from the gpio line */
struct Data
{
- /** @brief The estimate of the time the event occurred in nanoseconds */
- uint64_t timestamp;
+ /** @brief The estimate of the time the event occurred */
+ std::chrono::duration<uint64_t, std::nano> timestamp;
/** @brief The identifier of the event */
uint32_t id;
};
diff --git a/test/event.cpp b/test/event.cpp
index ed627e8..3676804 100644
--- a/test/event.cpp
+++ b/test/event.cpp
@@ -152,7 +152,7 @@
.WillOnce(DoAll(WithArg<1>(WriteStruct(ret)), Return(sizeof(ret))));
std::optional<Event::Data> data = event->read();
EXPECT_TRUE(data);
- EXPECT_EQ(ret.timestamp, data->timestamp);
+ EXPECT_EQ(ret.timestamp, data->timestamp.count());
EXPECT_EQ(ret.id, data->id);
}