mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-12-06 18:56:19 +08:00
Added support for std::chrono::duration; fixes #399
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <vector>
|
||||
|
||||
#include "write_and_read.hpp"
|
||||
|
||||
namespace test_duration_conversion {
|
||||
|
||||
struct TestStruct1 {
|
||||
std::chrono::minutes duration;
|
||||
};
|
||||
|
||||
struct TestStruct2 {
|
||||
std::chrono::seconds duration;
|
||||
};
|
||||
|
||||
TEST(json, test_duration_conversion) {
|
||||
const auto test1 = TestStruct1{.duration = std::chrono::minutes(10)};
|
||||
const auto test2 =
|
||||
rfl::json::read<TestStruct2>(rfl::json::write(test1)).value();
|
||||
write_and_read(test2, R"({"duration":{"count":600,"unit":"seconds"}})");
|
||||
}
|
||||
} // namespace test_duration_conversion
|
||||
Reference in New Issue
Block a user