25 #include <date/date.h>
27 #include <odb/pgsql/traits.hxx>
28 #include <odb/sqlite/traits.hxx>
45 class value_traits<std::chrono::system_clock::time_point, id_timestamp>
48 using TimePoint = std::chrono::system_clock::time_point;
54 static const long long neg_inf = -0x7fffffffffffffffLL - 1;
57 static const long long pos_inf = 0x7fffffffffffffffLL;
64 i = details::endian_traits::ntoh(i);
67 else if (i == pos_inf)
72 std::chrono::microseconds us(i);
83 if (v == TimePoint::max())
85 else if (v == TimePoint::min())
91 std::chrono::microseconds us =
92 std::chrono::duration_cast<std::chrono::microseconds>(v - epoch);
95 i = details::endian_traits::hton(i);
106 bzero(&tm,
sizeof(tm));
107 std::string epoch =
"2000-01-01T00:00:00Z";
109 std::chrono::system_clock::time_point tp;
110 auto x = date::parse(
"%FT%T%Z", tp);
111 std::istringstream iss(epoch);
127 class value_traits<std::chrono::system_clock::time_point, id_text>
130 using TimePoint = std::chrono::system_clock::time_point;
135 static constexpr
const char *
const TIME_POINT_MIN =
"TIME_POINT_MIN";
136 static constexpr
const char *
const TIME_POINT_MAX =
"TIME_POINT_MAX";
142 std::string str_rep(b.data(), n);
144 if (str_rep == TIME_POINT_MAX)
145 v = TimePoint::max();
146 else if (str_rep == TIME_POINT_MIN)
147 v = TimePoint::min();
150 auto x = date::parse(
"%FT%T%z", v);
151 std::istringstream iss(str_rep);
157 static void set_image(details::buffer &b, std::size_t &n,
bool &is_null,
163 if (v == TimePoint::max())
164 str_rep = TIME_POINT_MAX;
165 else if (v == TimePoint::min())
166 str_rep = TIME_POINT_MIN;
171 if (str_rep.size() > b.capacity())
172 b.capacity(str_rep.length());
173 std::memcpy(b.data(), str_rep.data(), str_rep.length());