libpqxx  7.7.1
time.hxx
1 
5 #ifndef PQXX_H_TIME
6 #define PQXX_H_TIME
7 
8 #if !defined(PQXX_HEADER_PRE)
9 # error "Include libpqxx headers as <pqxx/header>, not <pqxx/header.hxx>."
10 #endif
11 
12 #include <chrono>
13 #include <cstdlib>
14 
15 #include "pqxx/internal/concat.hxx"
16 #include "pqxx/strconv.hxx"
17 
18 
19 #if defined(PQXX_HAVE_YEAR_MONTH_DAY)
20 
21 namespace pqxx
22 {
23 using namespace std::literals;
24 
25 template<>
26 struct nullness<std::chrono::year_month_day>
27  : no_null<std::chrono::year_month_day>
28 {};
29 
30 
32 
60 template<> struct PQXX_LIBEXPORT string_traits<std::chrono::year_month_day>
61 {
62  [[nodiscard]] static zview
63  to_buf(char *begin, char *end, std::chrono::year_month_day const &value)
64  {
65  return generic_to_buf(begin, end, value);
66  }
67 
68  static char *
69  into_buf(char *begin, char *end, std::chrono::year_month_day const &value);
70 
71  [[nodiscard]] static std::chrono::year_month_day
72  from_string(std::string_view text);
73 
74  [[nodiscard]] static std::size_t
75  size_buffer(std::chrono::year_month_day const &) noexcept
76  {
77  static_assert(int{(std::chrono::year::min)()} >= -99999);
78  static_assert(int{(std::chrono::year::max)()} <= 99999);
79  return 5 + 1 + 2 + 1 + 2 + std::size(s_bc) + 1;
80  }
81 
82 private:
84  static constexpr std::string_view s_bc{" BC"sv};
85 };
86 } // namespace pqxx
87 #endif // PQXX_HAVE_YEAR_MONTH_DAY
88 #endif
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:26
std::vector< std::string_view > to_buf(char *here, char const *end, TYPE... value)
Convert multiple values to strings inside a single buffer.
Definition: strconv.hxx:346
STL namespace.
T from_string(field const &value)
Convert a field&#39;s value to type T.
Definition: field.hxx:506
zview generic_to_buf(char *begin, char *end, TYPE const &value)
Implement string_traits<TYPE>::to_buf by calling into_buf.
Definition: strconv.hxx:439
std::size_t size_buffer(TYPE const &...value) noexcept
Estimate how much buffer space is needed to represent values as a string.
Definition: strconv.hxx:378