From fcd018b142fb2a1cf1deac1a55af90ae41f3377e Mon Sep 17 00:00:00 2001 From: liuzicheng1987 Date: Wed, 4 Oct 2023 21:46:22 +0200 Subject: [PATCH] Added documentation on rfl::Timestamp --- docs/timestamps.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 docs/timestamps.md diff --git a/docs/timestamps.md b/docs/timestamps.md new file mode 100644 index 00000000..95fcb288 --- /dev/null +++ b/docs/timestamps.md @@ -0,0 +1,30 @@ +# `rfl::Timestamp` + +`rfl::Timestamp` is a simple wrapper around `std::tm` (https://en.cppreference.com/w/cpp/chrono/c/tm). + +As its template parameter it includes the time stamp format for serialization and deserialization. + +Here is a reference for for how you can specify the format: + +https://en.cppreference.com/w/cpp/chrono/c/strftime + +In fact, `rfl::Timestamp` does call `strftime` and `strptime` under-the-hood. + +They can be used in your struct like this: + +```cpp +struct Person { + rfl::Field<"birthday", rfl::Timestamp<"%Y-%m-%d">> birthday; +}; +``` + +An `rfl::Timestamp` can be constructed from either a string or a `std::tm` struct. + +You can access the underlying `std::tm` struct using the `.tm()` method and you can generate +the string representation using the `.str()` method. + +Note that constructing `rfl::Timestamp` from a string is convenient, but it might result in +an exception. + +To avoid the exception you can also use `Timestamp<...>::from_string(...)`, which will +return an `rfl::Result>` or `rfl::Error`.