libpqxx
The C++ client library for PostgreSQL
time.hxx
Go to the documentation of this file.
1 
5 #ifndef PQXX_TIME_HXX
6 #define PQXX_TIME_HXX
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/strconv.hxx"
16 
17 
18 #if defined(PQXX_HAVE_YEAR_MONTH_DAY)
19 
20 namespace pqxx
21 {
22 using namespace std::literals;
23 
24 template<>
25 struct nullness<std::chrono::year_month_day> final
26  : no_null<std::chrono::year_month_day>
27 {};
28 
29 
31 
59 template<>
60 struct PQXX_LIBEXPORT string_traits<std::chrono::year_month_day> final
61 {
62  [[nodiscard]] static std::string_view to_buf(
63  std::span<char> buf, std::chrono::year_month_day const &value, ctx c = {});
64 
65  [[nodiscard]] static std::chrono::year_month_day
66  from_string(std::string_view text, sl = sl::current());
67 
68  [[nodiscard]] static std::size_t
69  size_buffer(std::chrono::year_month_day const &) noexcept
70  {
71  static_assert(int{(std::chrono::year::min)()} >= -99999);
72  static_assert(int{(std::chrono::year::max)()} <= 99999);
73  return 5 + 1 + 2 + 1 + 2 + std::size(s_bc) + 1;
74  }
75 
76 private:
78  static constexpr std::string_view s_bc{" BC"sv};
79 };
80 } // namespace pqxx
81 #endif // PQXX_HAVE_YEAR_MONTH_DAY
82 #endif
#define PQXX_LIBEXPORT
Definition: header-pre.hxx:206
The home of all libpqxx classes, functions, templates, etc.
Definition: array.cxx:26
std::string_view to_buf(std::span< char > buf, TYPE const &value, ctx c={})
Represent value as SQL text, optionally using buf as storage.
Definition: strconv.hxx:430
std::source_location sl
Convenience alias for std::source_location. It's just too long.
Definition: types.hxx:38
T from_string(field const &value, ctx c={})
Convert a field's value to type T.
Definition: field.hxx:831
constexpr 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:399
conversion_context const & ctx
Convenience alias: const reference to a pqxx::conversion_context.
Definition: strconv.hxx:201