blob: f45e949b67ba6c9a67a39edd5ba26e0d10985285 [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>
15#include <__config>
16#include <format>
17#include <ostream>
18
19#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20# pragma GCC system_header
21#endif
22
23_LIBCPP_BEGIN_NAMESPACE_STD
24
25#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_FORMAT)
26
27namespace chrono {
28
29template <class _CharT, class _Traits>
30_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT basic_ostream<_CharT, _Traits>&
31operator<<(basic_ostream<_CharT, _Traits>& __os, const day& __d) {
32 return __os
33 << (__d.ok()
34 ? std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{:%d}"), __d)
35 // Note this error differs from the wording of the Standard. The
36 // Standard wording doesn't work well on AIX or Windows. There
37 // the formatted day seems to be either modulo 100 or completely
38 // omitted. Judging by the wording this is valid.
39 // TODO FMT Write a paper of file an LWG issue.
40 : std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{:02} is not a valid day"), static_cast<unsigned>(__d)));
41}
42
43} // namespace chrono
44
45#endif //if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_FORMAT)
46
47_LIBCPP_END_NAMESPACE_STD
48
49#endif // _LIBCPP___CHRONO_OSTREAM_H