blob: b6dcc5035ef66a1db2af4dc1291896bd23e9f9d8 [file] [log] [blame]
Mark de Wevere5d2d3e2022-03-20 12:40:021// -*- 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 Wever3eb4f162022-03-20 12:40:0215#include <__chrono/year.h>
Mark de Wevere5d2d3e2022-03-20 12:40:0216#include <__config>
Mark de Weverf2a26352022-09-13 18:10:2617#include <__format/format_functions.h>
Mark de Wevere5d2d3e2022-03-20 12:40:0218#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
28namespace chrono {
29
30template <class _CharT, class _Traits>
31_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT basic_ostream<_CharT, _Traits>&
32operator<<(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 Wever3eb4f162022-03-20 12:40:0244template <class _CharT, class _Traits>
45_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT basic_ostream<_CharT, _Traits>&
46operator<<(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 Wevere5d2d3e2022-03-20 12:40:0251} // 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