Extending <chrono> to Calendars and Time Zones

Contents

Revision History

Changes since R5

Miscellaneous editorial changes.

Un-deprecate system_clock::to_time_t and system_clock::from_time_t .

and . Rename std::literals::chrono_literals::sun to std::chrono::Sunday et al.

Changes since R4

Make the parsing of minutes optional under the flags %z , %Ez , and %Oz .

, , and . Replace the family of overloaded functions to_sys_time , to_utc_time , to_tai_time , to_gps_time , to_file_time , with clock_cast .

, , , , , with . Replace undefined behavior with unspecified behavior in [time.calendar].

Allow zoned_time conversion among different TimeZonePtr types.

conversion among different types. Specify the constructors for nonexistent_local_time and ambiguous_local_time .

Changes since R3

Presume that the time zone database is supplied only by the std::lib implementation, but can be updated at run time. Removed remote_download and remote_install . This functionality is now subsumed by the implementation.

and . This functionality is now subsumed by the implementation. to_stream sets failbit if it is required to create a name for an invalid month or weekday.

sets if it is required to create a name for an invalid month or weekday. Add note to promise compatibility with fmt (P0645)

(P0645) Have format throw an exception if anything happens so that it could not return an accurate string.

throw an exception if anything happens so that it could not return an accurate string. Template zoned_time on TimeZonePtr .

on . Give weekday_indexed a defaulted default constructor.

a defaulted default constructor. Make from_stream and to_stream customization points.

and customization points. Make the database singleton a singly linked list of tzdb with an atomic head pointer, instead of a single tzdb .

with an atomic head pointer, instead of a single . Rewrite in terms of string_view .

. Improve spec for operator-(const year_month& x, const year_month& y).

Refine constraints on conversions from calendar types to sys_days.

Added zoned_time default constructor.

default constructor. Added zoned_time deduction guides.

deduction guides. Correct minor type-o's.

Correct html bugs.

Changes since R2

Add to_stream and from_stream to utc_time<Duration> , tai_time<Duration> , and gps_time<Duration> .

and to , , and . Add from_stream , and rewrite format and parse in terms of to_stream and from_stream .

, and rewrite and in terms of and . Add to_stream and from_stream for year , month , day , weekday , year_month , and month_day .

and for , , , , , and . to_stream will set failbit instead of throw .

will set instead of . Add file_clock and hook it into filesytem .

and hook it into . Relax zoned_time to be coarser than seconds.

to be coarser than seconds. Remove make_time and make_zoned in favor of the implicit deduction guides.

and in favor of the implicit deduction guides. Create zoned_time(const char* name, ...) overloads to enable implicit deduction guides.

overloads to enable implicit deduction guides. Give time_of_day default constructor.

default constructor. Add Alloc to basic_string everywhere possible.

to everywhere possible. Deprecate system_clock::to_time_t and system_clock::from_time_t .

and . Make duration streaming respect padding and alignment requests.

Add is_clock type trait.

type trait. Allow the Clock template parameter of time_point to be a Clock or a local_t .

to be a Clock or a . Make functions in [thread] that take a Clock template parameter ill-formed if is_clock {} is false.

Changes since R1

Make time_point incremental and decrementable

incremental and decrementable Add unary operators + and - to year

Remove enum {am, pm} , time_of_day constructors which use it, and make_time factory functions which use it.

, constructors which use it, and factory functions which use it. Add to_stream .

. Add format and parse for duration .

Changes since R0

Tighten up utc_clock::utc_to_sys and utc_clock::sys_to_utc .

and . Eliminate utc_clock::utc_to_sys and utc_clock::sys_to_utc in favor of free functions such as to_sys_time and to_utc_time .

and in favor of free functions such as and . Give utc_time a streaming operator.

a streaming operator. Change format to take time_point s by const& instead of by value.

to take s by instead of by value. Add trivial default constructors to most calendar types.

Create %Ez & %Oz to put ':' in offset for format and parse.

Add %F to parse.

Changed parse functions to parse manipulators.

Excuse local_t from being a clock

Guarantee Unix Time.

Add duration stream insertion.

Introduce tai_clock.

Introduce gps_clock.

Removed noexcept from make_time .

Introduction

The purpose of a calendar is to give a name to each day.1 There are many different ways this can be accomplished. This paper proposes only the Gregorian calendar. However the design of this proposal is such that clients can code other calendars and have them interoperate with <chrono> , the civil calendar, and with time zones, all with a minimal coupling. For example:

#include "coptic.h" // not proposed, just an example #include <chrono> #include <iostream> int main() { using namespace std::chrono; auto date = 2016y/May/29; cout << date << " is " << coptic::year_month_day{date} << " in the Coptic calendar

"; // 2016-05-29 is 1732-09-21 in the Coptic calendar }

The above example creates a date in the Gregorian calendar (proposed) with the literal 2016y/May/29 . The meaning of this literal is without question. It is conventional and clearly readable. This proposal has no knowledge whatsoever of the Coptic calendar. However it is relatively easy to create a Coptic calendar (which knows nothing about the Gregorian calendar), which will convert to and from the Gregorian calendar. This is done by establishing a clear and simple communication channel between calendar systems and the <chrono> library (specifically a system_clock::time_point with a precision of days).

The paper proposes:

Minimal extensions to <chrono> to support calendar and time zone libraries. A proleptic Gregorian calendar, hereafter referred to as the civil calendar. A time zone library based on the IANA Time Zone Database. strftime -like formatting and parsing facilities with fully operational support for fractional seconds, time zone abbreviations, and UTC offsets. Several <chrono> clocks for computing with leap seconds which is also supported by the IANA Time Zone Database.

Everything proposed herein has been fully implemented here:

The implementation includes full documentation, and an active community of users with positive field experience. The implementation has been ported to Windows, Linux, Android, macOS and iOS.

The API stresses:

Seamless integration with the existing <chrono> library.

library. Type safety.

Detection of errors at compile time.

Performance.

Ease of use.

Readable code.

No artificial restrictions on precision. Note: current financial software is currently in the middle of a transition from seconds precision to milliseconds precision. This library handles that transition as seamlessly as <chrono> does.

Listing "Performance" in the API design deserves a little explanation as one usually thinks of that as an implementation issue. Think of it this way:

If vector<T>::push_front(const T&) existed, that would encourage inefficient code, even though it would be trivial to implement.

existed, that would encourage inefficient code, even though it would be trivial to implement. If list<T>::operator[](size_type index) existed, that would encourage inefficient code, even though it would be trivial to implement (by incrementing from begin() or decrementing from end() ).

This API makes it convenient to write efficient code, and inconvenient to write inefficient code. It turns out that conversion between a field type such as {year, month, day} and a serial type such as {count-of-days} is one of the more expensive operations when dealing with calendrical computations. Both data structures are very useful (just as both vector and list are very useful). So this library puts you in control of when and how often that conversion takes place, and makes it easy to avoid such conversions when not necessary.

Description

One can create a year like this:

auto y = year{2016};

Just like <chrono> , type safety is taken very seriously. The type year is distinct from type int , just as 3 can never mean "3 seconds", unless it is explicitly typed to do so: seconds{3} .

And just like seconds , there is a year literal suffix which can help make your code more readable:

auto y = 2016y;

year is a partial-calendar-type. It can be combined with other partial-calendar-types to create a full-calendar-type such as year_month_day . Full-calendar-types can be converted to and from the family of system_clock::time_point s. Full-calendar-types such as year_month_day are time points with a precision of a day, but they are also field types. They are composed of 3 fields under the hood: year , month and day . Thus when you construct a year_month_day from a year , month and day , absolutely no computation takes place. The only thing that happens is a year , month and day are stored inside the year_month_day .

year_month_day ymd1{2016y, month{5}, day{29}};

This is a very simple operation and can even be made constexpr when all of the inputs are compile-time constants. And conventional syntax is available which means the exact same thing, with the same run-time or compile-time performance. It can make date literals much more readable without sacrificing type safety:

constexpr year_month_day ymd1{2016y, month{5}, day{29}}; constexpr auto ymd2 = 2016y/May/29d; static_assert(ymd1 == ymd2); static_assert(ymd1.year() == 2016y); static_assert(ymd1.month() == May); static_assert(ymd1.day() == 29d);

year_month_day is a very simple, very understandable calendrical data structure:

