// -*- C++ -*- //===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// //============================================================================== // NOTICE: This file has been modified by Green Hills Software, Inc. Such // modifications are subject to copyright by Green Hills Software, Inc. See the // "Green Hills Software Modifications" section in the LICENSE.txt included with // this distribution for more information. //============================================================================== #ifndef _LIBCPP___CHRONO_OSTREAM_H #define _LIBCPP___CHRONO_OSTREAM_H #include <__chrono/day.h> #include <__chrono/duration.h> #include <__chrono/month.h> #include <__chrono/statically_widen.h> #include <__chrono/weekday.h> #include <__chrono/year.h> #include <__concepts/same_as.h> #include <__config> #include <__format/format_functions.h> #include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header #endif #if defined(__ghs__) #pragma ghs start_cxx_lib_header #pragma ghs startdata #if defined(__ghs_max_pack_value) #pragma pack (push, __ghs_max_pack_value) #endif #endif _LIBCPP_BEGIN_NAMESPACE_STD #if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_FORMAT) namespace chrono { // Depending on the type the return is a const _CharT* or a basic_string<_CharT> template _LIBCPP_HIDE_FROM_ABI auto __units_suffix() { // TODO FMT LWG issue the suffixes are always char and not STATICALLY-WIDEN'ed. if constexpr (same_as) return _LIBCPP_STATICALLY_WIDEN(_CharT, "as"); else if constexpr (same_as) return _LIBCPP_STATICALLY_WIDEN(_CharT, "fs"); else if constexpr (same_as) return _LIBCPP_STATICALLY_WIDEN(_CharT, "ps"); else if constexpr (same_as) return _LIBCPP_STATICALLY_WIDEN(_CharT, "ns"); else if constexpr (same_as) # ifndef _LIBCPP_HAS_NO_UNICODE return _LIBCPP_STATICALLY_WIDEN(_CharT, "u00b5s"); # else return _LIBCPP_STATICALLY_WIDEN(_CharT, "us"); # endif else if constexpr (same_as) return _LIBCPP_STATICALLY_WIDEN(_CharT, "ms"); else if constexpr (same_as) return _LIBCPP_STATICALLY_WIDEN(_CharT, "cs"); else if constexpr (same_as) return _LIBCPP_STATICALLY_WIDEN(_CharT, "ds"); else if constexpr (same_as>) return _LIBCPP_STATICALLY_WIDEN(_CharT, "s"); else if constexpr (same_as) return _LIBCPP_STATICALLY_WIDEN(_CharT, "das"); else if constexpr (same_as) return _LIBCPP_STATICALLY_WIDEN(_CharT, "hs"); else if constexpr (same_as) return _LIBCPP_STATICALLY_WIDEN(_CharT, "ks"); else if constexpr (same_as) return _LIBCPP_STATICALLY_WIDEN(_CharT, "Ms"); else if constexpr (same_as) return _LIBCPP_STATICALLY_WIDEN(_CharT, "Gs"); else if constexpr (same_as) return _LIBCPP_STATICALLY_WIDEN(_CharT, "Ts"); else if constexpr (same_as) return _LIBCPP_STATICALLY_WIDEN(_CharT, "Ps"); else if constexpr (same_as) return _LIBCPP_STATICALLY_WIDEN(_CharT, "Es"); else if constexpr (same_as>) return _LIBCPP_STATICALLY_WIDEN(_CharT, "min"); else if constexpr (same_as>) return _LIBCPP_STATICALLY_WIDEN(_CharT, "h"); else if constexpr (same_as>) return _LIBCPP_STATICALLY_WIDEN(_CharT, "d"); else if constexpr (_Period::den == 1) return std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "[{}]s"), _Period::num); else return std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "[{}/{}]s"), _Period::num, _Period::den); } template _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const duration<_Rep, _Period>& __d) { basic_ostringstream<_CharT, _Traits> __s; __s.flags(__os.flags()); __s.imbue(__os.getloc()); __s.precision(__os.precision()); __s << __d.count() << chrono::__units_suffix<_CharT, _Period>(); return __os << __s.str(); } template _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const day& __d) { return __os << (__d.ok() ? std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{:%d}"), __d) // Note this error differs from the wording of the Standard. The // Standard wording doesn't work well on AIX or Windows. There // the formatted day seems to be either modulo 100 or completely // omitted. Judging by the wording this is valid. // TODO FMT Write a paper of file an LWG issue. : std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{:02} is not a valid day"), static_cast(__d))); } template _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(__m))); // TODO FMT Standard mandated locale isn't used. } template _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)); } template _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const weekday& __wd) { return __os << (__wd.ok() ? std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L%a}"), __wd) : std::format(__os.getloc(), // TODO FMT Standard mandated locale isn't used. _LIBCPP_STATICALLY_WIDEN(_CharT, "{} is not a valid weekday"), static_cast(__wd.c_encoding()))); } } // namespace chrono #endif //if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_FORMAT) _LIBCPP_END_NAMESPACE_STD #if defined(__ghs__) #if defined(__ghs_max_pack_value) #pragma pack(pop) #endif #pragma ghs enddata #pragma ghs end_cxx_lib_header #endif #endif // _LIBCPP___CHRONO_OSTREAM_H