diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt --- a/libcxx/include/CMakeLists.txt +++ b/libcxx/include/CMakeLists.txt @@ -145,12 +145,16 @@ __chrono/day.h __chrono/duration.h __chrono/file_clock.h + __chrono/formatter.h __chrono/hh_mm_ss.h __chrono/high_resolution_clock.h __chrono/literals.h __chrono/month.h __chrono/month_weekday.h __chrono/monthday.h + __chrono/ostream.h + __chrono/parser_std_format_spec.h + __chrono/statically_widen.h __chrono/steady_clock.h __chrono/system_clock.h __chrono/time_point.h diff --git a/libcxx/include/__chrono/formatter.h b/libcxx/include/__chrono/formatter.h new file mode 100644 --- /dev/null +++ b/libcxx/include/__chrono/formatter.h @@ -0,0 +1,876 @@ +// -*- 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 +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___CHRONO_FORMATTER_H +#define _LIBCPP___CHRONO_FORMATTER_H + +// Make sure all feature-test macros are available. +#include +// Enable the contents of the header only when libc++ was built with LIBCXX_ENABLE_INCOMPLETE_FEATURES. +#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_FORMAT) + +# include <__chrono/calendar.h> +# include <__chrono/day.h> +# include <__chrono/hh_mm_ss.h> +# include <__chrono/month.h> +# include <__chrono/month_weekday.h> +# include <__chrono/monthday.h> +# include <__chrono/ostream.h> +# include <__chrono/parser_std_format_spec.h> +# include <__chrono/statically_widen.h> +# include <__chrono/weekday.h> +# include <__chrono/year.h> +# include <__chrono/year_month.h> +# include <__chrono/year_month_day.h> +# include <__chrono/year_month_weekday.h> +# include <__concepts/arithmetic.h> +# include <__concepts/same_as.h> +# include <__config> +# include <__memory/addressof.h> +# include +# include +# include +# include +# include +# include +# include + +// clang-format off +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif +// clang-format on + +_LIBCPP_BEGIN_NAMESPACE_STD + +// The time format functions use ostream which requires locale support. +# if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_LOCALIZATION) + +namespace chrono {} // namespace chrono + +namespace __formatter { + +/// Formats a time based on a tm struct. +/// +/// This formatter passes the formatting to time_put which uses strftime. When +/// the value is outside the valid range it's unspecified what strftime will +/// output. For example weekday 8, can print 1 when the day is processed module +/// 7 since that handles the Sunday for 0-based weekday. It can also print 8 if +/// 7 is handled as a special case.) +/// +/// The Standard doesn't specify what to do in this case so the result depends +/// on the result of the underlaying code. +/// +/// \pre When the (abbreviated) weekday on month name are used the caller +/// validates the value is valid. So the caller handles that requirement +/// of Table 97: Meaning of conversion specifiers [tab:time.format.spec]. +/// Formats a time based on a tm struct. +/// +/// When no chrono-specs are provided it uses the stream formatter. + +// Based on p2098r1, which is based on MSVC STL +template class > +inline constexpr bool __is_specialization_v = false; // true if and only if _Type is a specialization of _Template +template