class year_month_day { chrono::year y_; // exposition only chrono::month m_; // exposition only chrono::day d_; // exposition only public: constexpr year_month_day(const chrono::year& y, const chrono::month& m, const chrono::day& d) noexcept; // ...

By now you should be yawning and muttering "so what?"

Now we introduce a little <chrono> infrastructure that serves as the communication channel with simplistic calendrical data structures such as year_month_day .

using days = duration<int32_t, ratio_multiply<ratio<24>, hours::period>>; template <class Duration> using sys_time = time_point<system_clock, Duration>; using sys_days = sys_time<days>;

sys_days is a std::chrono::time_point . This time_point is based on system_clock and has a very coarse precision: 24 hours. Just as system_clock::time_point is nothing more than a count of microseconds (or nanoseconds, or whatever), sys_days is simply a count of days since the system_clock epoch. And sys_days is fully interoperable with system_clock::time_point in all of the ways normal to the <chrono> library:

sys_days implicitly converts to system_clock::time_point with no truncation error.

implicitly converts to with no truncation error. system_clock::time_point does not implicitly convert to sys_days because it would involve truncation error.

implicitly convert to because it would involve truncation error. Explicit conversion can be achieved from system_clock::time_point by using the existing <chrono> facilities time_point_cast or floor .

constexpr system_clock::time_point tp = sys_days{2016y/May/29d}; // Convert date to time_point static_assert(tp.time_since_epoch() == 1'464'480'000'000'000us); constexpr auto ymd = year_month_day{floor<days>(tp)}; // Convert time_point to date static_assert(ymd == 2016y/May/29d);

The calendrical type year_month_day provides conversions to and from sys_days . This conversion is easy to do for std::lib implementors using algorithms such as these. If the committee standardizes existing practice and specifies that system_clock measures Unix Time, then it will be equally easy for anyone to write their own calendar system which converts to and from sys_days (e.g. the coptic example in the introduction).

This proposal actually contains a second calendar. It is so closely related to the civil calendar that we normally don't think of it as another calendar. We often refer to dates like "the 5th Sunday of May in 2016" as opposed to "the 29th of May in 2016." This proposal makes it so easy to build fully functional calendars that interoperate with system_clock::time_point , that it is nearly trivial to include such functionality:

constexpr system_clock::time_point tp = sys_days{Sunday[5]/May/2016}; // Convert date to time_point static_assert(tp.time_since_epoch() == 1'464'480'000'000'000us); constexpr auto ymd = year_month_weekday{floor<days>(tp)}; // Convert time_point to date static_assert(ymd == Sunday[5]/May/2016);

The literal Sunday[5]/May/2016 means "the 5th Sunday of May in 2016." The conventional syntax is remarkably readable. Constructor syntax is also available to do the same thing. The type constructed is year_month_weekday which does nothing but store a year , month , weekday , and the number 5. This "auxiliary calendar" converts to and from sys_days just like year_month_day as demonstrated above. As such, year_month_weekday will interoperate with year_month_day (by bouncing off of sys_days ) just as it will with any other calendar that interoperates with sys_days :

static_assert(2016y/May/29d == year_month_day{Sunday[5]/May/2016});

Since year_month_day is so easy to convert to (or from) a time_point it makes sense to convert to a time_point when you need to talk about a date and time-of-day:

constexpr auto tp = sys_days{2016y/May/29d} + 7h + 30min; // 2016-05-29 07:30 UTC

The time zone is implicitly UTC because system_clock tracks Unix Time which is (a very close approximation to) UTC. If you need another time zone, no worries, we'll get there. And remember, tp above is a system_clock::time_point , except with minutes precision. You can compare it with system_clock::now() to find out if the date is in the past or the future. Also note that the syntax above (like <chrono> ) is precision neutral. That's because the syntax above is <chrono> , except for the part converting a calendar type into the <chrono> system. If you suddenly need to convert your minutes-precision time point into seconds or milliseconds (or whatever) precision, the change is seamlessly handled by the existing <chrono> system:

constexpr auto tp = sys_days{2016y/May/29d} + 7h + 30min + 6s + 153ms; // 2016-05-29 07:30:06.153 UTC

Simple streaming is provided:

cout << tp << '

'; // 2016-05-29 07:30:06.153

But I need the time in Tokyo!

auto tp = sys_days{2016y/May/29d} + 7h + 30min + 6s + 153ms; // 2016-05-29 07:30:06.153 UTC zoned_time zt = {"Asia/Tokyo", tp}; cout << zt << '

'; // 2016-05-29 16:30:06.153 JST

zoned_time is templated on the duration type of tp , which is automatically deduced from the initialization expression (milliseconds in this example). This effectively pairs a time zone with a time point. In this example we pair the time zone "Asia/Tokyo" with a sys_time (which is implicitly UTC). When printed out, you see the local time, and by default the current time zone abbreviation. Also by default, you see the full precision of the zoned_time .

Sometimes, instead of specifying the time in UTC as above, it is convenient to specify the time in terms of the local time of the time zone. It is very easy to change the above example to mean 7:30 JST instead of 7:30 UTC:

auto tp = local_days{2016y/May/29d} + 7h + 30min + 6s + 153ms; // 2016-05-29 07:30:06.153 auto zt = zoned_time{"Asia/Tokyo", tp}; cout << zt << '

'; // 2016-05-29 07:30:06.153 JST

The only change to the code is the use of local_days in place of sys_days . local_days is also a std::chrono::time_point but its "clock type" local_t has no now() function. This time_point is called local_time . A local_time can refer to any time zone. In the above example when we pair "Asia/Tokyo" with the local_time , the result becomes a zoned_time with the local time specified by the local_time .

To interoperate with time zones, calendrical types must convert to and from local_days as well as sys_days . The math is identical for both conversions, so it is very easy for the calendar author to provide. But as seen in this example, the meaning can be quite different.

The client of the calendar library can easily use the calendar types with the time zone library, specifying times either in the local time, or in UTC, simply by switching between local_days and sys_days . Here is an example that sets up a meeting at 9am on the third Tuesday of June, 2016 in New York:

auto zt = zoned_time{"America/New_York", local_days{Tuesday[3]/June/2016} + 9h}; cout << zt << '

'; // 2016-06-21 09:00:00 EDT

Need to set up a video conference with your partners in Helsinki?

cout << zoned_time{"Europe/Helsinki", zt} << '

';

This converts one zoned_time into another zoned_time where the only difference is changing from "America/New_York" to "Europe/Helsinki". The conversion preserves the UTC equivalent in both zoned_time s, and therefore outputs:

2016-06-21 16:00:00 EEST

And if this is not the formatting you prefer, that is easily fixed too:

cout << format("%F %H:%M %z", zoned_time{"Europe/Helsinki", zt}) << '

'; // 2016-06-21 16:00 +0300

Or perhaps properly localized:

cout << format(locale{"fi_FI"}, "%c", zoned_time{"Europe/Helsinki", zt}) << '

'; // Ti 21 Kes 16:00:00 2016

Wait, slow down, this is too much information! Let's start at the beginning. How do I get the current time?

cout << system_clock::now() << " UTC

"; // 2016-05-30 17:57:30.694574 UTC

My current local time?

cout << zoned_time{current_zone(), system_clock::now()} << '

'; // 2016-05-30 13:57:30.694574 EDT

Current time in Budapest?

cout << zoned_time{"Europe/Budapest", system_clock::now()} << '

'; // 2016-05-30 19:57:30.694574 CEST

For more documentation about the calendar portion of this proposal, including more details, more examples, and performance analyses, please see:

For a video introduction to the calendar portion, please see:

For a video introduction to the time zone portion, please see:

For more documentation about the time zone portion of this proposal, including more details, and more examples, please see:

For more examples, some of which are written by users of this library, please see:

For another example calendar which models the ISO week-based calendar, please see:

Proposed Wording

Table of Contents for Proposed Wording

Text in grey boxes is not proposed wording.

Insert into synopsis in 23.17.2 Header <chrono> synopsis [time.syn]:

namespace std { namespace chrono { // ... // customization traits // ... template <class T> struct is_clock; template <class T> inline constexpr bool is_clock_v = is_clock<T>::value; // duration I/O template <class charT, class traits, class Rep, class Period> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const duration<Rep, Period>& d); template <class charT, class traits, class Rep, class Period> basic_ostream<charT, traits>& to_stream(basic_ostream<charT, traits>& os, const charT* fmt, const duration<Rep, Period>& d); template <class charT, class traits, class Rep, class Period, class Alloc = allocator<charT>> basic_istream<charT, traits>& from_stream(basic_istream<charT, traits>& is, const charT* fmt, duration<Rep, Period>& d, basic_string<charT, traits, Alloc>* abbrev = nullptr, minutes* offset = nullptr); // ... // convenience typedefs // ... using days = duration<signed integer type of at least 25 bits, ratio_multiply<ratio<24>, hours::period>>; using weeks = duration<signed integer type of at least 22 bits, ratio_multiply<ratio<7>, days::period>>; using years = duration<signed integer type of at least 17 bits, ratio_multiply<ratio<146097, 400>, days::period>>; using months = duration<signed integer type of at least 20 bits, ratio_divide<years::period, ratio<12>>>; // ... // clocks // ... class utc_clock; class tai_clock; class gps_clock; class file_clock; // time_point families template <class Duration> using sys_time = time_point<system_clock, Duration>; using sys_seconds = sys_time<seconds>; using sys_days = sys_time<days>; struct local_t {}; template <class Duration> using local_time = time_point<local_t, Duration>; using local_seconds = local_time<seconds>; using local_days = local_time<days>; template <class Duration> using utc_time = time_point<utc_clock, Duration>; using utc_seconds = utc_time<seconds>; template <class Duration> using tai_time = time_point<tai_clock, Duration>; using tai_seconds = tai_time<seconds>; template <class Duration> using gps_time = time_point<gps_clock, Duration>; using gps_seconds = gps_time<seconds>; template <class Duration> using file_time = time_point<file_clock, Duration>; // time_point conversions template <class DestClock, class SourceClock> struct clock_time_conversion; template <class DestClock, class SourceClock, class Duration> time_point<DestClock, see below> clock_cast(const time_point<SourceClock, Duration>& t); // time_point I/O // operator<< template <class charT, class traits, class Duration> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const sys_time<Duration>& tp); template <class charT, class traits, class Duration> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const local_time<Duration>& tp); template <class charT, class traits> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const sys_days& dp); template <class charT, class traits, class Duration> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const utc_time<Duration>& t); template <class charT, class traits, class Duration> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const tai_time<Duration>& t); template <class charT, class traits, class Duration> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const gps_time<Duration>& t); template <class charT, class traits, class Duration> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const file_time<Duration>& tp); // to_stream template <class charT, class traits, class Duration> basic_ostream<charT, traits>& to_stream(basic_ostream<charT, traits>& os, const charT* fmt, const sys_time<Duration>& tp); template <class charT, class traits, class Duration> basic_ostream<charT, traits>& to_stream(basic_ostream<charT, traits>& os, const charT* fmt, const local_time<Duration>& tp, const string* abbrev = nullptr, const seconds* offset_sec = nullptr); template <class charT, class traits, class Duration> basic_ostream<charT, traits>& to_stream(basic_ostream<charT, traits>& os, const charT* fmt, const utc_time<Duration>& tp); template <class charT, class traits, class Duration> basic_ostream<charT, traits>& to_stream(basic_ostream<charT, traits>& os, const charT* fmt, const tai_time<Duration>& tp); template <class charT, class traits, class Duration> basic_ostream<charT, traits>& to_stream(basic_ostream<charT, traits>& os, const charT* fmt, const gps_time<Duration>& tp); template <class charT, class traits, class Duration> basic_ostream<charT, traits>& to_stream(basic_ostream<charT, traits>& os, const charT* fmt, const file_time<Duration>& tp); // from_stream template <class charT, class traits, class Duration, class Alloc = allocator<charT>> basic_istream<charT, traits>& from_stream(basic_istream<charT, traits>& is, const charT* fmt, sys_time<Duration>& tp, basic_string<charT, traits, Alloc>* abbrev = nullptr, minutes* offset = nullptr); template <class charT, class traits, class Duration, class Alloc = allocator<charT>> basic_istream<charT, traits>& from_stream(basic_istream<charT, traits>& is, const charT* fmt, local_time<Duration>& tp, basic_string<charT, traits, Alloc>* abbrev = nullptr, minutes* offset = nullptr); template <class charT, class traits, class Duration, class Alloc = allocator<charT>> basic_istream<charT, traits>& from_stream(basic_istream<charT, traits>& is, const charT* fmt, utc_time<Duration>& tp, basic_string<charT, traits, Alloc>* abbrev = nullptr, minutes* offset = nullptr); template <class charT, class traits, class Duration, class Alloc = allocator<charT>> basic_istream<charT, traits>& from_stream(basic_istream<charT, traits>& is, const charT* fmt, tai_time<Duration>& tp, basic_string<charT, traits, Alloc>* abbrev = nullptr, minutes* offset = nullptr); template <class charT, class traits, class Duration, class Alloc = allocator<charT>> basic_istream<charT, traits>& from_stream(basic_istream<charT, traits>& is, const charT* fmt, gps_time<Duration>& tp, basic_string<charT, traits, Alloc>* abbrev = nullptr, minutes* offset = nullptr); template <class charT, class traits, class Duration, class Alloc = allocator<charT>> basic_istream<charT, traits>& from_stream(basic_istream<charT, traits>& is, const charT* fmt, file_time<Duration>& tp, basic_string<charT, traits, Alloc>* abbrev = nullptr, minutes* offset = nullptr); // Calendrical types struct last_spec; class day; constexpr bool operator==(const day& x, const day& y) noexcept; constexpr bool operator!=(const day& x, const day& y) noexcept; constexpr bool operator< (const day& x, const day& y) noexcept; constexpr bool operator> (const day& x, const day& y) noexcept; constexpr bool operator<=(const day& x, const day& y) noexcept; constexpr bool operator>=(const day& x, const day& y) noexcept; constexpr day operator+(const day& x, const days& y) noexcept; constexpr day operator+(const days& x, const day& y) noexcept; constexpr day operator-(const day& x, const days& y) noexcept; constexpr days operator-(const day& x, const day& y) noexcept; template <class charT, class traits> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const day& d); template <class charT, class traits> basic_ostream<charT, traits>& to_stream(basic_ostream<charT, traits>& os, const charT* fmt, const day& d); template <class charT, class traits, class Alloc = allocator<charT>> basic_istream<charT, traits>& from_stream(basic_istream<charT, traits>& is, const charT* fmt, day& d, basic_string<charT, traits, Alloc>* abbrev = nullptr, minutes* offset = nullptr); class month; constexpr bool operator==(const month& x, const month& y) noexcept; constexpr bool operator!=(const month& x, const month& y) noexcept; constexpr bool operator< (const month& x, const month& y) noexcept; constexpr bool operator> (const month& x, const month& y) noexcept; constexpr bool operator<=(const month& x, const month& y) noexcept; constexpr bool operator>=(const month& x, const month& y) noexcept; constexpr month operator+(const month& x, const months& y) noexcept; constexpr month operator+(const months& x, const month& y) noexcept; constexpr month operator-(const month& x, const months& y) noexcept; constexpr months operator-(const month& x, const month& y) noexcept; template <class charT, class traits> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const month& m); template <class charT, class traits> basic_ostream<charT, traits>& to_stream(basic_ostream<charT, traits>& os, const charT* fmt, const month& m); template <class charT, class traits, class Alloc = allocator<charT>> basic_istream<charT, traits>& from_stream(basic_istream<charT, traits>& is, const charT* fmt, month& m, basic_string<charT, traits, Alloc>* abbrev = nullptr, minutes* offset = nullptr); class year; constexpr bool operator==(const year& x, const year& y) noexcept; constexpr bool operator!=(const year& x, const year& y) noexcept; constexpr bool operator< (const year& x, const year& y) noexcept; constexpr bool operator> (const year& x, const year& y) noexcept; constexpr bool operator<=(const year& x, const year& y) noexcept; constexpr bool operator>=(const year& x, const year& y) noexcept; constexpr year operator+(const year& x, const years& y) noexcept; constexpr year operator+(const years& x, const year& y) noexcept; constexpr year operator-(const year& x, const years& y) noexcept; constexpr years operator-(const year& x, const year& y) noexcept; template <class charT, class traits> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const year& y); template <class charT, class traits> basic_ostream<charT, traits>& to_stream(basic_ostream<charT, traits>& os, const charT* fmt, const year& y); template <class charT, class traits, class Alloc = allocator<charT>> basic_istream<charT, traits>& from_stream(basic_istream<charT, traits>& is, const charT* fmt, year& y, basic_string<charT, traits, Alloc>* abbrev = nullptr, minutes* offset = nullptr); class weekday; constexpr bool operator==(const weekday& x, const weekday& y) noexcept; constexpr bool operator!=(const weekday& x, const weekday& y) noexcept; constexpr weekday operator+(const weekday& x, const days& y) noexcept; constexpr weekday operator+(const days& x, const weekday& y) noexcept; constexpr weekday operator-(const weekday& x, const days& y) noexcept; constexpr days operator-(const weekday& x, const weekday& y) noexcept; template <class charT, class traits> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const weekday& wd); template <class charT, class traits> basic_ostream<charT, traits>& to_stream(basic_ostream<charT, traits>& os, const charT* fmt, const weekday& wd); template <class charT, class traits, class Alloc = allocator<charT>> basic_istream<charT, traits>& from_stream(basic_istream<charT, traits>& is, const charT* fmt, weekday& wd, basic_string<charT, traits, Alloc>* abbrev = nullptr, minutes* offset = nullptr); class weekday_indexed; constexpr bool operator==(const weekday_indexed& x, const weekday_indexed& y) noexcept; constexpr bool operator!=(const weekday_indexed& x, const weekday_indexed& y) noexcept; template <class charT, class traits> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const weekday_indexed& wdi); class weekday_last; constexpr bool operator==(const weekday_last& x, const weekday_last& y) noexcept; constexpr bool operator!=(const weekday_last& x, const weekday_last& y) noexcept; template <class charT, class traits> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const weekday_last& wdl); class month_day; constexpr bool operator==(const month_day& x, const month_day& y) noexcept; constexpr bool operator!=(const month_day& x, const month_day& y) noexcept; constexpr bool operator< (const month_day& x, const month_day& y) noexcept; constexpr bool operator> (const month_day& x, const month_day& y) noexcept; constexpr bool operator<=(const month_day& x, const month_day& y) noexcept; constexpr bool operator>=(const month_day& x, const month_day& y) noexcept; template <class charT, class traits> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const month_day& md); template <class charT, class traits> basic_ostream<charT, traits>& to_stream(basic_ostream<charT, traits>& os, const charT* fmt, const month_day& md); template <class charT, class traits, class Alloc = allocator<charT>> basic_istream<charT, traits>& from_stream(basic_istream<charT, traits>& is, const charT* fmt, month_day& md, basic_string<charT, traits, Alloc>* abbrev = nullptr, minutes* offset = nullptr); class month_day_last; constexpr bool operator==(const month_day_last& x, const month_day_last& y) noexcept; constexpr bool operator!=(const month_day_last& x, const month_day_last& y) noexcept; constexpr bool operator< (const month_day_last& x, const month_day_last& y) noexcept; constexpr bool operator> (const month_day_last& x, const month_day_last& y) noexcept; constexpr bool operator<=(const month_day_last& x, const month_day_last& y) noexcept; constexpr bool operator>=(const month_day_last& x, const month_day_last& y) noexcept; template <class charT, class traits> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const month_day_last& mdl); class month_weekday; constexpr bool operator==(const month_weekday& x, const month_weekday& y) noexcept; constexpr bool operator!=(const month_weekday& x, const month_weekday& y) noexcept; template <class charT, class traits> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const month_weekday& mwd); class month_weekday_last; constexpr bool operator==(const month_weekday_last& x, const month_weekday_last& y) noexcept; constexpr bool operator!=(const month_weekday_last& x, const month_weekday_last& y) noexcept; template <class charT, class traits> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const month_weekday_last& mwdl); class year_month; constexpr bool operator==(const year_month& x, const year_month& y) noexcept; constexpr bool operator!=(const year_month& x, const year_month& y) noexcept; constexpr bool operator< (const year_month& x, const year_month& y) noexcept; constexpr bool operator> (const year_month& x, const year_month& y) noexcept; constexpr bool operator<=(const year_month& x, const year_month& y) noexcept; constexpr bool operator>=(const year_month& x, const year_month& y) noexcept; constexpr year_month operator+(const year_month& ym, const months& dm) noexcept; constexpr year_month operator+(const months& dm, const year_month& ym) noexcept; constexpr year_month operator-(const year_month& ym, const months& dm) noexcept; constexpr months operator-(const year_month& x, const year_month& y) noexcept; constexpr year_month operator+(const year_month& ym, const years& dy) noexcept; constexpr year_month operator+(const years& dy, const year_month& ym) noexcept; constexpr year_month operator-(const year_month& ym, const years& dy) noexcept; template <class charT, class traits> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const year_month& ym); template <class charT, class traits> basic_ostream<charT, traits>& to_stream(basic_ostream<charT, traits>& os, const charT* fmt, const year_month& ym); template <class charT, class traits, class Alloc = allocator<charT>> basic_istream<charT, traits>& from_stream(basic_istream<charT, traits>& is, const charT* fmt, year_month& ym, basic_string<charT, traits, Alloc>* abbrev = nullptr, minutes* offset = nullptr); class year_month_day; constexpr bool operator==(const year_month_day& x, const year_month_day& y) noexcept; constexpr bool operator!=(const year_month_day& x, const year_month_day& y) noexcept; constexpr bool operator< (const year_month_day& x, const year_month_day& y) noexcept; constexpr bool operator> (const year_month_day& x, const year_month_day& y) noexcept; constexpr bool operator<=(const year_month_day& x, const year_month_day& y) noexcept; constexpr bool operator>=(const year_month_day& x, const year_month_day& y) noexcept; constexpr year_month_day operator+(const year_month_day& ymd, const months& dm) noexcept; constexpr year_month_day operator+(const months& dm, const year_month_day& ymd) noexcept; constexpr year_month_day operator+(const year_month_day& ymd, const years& dy) noexcept; constexpr year_month_day operator+(const years& dy, const year_month_day& ymd) noexcept; constexpr year_month_day operator-(const year_month_day& ymd, const months& dm) noexcept; constexpr year_month_day operator-(const year_month_day& ymd, const years& dy) noexcept; template <class charT, class traits> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const year_month_day& ymd); template <class charT, class traits> basic_ostream<charT, traits>& to_stream(basic_ostream<charT, traits>& os, const charT* fmt, const year_month_day& ymd); template <class charT, class traits, class Alloc = allocator<charT>> basic_istream<charT, traits>& from_stream(basic_istream<charT, traits>& is, const charT* fmt, year_month_day& ymd, basic_string<charT, traits, Alloc>* abbrev = nullptr, minutes* offset = nullptr); class year_month_day_last; constexpr bool operator==(const year_month_day_last& x, const year_month_day_last& y) noexcept; constexpr bool operator!=(const year_month_day_last& x, const year_month_day_last& y) noexcept; constexpr bool operator< (const year_month_day_last& x, const year_month_day_last& y) noexcept; constexpr bool operator> (const year_month_day_last& x, const year_month_day_last& y) noexcept; constexpr bool operator<=(const year_month_day_last& x, const year_month_day_last& y) noexcept; constexpr bool operator>=(const year_month_day_last& x, const year_month_day_last& y) noexcept; constexpr year_month_day_last operator+(const year_month_day_last& ymdl, const months& dm) noexcept; constexpr year_month_day_last operator+(const months& dm, const year_month_day_last& ymdl) noexcept; constexpr year_month_day_last operator+(const year_month_day_last& ymdl, const years& dy) noexcept; constexpr year_month_day_last operator+(const years& dy, const year_month_day_last& ymdl) noexcept; constexpr year_month_day_last operator-(const year_month_day_last& ymdl, const months& dm) noexcept; constexpr year_month_day_last operator-(const year_month_day_last& ymdl, const years& dy) noexcept; template <class charT, class traits> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const year_month_day_last& ymdl); class year_month_weekday; constexpr bool operator==(const year_month_weekday& x, const year_month_weekday& y) noexcept; constexpr bool operator!=(const year_month_weekday& x, const year_month_weekday& y) noexcept; constexpr year_month_weekday operator+(const year_month_weekday& ymwd, const months& dm) noexcept; constexpr year_month_weekday operator+(const months& dm, const year_month_weekday& ymwd) noexcept; constexpr year_month_weekday operator+(const year_month_weekday& ymwd, const years& dy) noexcept; constexpr year_month_weekday operator+(const years& dy, const year_month_weekday& ymwd) noexcept; constexpr year_month_weekday operator-(const year_month_weekday& ymwd, const months& dm) noexcept; constexpr year_month_weekday operator-(const year_month_weekday& ymwd, const years& dy) noexcept; template <class charT, class traits> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const year_month_weekday& ymwdi); class year_month_weekday_last; constexpr bool operator==(const year_month_weekday_last& x, const year_month_weekday_last& y) noexcept; constexpr bool operator!=(const year_month_weekday_last& x, const year_month_weekday_last& y) noexcept; constexpr year_month_weekday_last operator+(const year_month_weekday_last& ymwdl, const months& dm) noexcept; constexpr year_month_weekday_last operator+(const months& dm, const year_month_weekday_last& ymwdl) noexcept; constexpr year_month_weekday_last operator+(const year_month_weekday_last& ymwdl, const years& dy) noexcept; constexpr year_month_weekday_last operator+(const years& dy, const year_month_weekday_last& ymwdl) noexcept; constexpr year_month_weekday_last operator-(const year_month_weekday_last& ymwdl, const months& dm) noexcept; constexpr year_month_weekday_last operator-(const year_month_weekday_last& ymwdl, const years& dy) noexcept; template <class charT, class traits> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const year_month_weekday_last& ymwdl); // civil calendar conventional syntax operators constexpr year_month operator/(const year& y, const month& m) noexcept; constexpr year_month operator/(const year& y, int m) noexcept; constexpr month_day operator/(const month& m, const day& d) noexcept; constexpr month_day operator/(const month& m, int d) noexcept; constexpr month_day operator/(int m, const day& d) noexcept; constexpr month_day operator/(const day& d, const month& m) noexcept; constexpr month_day operator/(const day& d, int m) noexcept; constexpr month_day_last operator/(const month& m, last_spec) noexcept; constexpr month_day_last operator/(int m, last_spec) noexcept; constexpr month_day_last operator/(last_spec, const month& m) noexcept; constexpr month_day_last operator/(last_spec, int m) noexcept; constexpr month_weekday operator/(const month& m, const weekday_indexed& wdi) noexcept; constexpr month_weekday operator/(int m, const weekday_indexed& wdi) noexcept; constexpr month_weekday operator/(const weekday_indexed& wdi, const month& m) noexcept; constexpr month_weekday operator/(const weekday_indexed& wdi, int m) noexcept; constexpr month_weekday_last operator/(const month& m, const weekday_last& wdl) noexcept; constexpr month_weekday_last operator/(int m, const weekday_last& wdl) noexcept; constexpr month_weekday_last operator/(const weekday_last& wdl, const month& m) noexcept; constexpr month_weekday_last operator/(const weekday_last& wdl, int m) noexcept; constexpr year_month_day operator/(const year_month& ym, const day& d) noexcept; constexpr year_month_day operator/(const year_month& ym, int d) noexcept; constexpr year_month_day operator/(const year& y, const month_day& md) noexcept; constexpr year_month_day operator/(int y, const month_day& md) noexcept; constexpr year_month_day operator/(const month_day& md, const year& y) noexcept; constexpr year_month_day operator/(const month_day& md, int y) noexcept; constexpr year_month_day_last operator/(const year_month& ym, last_spec) noexcept; constexpr year_month_day_last operator/(const year& y, const month_day_last& mdl) noexcept; constexpr year_month_day_last operator/(int y, const month_day_last& mdl) noexcept; constexpr year_month_day_last operator/(const month_day_last& mdl, const year& y) noexcept; constexpr year_month_day_last operator/(const month_day_last& mdl, int y) noexcept; constexpr year_month_weekday operator/(const year_month& ym, const weekday_indexed& wdi) noexcept; constexpr year_month_weekday operator/(const year& y, const month_weekday& mwd) noexcept; constexpr year_month_weekday operator/(int y, const month_weekday& mwd) noexcept; constexpr year_month_weekday operator/(const month_weekday& mwd, const year& y) noexcept; constexpr year_month_weekday operator/(const month_weekday& mwd, int y) noexcept; constexpr year_month_weekday_last operator/(const year_month& ym, const weekday_last& wdl) noexcept; constexpr year_month_weekday_last operator/(const year& y, const month_weekday_last& mwdl) noexcept; constexpr year_month_weekday_last operator/(int y, const month_weekday_last& mwdl) noexcept; constexpr year_month_weekday_last operator/(const month_weekday_last& mwdl, const year& y) noexcept; constexpr year_month_weekday_last operator/(const month_weekday_last& mwdl, int y) noexcept; // time_of_day template <class Duration> class time_of_day; template <> class time_of_day<hours>; template <> class time_of_day<minutes>; template <> class time_of_day<seconds>; template <class Rep, class Period> class time_of_day<duration<Rep, Period>>; template <class charT, class traits> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const time_of_day<hours>& t); template <class charT, class traits> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const time_of_day<minutes>& t); template <class charT, class traits> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const time_of_day<seconds>& t); template <class charT, class traits, class Rep, class Period> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const time_of_day<duration<Rep, Period>>& t); // time zone database struct tzdb; class tzdb_list; const tzdb& get_tzdb(); tzdb_list& get_tzdb_list(); const time_zone* locate_zone(string_view tz_name); const time_zone* current_zone(); // Remote time zone database -- Needs discussion const tzdb& reload_tzdb(); string remote_version(); // exception classes class nonexistent_local_time; class ambiguous_local_time; // information classes struct sys_info; template <class charT, class traits> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const sys_info& si); struct local_info; template <class charT, class traits> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const local_info& li); // time_zone enum class choose {earliest, latest}; class time_zone; bool operator==(const time_zone& x, const time_zone& y) noexcept; bool operator!=(const time_zone& x, const time_zone& y) noexcept; bool operator<(const time_zone& x, const time_zone& y) noexcept; bool operator>(const time_zone& x, const time_zone& y) noexcept; bool operator<=(const time_zone& x, const time_zone& y) noexcept; bool operator>=(const time_zone& x, const time_zone& y) noexcept; // zoned_time template <class Duration, class TimeZonePtr = const time_zone*> class zoned_time; using zoned_seconds = zoned_time<seconds>; template <class Duration1, class Duration2, class TimeZonePtr> bool operator==(const zoned_time<Duration1, TimeZonePtr>& x, const zoned_time<Duration2, TimeZonePtr>& y); template <class Duration1, class Duration, class TimeZonePtr2> bool operator!=(const zoned_time<Duration1, TimeZonePtr>& x, const zoned_time<Duration2, TimeZonePtr>& y); template <class charT, class traits, class Duration, class TimeZonePtr> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const zoned_time<Duration, TimeZonePtr>& t); template <class charT, class traits, class Duration, class TimeZonePtr> basic_ostream<charT, traits>& to_stream(basic_ostream<charT, traits>& os, const charT* fmt, const zoned_time<Duration, TimeZonePtr>& tp); // format template <class charT, class Streamable> basic_string<charT> format(const charT* fmt, const Streamable& s); template <class charT, class Streamable> basic_string<charT> format(const locale& loc, const charT* fmt, const Streamable& s); template <class charT, class traits, class Alloc, class Streamable> basic_string<charT, traits, Alloc> format(const basic_string<charT, traits, Alloc>& fmt, const Streamable& s); template <class charT, class traits, class Alloc, class Streamable> basic_string<charT, traits, Alloc> format(const locale& loc, const basic_string<charT, traits, Alloc>& fmt, const Streamable& s); // parse template <class charT, class traits, class Alloc, class Parsable> unspecified parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp); template <class charT, class traits, class Alloc, class Parsable> unspecified parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp, basic_string<charT, traits, Alloc>& abbrev); template <class charT, class traits, class Alloc, class Parsable> unspecified parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp, minutes& offset); template <class charT, class traits, class Alloc, class Parsable> unspecified parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp, basic_string<charT, traits, Alloc>& abbrev, minutes& offset); // leap second support class leap; bool operator==(const leap& x, const leap& y); bool operator!=(const leap& x, const leap& y); bool operator< (const leap& x, const leap& y); bool operator> (const leap& x, const leap& y); bool operator<=(const leap& x, const leap& y); bool operator>=(const leap& x, const leap& y); template <class Duration> bool operator==(const leap& x, const sys_time<Duration>& y); template <class Duration> bool operator==(const sys_time<Duration>& x, const leap& y); template <class Duration> bool operator!=(const leap& x, const sys_time<Duration>& y); template <class Duration> bool operator!=(const sys_time<Duration>& x, const leap& y); template <class Duration> bool operator< (const leap& x, const sys_time<Duration>& y); template <class Duration> bool operator< (const sys_time<Duration>& x, const leap& y); template <class Duration> bool operator> (const leap& x, const sys_time<Duration>& y); template <class Duration> bool operator> (const sys_time<Duration>& x, const leap& y); template <class Duration> bool operator<=(const leap& x, const sys_time<Duration>& y); template <class Duration> bool operator<=(const sys_time<Duration>& x, const leap& y); template <class Duration> bool operator>=(const leap& x, const sys_time<Duration>& y); template <class Duration> bool operator>=(const sys_time<Duration>& x, const leap& y); class link; bool operator==(const link& x, const link& y); bool operator!=(const link& x, const link& y); bool operator< (const link& x, const link& y); bool operator> (const link& x, const link& y); bool operator<=(const link& x, const link& y); bool operator>=(const link& x, const link& y); inline constexpr chrono::last_spec last{}; inline constexpr chrono::weekday Sunday{0}; inline constexpr chrono::weekday Monday{1}; inline constexpr chrono::weekday Tuesday{2}; inline constexpr chrono::weekday Wednesday{3}; inline constexpr chrono::weekday Thursday{4}; inline constexpr chrono::weekday Friday{5}; inline constexpr chrono::weekday Saturday{6}; inline constexpr chrono::month January{1}; inline constexpr chrono::month February{2}; inline constexpr chrono::month March{3}; inline constexpr chrono::month April{4}; inline constexpr chrono::month May{5}; inline constexpr chrono::month June{6}; inline constexpr chrono::month July{7}; inline constexpr chrono::month August{8}; inline constexpr chrono::month September{9}; inline constexpr chrono::month October{10}; inline constexpr chrono::month November{11}; inline constexpr chrono::month December{12}; } // namespace chrono inline namespace literals { inline namespace chrono_literals { // ... constexpr chrono::day operator "" d(unsigned long long d) noexcept; constexpr chrono::year operator "" y(unsigned long long y) noexcept; } } Back to TOC

Add new section [time.is_clock] after 23.17.4.3 Specializations of common_type [time.traits.specializations]:

23.17.4.4 is_clock [time.traits.is_clock] template <class T> struct is_clock; is_clock is a UnaryTypeTrait ([meta.rqmts]) with a base characteristic of true_type if T meets the Clock requirements ([time.clock.req]), otherwise false_type . For the purposes of the specification of this trait, the extent to which an implementation determines that a type cannot meet the clock requirements is unspecified, except that as a minimum a type T shall not qualify as a clock unless it satisfies all of the following conditions: the qualified-id s T::rep , T::period , T::duration , and T::time_point are valid and each denotes a type ([temp.deduct]),

s , , , and are valid and each denotes a type ([temp.deduct]), the expression T::is_steady is well-formed when treated as an unevaluated operand,

is well-formed when treated as an unevaluated operand, the expression T::now() is well-formed when treated as an unevaluated operand. The behavior of a program that adds specializations for is_clock is undefined. Back to TOC

Add new section [time.duration.io] after 23.17.5.9 duration algorithms [time.duration.alg]:

23.17.5.10 duration stream insertion [time.duration.io] template <class charT, class traits, class Rep, class Period> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const duration<Rep, Period>& d); Requires: Rep is an integral type with rank short or greater, or a floating point type. charT is char or wchar_t . Effects: Forms a basic_string<charT, traits> from d.count() using to_string if charT is char , or to_wstring if charT is wchar_t . This basic_string<charT, traits> is appended with get_units<charT, traits>(typename Period::type{}) (described below) and inserts that basic_string into os . [Note: this specification assures that the result of this streaming operation will obey the width and alignment properties of the stream. — end note] get_units<charT, traits>(typename Period::type{}) is an exposition-only function which returns a NTCTS which depends on Period::type as follows (let period be the type Period::type ): If period is type atto , as , else

is type , , else if period is type femto , fs , else

is type , , else if period is type pico , ps , else

is type , , else if period is type nano , ns , else

is type , , else if period is type micro , µs (U+00B5), else

is type , (U+00B5), else if period is type milli , ms , else

is type , , else if period is type centi , cs , else

is type , , else if period is type deci , ds , else

is type , , else if period is type ratio<1> , s , else

is type , , else if period is type deca , das , else

is type , , else if period is type hecto , hs , else

is type , , else if period is type kilo , ks , else

is type , , else if period is type mega , Ms , else

is type , , else if period is type giga , Gs , else

is type , , else if period is type tera , Ts , else

is type , , else if period is type peta , Ps , else

is type , , else if period is type exa , Es , else

is type , , else if period is type ratio<60> , min , else

is type , , else if period is type ratio<3600> , h , else

is type , , else if period::den == 1 , [num]s , else

, , else [num/den]s . In the list above the use of num and den refer to the static data members of period which are converted to arrays of charT using a decimal conversion with no leading zeroes. For streams with charT which has a representation of 8 bits µs should be encoded as UTF-8. Otherwise UTF-16 or UTF-32 is encouraged. The implementation may substitute other encodings, including us . Returns: os . template <class charT, class traits, class Rep, class Period> basic_ostream<charT, traits>& to_stream(basic_ostream<charT, traits>& os, const charT* fmt, const duration<Rep, Period>& d); Effects: Streams d into os using the format specified by the NTCTS fmt . fmt encoding follows the rules specified by [time.format]. Returns: os . template <class charT, class traits, class Rep, class Period, class Alloc = allocator<charT>> basic_istream<charT, traits>& from_stream(basic_istream<charT, traits>& is, const charT* fmt, duration<Rep, Period>& d, basic_string<charT, traits, Alloc>* abbrev = nullptr, minutes* offset = nullptr); Effects: Attempts to parse the input stream is into the duration d using the format flags given in the NTCTS fmt as specified in [time.parse]. If the parse parses everything specified by the parsing format flags without error, and yet none of the flags impacts a duration, d will be assigned a zero value. If %Z is used and successfully parsed, that value will be assigned to *abbrev if abbrev is non-null. If %z (or a modified variant) is used and successfully parsed, that value will be assigned to *offset if offset is non-null. Returns: is . Back to TOC

Add to synopsis in section [time.point] 23.17.6 Class template time_point :

template <class Clock, class Duration = typename Clock::duration> class time_point { public: ... // 23.17.6.3, arithmetic constexpr time_point& operator++(); constexpr time_point operator++(int); constexpr time_point& operator--(); constexpr time_point operator--(int); constexpr time_point& operator+=(const duration& d); constexpr time_point& operator-=(const duration& d); ... }; Back to TOC

Modify section 23.17.6 Class template time_point [time.point]/p1:

1 Clock shall meet the Clock requirements ([time.clock.req]) or Clock shall be local_t . Back to TOC

Add to section [time.point.arithmetic] 23.17.6.3 time_point arithmetic:

constexpr time_point& operator++(); Effects: ++d_ . Returns: *this . constexpr time_point operator++(int); Returns: time_point{d_++} . constexpr time_point& operator--(); Effects: --d_ . Returns: *this . constexpr time_point operator--(int); Returns: time_point{d_--} . Back to TOC

Modify 23.17.7 [time.clock]:

1 The types defined in this subclause shall satisfy the TrivialClock requirements (23.17.3) unless otherwise specified . Back to TOC

Modify 23.17.7.1 [time.clock.system]:

1 Objects of class system_clock represent wall clock time from the system-wide realtime clock. sys_time<Duration> measures time since (and before) 1970-01-01 00:00:00 UTC excluding leap seconds. This measure is commonly referred to as Unix Time. This measure facilitates an efficient mapping between sys_time and calendar types ([time.calendar]). [Example: sys_seconds{sys_days{1970y/January/1}}.time_since_epoch() is 0s sys_seconds{sys_days{2000y/January/1}}.time_since_epoch() is 946'684'800s which is 10'957 * 86'400s —end example] Back to TOC

Append new paragraphs after 23.17.7.1 [time.clock.system]/p4:

template <class charT, class traits, class Duration> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const sys_time<Duration>& tp); Remarks: This operator shall not participate in overload resolution if treat_as_floating_point_v<typename Duration::rep> is true, or if Duration{1} >= days{1} . Effects: auto const dp = floor<days>(tp); os << year_month_day{dp} << ' ' << time_of_day{tp-dp}; Returns: os . [Example: cout << sys_seconds{0s} << '

'; // 1970-01-01 00:00:00 cout << sys_seconds{946'684'800s} << '

'; // 2000-01-01 00:00:00 cout << sys_seconds{946'688'523s} << '

'; // 2000-01-01 01:02:03 — end example] template <class charT, class traits> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const sys_days& dp); Effects: os << year_month_day{dp} . Returns: os . template <class charT, class traits, class Duration> basic_ostream<charT, traits>& to_stream(basic_ostream<charT, traits>& os, const charT* fmt, const sys_time<Duration>& tp); Effects: Streams tp into os using the format specified by the NTCTS fmt . fmt encoding follows the rules specified by [time.format]. If %Z is used, it will be replaced with "UTC" widened to charT . If %z is used (or a modified variant of %z ), an offset of 0min will be formatted. Returns: os . template <class charT, class traits, class Duration, class Alloc = allocator<charT>> basic_istream<charT, traits>& from_stream(basic_istream<charT, traits>& is, const charT* fmt, sys_time<Duration>& tp, basic_string<charT, traits, Alloc>* abbrev = nullptr, minutes* offset = nullptr); Effects: Attempts to parse the input stream is into the sys_time tp using the format flags given in the NTCTS fmt as specified in [time.parse]. If the parse fails to decode a valid date, is.setstate(ios_base::failbit) shall be called and tp shall not be modified. If %Z is used and successfully parsed, that value will be assigned to *abbrev if abbrev is non-null. If %z (or a modified variant) is used and successfully parsed, that value will be assigned to *offset if offset is non-null. Additionally, the parsed offset will be subtracted from the successfully parsed timestamp prior to assigning that difference to tp . Returns: is . Back to TOC

Add new section [time.clock.utc] after 23.17.7.1 Class system_clock [time.clock.system]:

23.17.7.2 Class utc_clock [time.clock.utc] class utc_clock { public: using rep = a signed arithmetic type; using period = ratio<unspecified, unspecified>; using duration = chrono::duration<rep, period>; using time_point = chrono::time_point<utc_clock>; static constexpr bool is_steady = unspecified; static time_point now(); template <class Duration> static sys_time<common_type_t<Duration, seconds>> to_sys(const utc_time<Duration>& t); template <class Duration> static utc_time<common_type_t<Duration, seconds>> from_sys(const sys_time<Duration>& t); }; In contrast to sys_time which does not take leap seconds into account, utc_clock and its associated time_point , utc_time , count time, including leap seconds, since 1970-01-01 00:00:00 UTC. [Example: clock_cast<utc_clock>(sys_seconds{sys_days{1970y/January/1}}).time_since_epoch() is 0s clock_cast<utc_clock>(sys_seconds{sys_days{2000y/January/1}}).time_since_epoch() is 946'684'822s which is 10'957 * 86'400s + 22s —end example] utc_clock is not a TrivialClock unless the implementation can guarantee that utc_clock::now() does not propagate an exception. [Note: noexcept(from_sys(system_clock::now())) is false . — end note] static utc_clock::time_point utc_clock::now(); Returns: from_sys(system_clock::now()) , or a more accurate value of utc_time . template <typename Duration> static sys_time<common_type_t<Duration, seconds>> utc_clock::to_sys(const utc_time<Duration>& u); Returns: A sys_time t , such that from_sys(t) == u if such a mapping exists. Otherwise u represents a time_point during a leap second insertion and the last representable value of sys_time prior to the insertion of the leap second is returned. template <typename Duration> static utc_time<common_type_t<Duration, seconds>> utc_clock::from_sys(const sys_time<Duration>& t); Returns: A utc_time u , such that u.time_since_epoch() - t.time_since_epoch() is equal to the number of leap seconds that were inserted between t and 1970-01-01. If t is exactly the date of leap second insertion, then the conversion counts that leap second as inserted. [Example: auto t = sys_days{July/1/2015} - 2ns; auto u = utc_clock::from_sys(t); assert(u.time_since_epoch() - t.time_since_epoch() == 25s); t += 1ns; u = utc_clock::from_sys(t); assert(u.time_since_epoch() - t.time_since_epoch() == 25s); t += 1ns; u = utc_clock::from_sys(t); assert(u.time_since_epoch() - t.time_since_epoch() == 26s); t += 1ns; u = utc_clock::from_sys(t); assert(u.time_since_epoch() - t.time_since_epoch() == 26s); — end example] template <class charT, class traits, class Duration> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const utc_time<Duration>& t); Effects: Calls to_stream(os, fmt, t) , where fmt is a string containing "%F %T" widened to charT . Returns: os . template <class charT, class traits, class Duration> basic_ostream<charT, traits>& to_stream(basic_ostream<charT, traits>& os, const charT* fmt, const utc_time<Duration>& tp); Effects: Streams tp into os using the format specified by the NTCTS fmt . fmt encoding follows the rules specified by [time.format]. If %Z is used, it will be replaced with "UTC" widened to charT . If %z is used (or a modified variant of %z ), an offset of 0min will be formatted. If tp represents a time during a leap second insertion, and if a seconds field is formatted, the integral portion of that format shall be "60" widened to charT . Returns: os . [Example: auto t = sys_days{July/1/2015} - 500ms; auto u = clock_cast<utc_clock>(t); for (auto i = 0; i < 8; ++i, u += 250ms) cout << u << " UTC

"; Output: 2015-06-30 23:59:59.500 UTC 2015-06-30 23:59:59.750 UTC 2015-06-30 23:59:60.000 UTC 2015-06-30 23:59:60.250 UTC 2015-06-30 23:59:60.500 UTC 2015-06-30 23:59:60.750 UTC 2015-07-01 00:00:00.000 UTC 2015-07-01 00:00:00.250 UTC — end example] template <class charT, class traits, class Duration, class Alloc = allocator<charT>> basic_istream<charT, traits>& from_stream(basic_istream<charT, traits>& is, const charT* fmt, utc_time<Duration>& tp, basic_string<charT, traits, Alloc>* abbrev = nullptr, minutes* offset = nullptr); Effects: Attempts to parse the input stream is into the utc_time tp using the format flags given in the NTCTS fmt as specified in [time.parse]. If the parse fails to decode a valid date, is.setstate(ios_base::failbit) shall be called and tp shall not be modified. If %Z is used and successfully parsed, that value will be assigned to *abbrev if abbrev is non-null. If %z (or a modified variant) is used and successfully parsed, that value will be assigned to *offset if offset is non-null. Additionally, the parsed offset will be subtracted from the successfully parsed timestamp prior to assigning that difference to tp . Returns: is . Back to TOC

Add new section [time.clock.tai] after 23.17.7.2 Class utc_clock [time.clock.utc]:

23.17.7.3 Class tai_clock [time.clock.tai] class tai_clock { public: using rep = a signed arithmetic type; using period = ratio<unspecified, unspecified>; using duration = chrono::duration<rep, period>; using time_point = chrono::time_point<tai_clock>; static constexpr bool is_steady = unspecified; static time_point now(); template <class Duration> static utc_time<common_type_t<Duration, seconds>> to_utc(const tai_time<Duration>&) noexcept; template <class Duration> static tai_time<common_type_t<Duration, seconds>> from_utc(const utc_time<Duration>&) noexcept; }; The clock tai_clock measures seconds since 1958-01-01 00:00:00 and is offset 10s ahead of UTC at this date. That is, 1958-01-01 00:00:00 TAI is equivalent to 1957-12-31 23:59:50 UTC. Leap seconds are not inserted into TAI. Therefore every time a leap second is inserted into UTC, UTC falls another second behind TAI. For example by 2000-01-01 there had been 22 leap seconds inserted so 2000-01-01 00:00:00 UTC is equivalent to 2000-01-01 00:00:32 TAI (22s plus the initial 10s offset). tai_clock is not a TrivialClock unless the implementation can guarantee that tai_clock::now() does not propagate an exception. [Note: noexcept(from_utc(utc_clock::now())) is false . — end note] static tai_clock::time_point tai_clock::now(); Returns: from_utc(utc_clock::now()) , or a more accurate value of tai_time . template <class Duration> static utc_time<common_type_t<Duration, seconds>> to_utc(const tai_time<Duration>& t) noexcept; Returns: utc_time<common_type_t<Duration, seconds>>{t.time_since_epoch()} - 378691210s [Note: 378691210s == sys_days{1970y/January/1} - sys_days{1958y/January/1} + 10s — end note] template <class Duration> static tai_time<common_type_t<Duration, seconds>> tai_clock::from_utc(const utc_time<Duration>& t) noexcept; Returns: tai_time<common_type_t<Duration, seconds>>{t.time_since_epoch()} + 378691210s [Note: 378691210s == sys_days{1970y/January/1} - sys_days{1958y/January/1} + 10s — end note] template <class charT, class traits, class Duration> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const tai_time<Duration>& t); Effects: Calls to_stream(os, fmt, t) , where fmt is a string containing "%F %T" widened to charT . Returns: os . template <class charT, class traits, class Duration> basic_ostream<charT, traits>& to_stream(basic_ostream<charT, traits>& os, const charT* fmt, const tai_time<Duration>& tp); Effects: Streams tp into os using the format specified by the NTCTS fmt . fmt encoding follows the rules specified by [time.format]. If %Z is used, it will be replaced with "TAI" . If %z is used (or a modified variant of %z ), an offset of 0min will be formatted. The date and time formatted shall be equivalent to that formatted by a sys_time initialized with: sys_time<Duration>{tp.time_since_epoch()} - (sys_days{1970y/January/1} - sys_days{1958y/January/1}) Returns: os . [Example: auto st = sys_days{2000y/January/1}; auto tt = clock_cast<tai_clock>(st); cout << format("%F %T %Z == ", st) << format("%F %T %Z

", tt); Output: 2000-01-01 00:00:00 UTC == 2000-01-01 00:00:32 TAI — end example] template <class charT, class traits, class Duration, class Alloc = allocator<charT>> basic_istream<charT, traits>& from_stream(basic_istream<charT, traits>& is, const charT* fmt, tai_time<Duration>& tp, basic_string<charT, traits, Alloc>* abbrev = nullptr, minutes* offset = nullptr); Effects: Attempts to parse the input stream is into the tai_time tp using the format flags given in the NTCTS fmt as specified in [time.parse]. If the parse fails to decode a valid date, is.setstate(ios_base::failbit) shall be called and tp shall not be modified. If %Z is used and successfully parsed, that value will be assigned to *abbrev if abbrev is non-null. If %z (or a modified variant) is used and successfully parsed, that value will be assigned to *offset if offset is non-null. Additionally, the parsed offset will be subtracted from the successfully parsed timestamp prior to assigning that difference to tp . Returns: is . Back to TOC

Add new section [time.clock.gps] after 23.17.7.3 Class tai_clock [time.clock.tai]:

23.17.7.4 Class gps_clock [time.clock.gps] class gps_clock { public: using rep = a signed arithmetic type; using period = ratio<unspecified, unspecified>; using duration = chrono::duration<rep, period>; using time_point = chrono::time_point<gps_clock>; static constexpr bool is_steady = unspecified; static time_point now(); template <class Duration> static utc_time<common_type_t<Duration, seconds>> to_utc(const gps_time<Duration>&) noexcept; template <class Duration> static gps_time<common_type_t<Duration, seconds>> from_utc(const utc_time<Duration>&) noexcept; }; The clock gps_clock measures seconds since the first Sunday of January, 1980 00:00:00 UTC. Leap seconds are not inserted into GPS. Therefore every time a leap second is inserted into UTC, UTC falls another second behind GPS. Aside from the offset from 1958y/January/1 to 1980y/January/Sunday[1] GPS is behind TAI by 19s due to the 10s offset between 1958 and 1970 and the additional 9 leap seconds inserted between 1970 and 1980. gps_clock is not a TrivialClock unless the implementation can guarantee that gps_clock::now() does not propagate an exception. [Note: noexcept(from_utc(utc_clock::now())) is false . — end note] static gps_clock::time_point gps_clock::now(); Returns: from_utc(utc_clock::now()) , or a more accurate value of gps_time . template <class Duration> static utc_time<common_type_t<Duration, seconds>> gps_clock::to_utc(const gps_time<Duration>& t) noexcept; Returns: gps_time<common_type_t<Duration, seconds>>{t.time_since_epoch()} + 315964809s [Note: 315964809s == sys_days{1980y/January/Sunday[1]} - sys_days{1970y/January/1} + 9s — end note] template <class Duration> static gps_time<common_type_t<Duration, seconds>> gps_clock::from_utc(const utc_time<Duration>& t) noexcept; Returns: gps_time<common_type_t<Duration, seconds>>{t.time_since_epoch()} - 315964809s [Note: 315964809s == sys_days{1980y/January/Sunday[1]} - sys_days{1970y/January/1} + 9s — end note] template <class charT, class traits, class Duration> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const gps_time<Duration>& t); Effects: Calls to_stream(os, fmt, t) , where fmt is a string containing "%F %T" widened to charT . Returns: os . template <class charT, class traits, class Duration> basic_ostream<charT, traits>& to_stream(basic_ostream<charT, traits>& os, const charT* fmt, const gps_time<Duration>& tp); Effects: Streams tp into os using the format specified by the NTCTS fmt . fmt encoding follows the rules specified by [time.format]. If %Z is used, it will be replaced with "GPS" . If %z is used (or a modified variant of %z ), an offset of 0min will be formatted. The date and time formatted shall be equivalent to that formatted by a sys_time initialized with: sys_time<Duration>{tp.time_since_epoch()} + (sys_days{1980y/January/Sunday[1]} - sys_days{1970y/January/1}) Returns: os . [Example: auto st = sys_days{2000y/January/1}; auto gt = clock_cast<gps_clock>(st); cout << format("%F %T %Z == ", st) << format("%F %T %Z

", gt); Output: 2000-01-01 00:00:00 UTC == 2000-01-01 00:00:13 GPS — end example] template <class charT, class traits, class Duration, class Alloc = allocator<charT>> basic_istream<charT, traits>& from_stream(basic_istream<charT, traits>& is, const charT* fmt, gps_time<Duration>& tp, basic_string<charT, traits, Alloc>* abbrev = nullptr, minutes* offset = nullptr); Effects: Attempts to parse the input stream is into the gps_time tp using the format flags given in the NTCTS fmt as specified in [time.parse]. If the parse fails to decode a valid date, is.setstate(ios_base::failbit) shall be called and tp shall not be modified. If %Z is used and successfully parsed, that value will be assigned to *abbrev if abbrev is non-null. If %z (or a modified variant) is used and successfully parsed, that value will be assigned to *offset if offset is non-null. Additionally, the parsed offset will be subtracted from the successfully parsed timestamp prior to assigning that difference to tp . Returns: is . Back to TOC

Add new section [time.clock.file] after 23.17.7.4 Class gps_clock [time.clock.gps]:

23.17.7.5 Class file_clock [time.clock.file] class file_clock { public: using rep = a signed arithmetic type; using period = ratio<unspecified, unspecified>; using duration = chrono::duration<rep, period>; using time_point = chrono::time_point<file_clock>; static constexpr bool is_steady = unspecified; static time_point now() noexcept; // Conversion functions, see below }; The clock file_clock is used to create the time_point system used for file_time_type ([filesystems]). Its epoch is unspecified. static file_clock::time_point file_clock::now(); Returns: A file_clock::time_point indicating the current time. The class file_clock shall provide precisely one of the following two sets of static member functions: template <class Duration> static sys_time<see below> to_sys(const file_time<Duration>&); template <class Duration> static file_time<see below> from_sys(const sys_time<Duration>&); or: template <class Duration> static utc_time<see below> to_utc(const file_time<Duration>&); template <class Duration> static file_time<see below> from_utc(const utc_time<Duration>&); These member functions shall provide time_point conversions consistent with those specified by utc_clock , tai_clock , and gps_clock . The duration of the resultant time_point is computed from the Duration of the input time_point . template <class charT, class traits, class Duration> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const file_time<Duration>& t); Effects: Calls to_stream(os, fmt, t) , where fmt is a string containing "%F %T" widened to charT . Returns: os . template <class charT, class traits, class Duration> basic_ostream<charT, traits>& to_stream(basic_ostream<charT, traits>& os, const charT* fmt, const file_time<Duration>& tp); Effects: Streams tp into os using the format specified by the NTCTS fmt . fmt encoding follows the rules specified by [time.format]. If %Z is used, it will be replaced with "UTC" widened to charT . If %z is used (or a modified variant of %z ), an offset of 0min will be formatted. The date and time formatted shall be equivalent to that formatted by a sys_time initialized with clock_cast<system_clock>(tp) , or by a utc_time initialized with clock_cast<utc_clock>(tp) . Returns: os . template <class charT, class traits, class Duration, class Alloc = allocator<charT>> basic_istream<charT, traits>& from_stream(basic_istream<charT, traits>& is, const charT* fmt, file_time<Duration>& tp, basic_string<charT, traits, Alloc>* abbrev = nullptr, minutes* offset = nullptr); Effects: Attempts to parse the input stream is into the file_time tp using the format flags given in the NTCTS fmt as specified in [time.parse]. If the parse fails to decode a valid date, is.setstate(ios_base::failbit) shall be called and tp shall not be modified. If %Z is used and successfully parsed, that value will be assigned to *abbrev if abbrev is non-null. If %z (or a modified variant) is used and successfully parsed, that value will be assigned to *offset if offset is non-null. Additionally, the parsed offset will be subtracted from the successfully parsed timestamp prior to assigning that difference to tp . Returns: is . Back to TOC

Add new section [time.clock.local_time] after 23.17.7.3 Class high_resolution_clock [time.clock.hres]:

23.17.7.8 local_time [time.clock.local_time] The family of time points denoted by local_time<Duration> are based on the pseudo clock local_t . local_t has no member now() and thus does not meet the clock requirements. Nevertheless local_time<Duration> serves the vital role of representing local time with respect to a not-yet-specified time zone. Aside from being able to get the current time, the complete time_point algebra is available for local_time<Duration> (just as for sys_time<Duration> ). template <class charT, class traits, class Duration> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const local_time<Duration>& lt); Effects: os << sys_time<Duration>{lt.time_since_epoch()}; Returns: os . template <class charT, class traits, class Duration> basic_ostream<charT, traits>& to_stream(basic_ostream<charT, traits>& os, const charT* fmt, const local_time<Duration>& tp, const string* abbrev = nullptr, const seconds* offset_sec = nullptr); Effects: Streams tp into os using the format specified by the NTCTS fmt . fmt encoding follows the rules specified by [time.format]. If %Z is used, it will be replaced with *abbrev if abbrev is not equal to nullptr . If abbrev is equal to nullptr (and %Z is used), os.setstate(ios_base::failbit) shall be called. If %z is used (or a modified variant of %z ), it will be formatted with the value of *offset_sec if offset_sec is not equal to nullptr . If %z (or a modified variant of %z ) is used, and offset_sec is equal to nullptr , then os.setstate(ios_base::failbit) shall be called. Returns: os . template <class charT, class traits, class Duration, class Alloc = allocator<charT>> basic_istream<charT, traits>& from_stream(basic_istream<charT, traits>& is, const charT* fmt, local_time<Duration>& tp, basic_string<charT, traits, Alloc>* abbrev = nullptr, minutes* offset = nullptr); Effects: Attempts to parse the input stream is into the local_time tp using the format flags given in the NTCTS fmt as specified in [time.parse]. If the parse fails to decode a valid date, is.setstate(ios_base::failbit) shall be called and tp shall not be modified. If %Z is used and successfully parsed, that value will be assigned to *abbrev if abbrev is non-null. If %z (or a modified variant) is used and successfully parsed, that value will be assigned to *offset if offset is non-null. Returns: is . Back to TOC

Add new section [time.clock.clock_cast] after 23.17.7.9 local_time [time.clock.local_time]:

23.17.7.9 clock_cast [time.clock.clock_cast] template <class DestClock, class SourceClock> struct clock_time_conversion {}; clock_time_conversion serves as a trait which can be used to specify how to convert time_point<SourceClock, Duration> to time_point<DestClock, Duration> via a specialization: clock_time_conversion<DestClock, SourceClock> . A specialization of clock_time_conversion<DestClock, SourceClock> shall provide a const-qualified operator() that takes a parameter of type time_point<SourceClock, Duration> and returns a time_point<DestClock, OtherDuration> representing an equivalent point in time. OtherDuration is a chrono::duration whose specialization is computed from the input Duration in a manner which can vary for each clock_time_conversion specialization. A program may specialize clock_time_conversion if at least one of the template parameters is a user-defined clock type. Several specializations are provided by the implementation: // Identity template <typename Clock> struct clock_time_conversion<Clock, Clock> { template <class Duration> time_point<Clock, Duration> operator()(const time_point<Clock, Duration>& t) const; }; template <class Duration> time_point<Clock, Duration> operator()(const time_point<Clock, Duration>& t) const; Returns: t . template <> struct clock_time_conversion<system_clock, system_clock> { template <class Duration> sys_time<Duration> operator()(const sys_time<Duration>& t) const; }; template <class Duration> sys_time<Duration> operator()(const sys_time<Duration>& t) const; Returns: t . template <> struct clock_time_conversion<utc_clock, utc_clock> { template <class Duration> utc_time<Duration> operator()(const utc_time<Duration>& t) const; }; template <class Duration> utc_time<Duration> operator()(const utc_time<Duration>& t) const; Returns: t . // system_clock <-> utc_clock template <> struct clock_time_conversion<utc_clock, system_clock> { template <class Duration> utc_time<common_type_t<Duration, seconds>> operator()(const sys_time<Duration>& t) const; }; template <class Duration> utc_time<common_type_t<Duration, seconds>> operator()(const sys_time<Duration>& t) const; Returns: utc_clock::from_sys(t) . template <> struct clock_time_conversion<system_clock, utc_clock> { template <class Duration> sys_time<common_type_t<Duration, seconds>> operator()(const utc_time<Duration>& t) const; }; template <class Duration> sys_time<common_type_t<Duration, seconds>> operator()(const utc_time<Duration>& t) const; Returns: utc_clock::to_sys(t) . // Clock <-> system_clock template <class SourceClock> struct clock_time_conversion<system_clock, SourceClock> { template <class Duration> auto operator()(const time_point<SourceClock, Duration>& t) const -> decltype(SourceClock::to_sys(t)); }; template <class Duration> auto operator()(const time_point<SourceClock, Duration>& t) const -> decltype(SourceClock::to_sys(t)); Remarks: This function does not participate in overload resolution unless SourceClock::to_sys(t) is well-formed. If SourceClock::to_sys(t) does not return sys_time<Duration> , where Duration is a valid chrono::duration specialization, the program is ill-formed. Returns: SourceClock::to_sys(t) . template <class DestClock> struct clock_time_conversion<DestClock, system_clock> { template <class Duration> auto operator()(const sys_time<Duration>& t) const -> decltype(DestClock::from_sys(t)); }; template <class Duration> auto operator()(const sys_time<Duration>& t) const -> decltype(DestClock::from_sys(t)); Remarks: This function does not participate in overload resolution unless DestClock::from_sys(t) is well-formed. If DestClock::from_sys(t) does not return time_point<DestClock, Duration> , where Duration is a valid chrono::duration specialization, the program is ill-formed. Returns: DestClock::from_sys(t) . // Clock <-> utc_clock template <class SourceClock> struct clock_time_conversion<utc_clock, SourceClock> { template <class Duration> auto operator()(const time_point<SourceClock, Duration>& t) const -> decltype(SourceClock::to_utc(t)); }; template <class Duration> auto operator()(const time_point<SourceClock, Duration>& t) const -> decltype(SourceClock::to_utc(t)); Remarks: This function does not participate in overload resolution unless SourceClock::to_utc(t) is well-formed. If SourceClock::to_utc(t) does not return utc_time<Duration> , where Duration is a valid chrono::duration specialization, the program is ill-formed. Returns: SourceClock::to_utc(t) . template <class DestClock> struct clock_time_conversion<DestClock, utc_clock> { template <class Duration> auto operator()(const utc_time<Duration>& t) const -> decltype(DestClock::from_utc(t)); }; template <class Duration> auto operator()(const utc_time<Duration>& t) const -> decltype(DestClock::from_utc(t)); Remarks: This function does not participate in overload resolution unless DestClock::from_utc(t) is well-formed. If DestClock::from_utc(t) does not return time_point<DestClock, Duration> , where Duration is a valid chrono::duration specialization, the program is ill-formed. . Returns: DestClock::from_utc(t) . // clock_cast template <class DestClock, class SourceClock, class Duration> auto clock_cast(const time_point<SourceClock, Duration>& t); Remarks: This function does not participate in overload resolution unless at least one of the following expressions are well-formed: clock_time_conversion<DestClock, SourceClock>{}(t) Exactly one of: clock_time_conversion<DestClock, system_clock>{}( clock_time_conversion<system_clock, SourceClock>{}(t))

clock_time_conversion<DestClock, utc_clock>{}( clock_time_conversion<utc_clock, SourceClock>{}(t)) Exactly one of: clock_time_conversion<DestClock, utc_clock>{}( clock_time_conversion<utc_clock, system_clock>{}( clock_time_conversion<system_clock, SourceClock>{}(t)))

clock_time_conversion<DestClock, system_clock>{}( clock_time_conversion<system_clock, utc_clock>{}( clock_time_conversion<utc_clock, SourceClock>{}(t))) Returns: The first expression in the above list that is well-formed. If item 1 is not well-formed and both expressions in item 2 are well-formed, the clock_cast is ambiguous and the program is ill-formed. If items 1 and 2 are not well-formed and both expressions in item 3 are well-formed, the clock_cast is ambiguous and the program is ill-formed. Back to TOC

Add a new section 23.17.8 Formatting [time.format]:

If fmt (P0645) moves forward within the LEWG, this section can easily be reworked to plug into that facility without loss of functionality. This will avoid two unrelated format facilities in the standard.

23.17.8 Formatting [time.format] Each format overload specified in this section calls to_stream unqualified, so as to enable argument dependent lookup ([basic.lookup.argdep]). template <class charT, class Streamable> basic_string<charT> format(const charT* fmt, const Streamable& s); Remarks: This function shall not participate in overload resolution unless to_stream(declval<basic_ostream<charT>&>(), fmt, s) is a valid expression. Effects: Constructs a local variable of type basic_ostringstream<charT> (for exposition purposes, named os ). Executes os.exceptions(ios::failbit | ios::badbit) . Then calls to_stream(os, fmt, s) . Returns: os.str() . template <class charT, class Streamable> basic_string<charT> format(const locale& loc, const charT* fmt, const Streamable& s); Remarks: This function shall not participate in overload resolution unless to_stream(declval<basic_ostream<charT>&>(), fmt, s) is a valid expression. Effects: Constructs a local variable of type basic_ostringstream<charT> (for exposition purposes, named os ). Executes os.exceptions(ios::failbit | ios::badbit) . Then calls os.imbue(loc) . Then calls to_stream(os, fmt, s) . Returns: os.str() . template <class charT, class traits, class Alloc, class Streamable> basic_string<charT, traits, Alloc> format(const basic_string<charT, traits, Alloc>& fmt, const Streamable& s); Remarks: This function shall not participate in overload resolution unless to_stream(declval<basic_ostringstream<charT, traits, Alloc>&>(), fmt.c_str(), s) is a valid expression. Effects: Constructs a local variable of type basic_ostringstream<charT, traits, Alloc> (for exposition purposes, named os ). Executes os.exceptions(ios::failbit | ios::badbit) . Then calls to_stream(os, fmt.c_str(), s) . Returns: os.str() . template <class charT, class traits, class Alloc, class Streamable> basic_string<charT, traits, Alloc> format(const locale& loc, const basic_string<charT, traits, Alloc>& fmt, const Streamable& s); Remarks: This function shall not participate in overload resolution unless to_stream(declval<basic_ostringstream<charT, traits, Alloc>&>(), fmt.c_str(), s) is a valid expression. Effects: Constructs a local variable of type basic_ostringstream<charT, traits, Alloc> (for exposition purposes, named os ). Then calls os.imbue(loc) . Executes os.exceptions(ios::failbit | ios::badbit) . Then calls to_stream(os, fmt.c_str(), s) . Returns: os.str() . The format functions call a to_stream function with a basic_ostream , a formatting string specifier, and a Streamable argument. Each to_stream overload is customized for each Streamable type. However all to_stream overloads treat the formatting string specifier according to the following specification: The fmt string consists of zero or more conversion specifiers and ordinary multibyte characters. A conversion specifier consists of a % character, possibly followed by an E or O modifier character (described below), followed by a character that determines the behavior of the conversion specifier. All ordinary multibyte characters (excluding the terminating null character) are streamed unchanged into the basic_ostream . Each conversion specifier is replaced by appropriate characters as described in the following list. Some of the conversion specifiers depend on the locale which is imbued to the basic_ostream . If the Streamable object does not contain the information the conversion specifier refers to, the value streamed to the basic_ostream is unspecified. Unless explicitly specified, Streamable types will not contain time zone abbreviation and time zone offset information. If available, the conversion specifiers %Z and %z will format this information (respectively). If the information is not available, and %Z or %z are contained in fmt , os.setstate(ios_base::failbit) shall be called. %a The locale's abbreviated weekday name. If the value does not contain a valid weekday , setstate(ios::failbit) is called. %A The locale's full weekday name. If the value does not contain a valid weekday , setstate(ios::failbit) is called. %b The locale's abbreviated month name. If the value does not contain a valid month , setstate(ios::failbit) is called. %B The locale's full month name. If the value does not contain a valid month , setstate(ios::failbit) is called. %c The locale's date and time representation. The modified command %Ec produces the locale's alternate date and time representation. %C The year divided by 100 using floored division. If the result is a single decimal digit, it is prefixed with 0 . The modified command %EC produces the locale's alternative representation of the century. %d The day of month as a decimal number. If the result is a single decimal digit, it is prefixed with 0 . The modified command %Od produces the locale's alternative representation. %D Equivalent to %m/%d/%y . %e The day of month as a decimal number. If the result is a single decimal digit, it is prefixed with a space. The modified command %Oe produces the locale's alternative representation. %F Equivalent to %Y-%m-%d . %g The last two decimal digits of the ISO week-based year. If the result is a single digit it is prefixed by 0 . %G The ISO week-based year as a decimal number. If the result is less than four digits it is left-padded with 0 to four digits. %h Equivalent to %b . %H The hour (24-hour clock) as a decimal number. If the result is a single digit, it is prefixed with 0 . The modified command %OH produces the locale's alternative representation. %I The hour (12-hour clock) as a decimal number. If the result is a single digit, it is prefixed with 0 . The modified command %OI produces the locale's alternative representation. %j The day of the year as a decimal number. Jan 1 is 001 . If the result is less than three digits, it is left-padded with 0 to three digits. %m The month as a decimal number. Jan is 01 . If the result is a single digit, it is prefixed with 0 . The modified command %Om produces the locale's alternative representation. %M The minute as a decimal number. If the result is a single digit, it is prefixed with 0 . The modified command %OM produces the locale's alternative representation. %n A new-line character. %p The locale's equivalent of the AM/PM designations associated with a 12-hour clock. %r The locale's 12-hour clock time. %R Equivalent to %H:%M . %S Seconds as a decimal number. If the number of seconds is less than 10, the result is prefixed with 0 . If the precision of the input can not be exactly represented with seconds, then the format is a decimal floating point number with a fixed format and a precision matching that of the precision of the input (or to a microseconds precision if the conversion to floating point decimal seconds can not be made within 18 fractional digits). The character for the decimal point is localized according to the locale. The modified command %OS produces the locale's alternative representation. %t A horizontal-tab character. %T Equivalent to %H:%M:%S . %u The ISO weekday as a decimal number (1-7), where Monday is 1. The modified command %Ou produces the locale's alternative representation. %U The week number of the year as a decimal number. The first Sunday of the year is the first day of week 01 . Days of the same year prior to that are in week 00 . If the result is a single digit, it is prefixed with 0 . The modified command %OU produces the locale's alternative representation. %V The ISO week-based week number as a decimal number. If the result is a single digit, it is prefixed with 0 . The modified command %OV produces the locale's alternative representation. %w The weekday as a decimal number (0-6), where Sunday is 0. The modified command %Ow produces the locale's alternative representation. %W The week number of the year as a decimal number. The first Monday of the year is the first day of week 01 . Days of the same year prior to that are in week 00 . If the result is a single digit, it is prefixed with 0 . The modified command %OW produces the locale's alternative representation. %x The locale's date representation. The modified command %Ex produces the locale's alternate date representation. %X The locale's time representation. The modified command %EX produces the locale's alternate time representation. %y The last two decimal digits of the year. If the result is a single digit it is prefixed by 0 . %Y The year as a decimal number. If the result is less than four digits it is left-padded with 0 to four digits. %z The offset from UTC in the ISO 8601 format. For example -0430 refers to 4 hours 30 minutes behind UTC. If the offset is zero, +0000 is used. The modified commands %Ez and %Oz insert a : between the hours and minutes: -04:30 . If the offset information is not available, setstate(ios_base::failbit) shall be called. %Z The time zone abbreviation. If the time zone abbreviation is not available, setstate(ios_base::failbit) shall be called. %% A % character. Back to TOC

Add a new section 23.17.9 Parsing [time.parse]:

23.17.9 Parsing [time.parse] Each parse overload specified in this section calls from_stream unqualified, so as to enable argument dependent lookup ([basic.lookup.argdep]). template <class charT, class traits, class Alloc, class Parsable> unspecified parse(const basic_string<charT, traits, Alloc>& fmt, Parsable& tp); Remarks: This function shall not participate in overload resolution unless from_stream(declval<basic_istream<charT, traits>&>(), fmt.c_str(), tp) is a valid expression. Returns: A manipulator that when extracted from a basic_istream<charT, traits> is calls from_stream(is, fmt.c_str(), tp) . template <class charT, class traits, class Alloc, class Parsable> unspecified parse(const basic_string<charT, traits, Alloc>& fmt, Parsable& tp, basic_string<charT, traits, Alloc>& abbrev); Remarks: This function shall not participate in overload resolution unless from_stream(declval<basic_istream<charT, traits>&>(), fmt.c_str(), tp, &abbrev) is a valid expression. Returns: A manipulator that when extracted from a basic_istream<charT, traits> is calls from_stream(is, fmt.c_str(), tp, &abbrev) . template <class charT, class traits, class Alloc, class Parsable> unspecified parse(const basic_string<charT, traits, Alloc>& fmt, Parsable& tp, minutes& offset); Remarks: This function shall not participate in overload resolution unless from_stream(declval<basic_istream<charT, traits>&>(), fmt.c_str(), tp, nullptr, &offset) is a valid expression. Returns: A manipulator that when extracted from a basic_istream<charT, traits> is calls from_stream(is, fmt.c_str(), tp, nullptr, &offset) . template <class charT, class traits, class Alloc, class Parsable> unspecified parse(const basic_string<charT, traits, Alloc>& fmt, Parsable& tp, basic_string<charT, traits, Alloc>& abbrev, minutes& offset); Remarks: This function shall not participate in overload resolution unless from_stream(declval<basic_istream<charT, traits>&>(), fmt.c_str(), tp, &abbrev, &offset) is a valid expression. Returns: A manipulator that when extracted from a basic_istream<charT, traits> is calls from_stream(is, fmt.c_str(), tp, &abbrev, &offset) . All from_stream overloads behave as an unformatted input function, except that they have an unspecified effect on the value returned by subsequent calls to basic_istream<>::gcount() . Each overload takes a format string containing ordinary characters and flags which have special meaning. Each flag begins with a % . Some flags can be modified by E or O . During parsing each flag interprets characters as parts of date and time type according to the table below. Some flags can be modified by a width parameter given as a positive decimal integer called out as N below which governs how many characters are parsed from the stream in interpreting the flag. All characters in the format string which are not represented in the table below, except for white space, are parsed unchanged from the stream. A white space character matches zero or more white space characters in the input stream. If the from_stream overload fails to parse everything specified by the format string, or if insufficient information is parsed to specify a complete duration, time point, or calendrical data structure, setstate(ios_base::failbit) is called on the basic_istream . %a The locale's full or abbreviated case-insensitive weekday name. %A Equivalent to %a . %b The locale's full or abbreviated case-insensitive month name. %B Equivalent to %b . %c The locale's date and time representation. The modified command %Ec interprets the locale's alternate date and time representation. %C The century as a decimal number. The modified command %NC specifies the maximum number of characters to read. If N is not specified, the default is 2. Leading zeroes are permitted but not required. The modified commands %EC and %OC interpret the locale's alternative representation of the century. %d The day of the month as a decimal number. The modified command %Nd specifies the maximum number of characters to read. If N is not specified, the default is 2. Leading zeroes are permitted but not required. The modified command %Ed interprets the locale's alternative representation of the day of the month. %D Equivalent to %m/%d/%y . %e Equivalent to %d and can be modified like %d . %F Equivalent to %Y-%m-%d . If modified with a width N , the width is applied to only %Y . %g The last two decimal digits of the ISO week-based year. The modified command %Ng specifies the maximum number of characters to read. If N is not specified, the default is 2. Leading zeroes are permitted but not required. %G The ISO week-based year as a decimal number. The modified command %NG specifies the maximum number of characters to read. If N is not specified, the default is 4. Leading zeroes are permitted but not required. %h Equivalent to %b . %H The hour (24-hour clock) as a decimal number. The modified command %NH specifies the maximum number of characters to read. If N is not specified, the default is 2. Leading zeroes are permitted but not required. The modified command %OH interprets the locale's alternative representation. %I The hour (12-hour clock) as a decimal number. The modified command %NI specifies the maximum number of characters to read. If N is not specified, the default is 2. Leading zeroes are permitted but not required. %j The day of the year as a decimal number. Jan 1 is 1 . The modified command %Nj specifies the maximum number of characters to read. If N is not specified, the default is 3. Leading zeroes are permitted but not required. %m The month as a decimal number. Jan is 1 . The modified command %Nm specifies the maximum number of characters to read. If N is not specified, the default is 2. Leading zeroes are permitted but not required. The modified command %Om interprets the locale's alternative representation. %M The minutes as a decimal number. The modified command %NM specifies the maximum number of characters to read. If N is not specified, the default is 2. Leading zeroes are permitted but not required. The modified command %OM interprets the locale's alternative representation. %n Matches one white space character. [Note: %n , %t and a space, can be combined to match a wide range of white-space patterns. For example "%n " matches one or more white space characters, and "%n%t%t" matches one to three white space characters. — end note] %p The locale's equivalent of the AM/PM designations associated with a 12-hour clock. The command %I must precede %p in the format string. %r The locale's 12-hour clock time. %R Equivalent to %H:%M . %S The seconds as a decimal number. The modified command %NS specifies the maximum number of characters to read. If N is not specified, the default is 2 if the input time has a