datetime.ipp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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_DATETIME_IPP
  8. #define BHO_MYSQL_IMPL_DATETIME_IPP
  9. #pragma once
  10. #include <asio2/bho/mysql/datetime.hpp>
  11. #include <cstdio>
  12. #include <ostream>
  13. std::ostream& bho::mysql::operator<<(std::ostream& os, const datetime& value)
  14. {
  15. // Worst-case output is 37 chars, extra space just in case
  16. char buffer[64]{};
  17. snprintf(
  18. buffer,
  19. sizeof(buffer),
  20. "%04u-%02u-%02u %02d:%02u:%02u.%06u",
  21. static_cast<unsigned>(value.year()),
  22. static_cast<unsigned>(value.month()),
  23. static_cast<unsigned>(value.day()),
  24. static_cast<unsigned>(value.hour()),
  25. static_cast<unsigned>(value.minute()),
  26. static_cast<unsigned>(value.second()),
  27. static_cast<unsigned>(value.microsecond())
  28. );
  29. os << buffer;
  30. return os;
  31. }
  32. #endif