Mark de Wever | e5d2d3e | 2022-03-20 12:40:02 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===----------------------------------------------------------------------===// |
| 3 | // |
| 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP___CHRONO_OSTREAM_H |
| 11 | #define _LIBCPP___CHRONO_OSTREAM_H |
| 12 | |
| 13 | #include <__chrono/day.h> |
| 14 | #include <__chrono/statically_widen.h> |
Mark de Wever | 3eb4f16 | 2022-03-20 12:40:02 | [diff] [blame^] | 15 | #include <__chrono/year.h> |
Mark de Wever | e5d2d3e | 2022-03-20 12:40:02 | [diff] [blame] | 16 | #include <__config> |
Mark de Wever | f2a2635 | 2022-09-13 18:10:26 | [diff] [blame] | 17 | #include <__format/format_functions.h> |
Mark de Wever | e5d2d3e | 2022-03-20 12:40:02 | [diff] [blame] | 18 | #include <ostream> |
| 19 | |
| 20 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 21 | # pragma GCC system_header |
| 22 | #endif |
| 23 | |
| 24 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 25 | |
| 26 | #if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_FORMAT) |
| 27 | |
| 28 | namespace chrono { |
| 29 | |
| 30 | template <class _CharT, class _Traits> |
| 31 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT basic_ostream<_CharT, _Traits>& |
| 32 | operator<<(basic_ostream<_CharT, _Traits>& __os, const day& __d) { |
| 33 | return __os |
| 34 | << (__d.ok() |
| 35 | ? std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{:%d}"), __d) |
| 36 | // Note this error differs from the wording of the Standard. The |
| 37 | // Standard wording doesn't work well on AIX or Windows. There |
| 38 | // the formatted day seems to be either modulo 100 or completely |
| 39 | // omitted. Judging by the wording this is valid. |
| 40 | // TODO FMT Write a paper of file an LWG issue. |
| 41 | : std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{:02} is not a valid day"), static_cast<unsigned>(__d))); |
| 42 | } |
| 43 | |
Mark de Wever | 3eb4f16 | 2022-03-20 12:40:02 | [diff] [blame^] | 44 | template <class _CharT, class _Traits> |
| 45 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT basic_ostream<_CharT, _Traits>& |
| 46 | operator<<(basic_ostream<_CharT, _Traits>& __os, const year& __y) { |
| 47 | return __os << (__y.ok() ? std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{:%Y}"), __y) |
| 48 | : std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{:%Y} is not a valid year"), __y)); |
| 49 | } |
| 50 | |
Mark de Wever | e5d2d3e | 2022-03-20 12:40:02 | [diff] [blame] | 51 | } // namespace chrono |
| 52 | |
| 53 | #endif //if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_FORMAT) |
| 54 | |
| 55 | _LIBCPP_END_NAMESPACE_STD |
| 56 | |
| 57 | #endif // _LIBCPP___CHRONO_OSTREAM_H |