[libc++][chrono] Implements formatter month.
Partially implements:
- P1361 Integration of chrono with text formatting
Reviewed By: ldionne, #libc
Differential Revision: https://reviews.llvm.org/D134138
diff --git a/libcxx/include/__chrono/ostream.h b/libcxx/include/__chrono/ostream.h
index b6dcc50..21951cf3 100644
--- a/libcxx/include/__chrono/ostream.h
+++ b/libcxx/include/__chrono/ostream.h
@@ -11,6 +11,7 @@
#define _LIBCPP___CHRONO_OSTREAM_H
#include <__chrono/day.h>
+#include <__chrono/month.h>
#include <__chrono/statically_widen.h>
#include <__chrono/year.h>
#include <__config>
@@ -43,6 +44,15 @@
template <class _CharT, class _Traits>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os, const month& __m) {
+ return __os << (__m.ok() ? std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L%b}"), __m)
+ : std::format(__os.getloc(),
+ _LIBCPP_STATICALLY_WIDEN(_CharT, "{} is not a valid month"),
+ static_cast<unsigned>(__m))); // TODO FMT Standard mandated locale isn't used.
+}
+
+template <class _CharT, class _Traits>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, const year& __y) {
return __os << (__y.ok() ? std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{:%Y}"), __y)
: std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{:%Y} is not a valid year"), __y));