Read/write of std::chrono data #1606
Replies: 2 comments
-
I've been wanting to add If you could provide some examples of |
Beta Was this translation helpful? Give feedback.
-
For using namespace std::chrono;
std::chrono::year_month_day ymd{2025y, std::chrono::March, 4d}; translates to {"year":2025,"month":3,"day":4} For std::chrono::system_clock::time_point tp = std::chrono::system_clock::now(); might translate to {"unit":"microseconds","count":1739234225419488} It would be nice to have |
Beta Was this translation helpful? Give feedback.
-
I'm using Glaze on a C++23 project to add JSON import/export of existing data structures.
Where the data structures use "normal" types, things work well. However I'm struggling to use Glaze to serialise/deserialise classes which have
std::chrono
members. I'm quite new to Glaze.For example, one data structure is a
std::vector
of a type which has astd::chrono::year_month_day
member as well as astd::chrono::system_clock::time_point
member. I have tried to use custom reader/writer code with lambdas but I can't get it to compile.I think part of the problem is that
std::chrono::year_month_day
has getters but no setters; I would need to create a new instance. I could replacestd::chrono::year_month_day
with a custom struct which does basically the same thing, but I am reluctant to change the current data definitions.Has anyone got any snippet of code that uses Glaze to read/write
std::chrono
data? I'm not able to find any examples so far.Beta Was this translation helpful? Give feedback.
All reactions