date.ipp 823 B

12345678910111213141516171819202122232425262728293031323334
  1. //
  2. // Copyright (c) 2019-2023 Ruben Perez Hidalgo (rubenperez038 at gmail dot com)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. #ifndef BHO_MYSQL_IMPL_DATE_IPP
  8. #define BHO_MYSQL_IMPL_DATE_IPP
  9. #pragma once
  10. #include <asio2/bho/mysql/date.hpp>
  11. #include <cstdio>
  12. #include <ostream>
  13. std::ostream& bho::mysql::operator<<(std::ostream& os, const date& value)
  14. {
  15. // Worst-case output is 14 chars, extra space just in case
  16. char buffer[32]{};
  17. snprintf(
  18. buffer,
  19. sizeof(buffer),
  20. "%04u-%02u-%02u",
  21. static_cast<unsigned>(value.year()),
  22. static_cast<unsigned>(value.month()),
  23. static_cast<unsigned>(value.day())
  24. );
  25. os << buffer;
  26. return os;
  27. }
  28. #endif