Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
524 changes: 524 additions & 0 deletions src/content/docs/cpp/library/chrono.mdx

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/content/docs/cpp/library/chrono/_meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
label: Date and time library
184 changes: 184 additions & 0 deletions src/content/docs/cpp/library/chrono/ambiguous_local_time.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
---
title: std::chrono::ambiguous_local_time
cppdoc:
keys: ["cpp.chrono.ambiguous_local_time"]
revision:
since: C++20
---

import { CppHeader } from "@components/header";
import { Decl, DeclDoc } from "@components/decl-doc";
import { Desc, DescList } from "@components/desc-list";
import { ParamDoc, ParamDocList } from "@components/param-doc";
import Missing from "@components/Missing.astro";
import { Revision, RevisionBlock } from "@components/revision";

Defined in header <CppHeader name="chrono" />.

<DeclDoc>
<Decl slot="decl">
<RevisionBlock since="C++20" noborder>
```cpp
class ambiguous_local_time;
```
</RevisionBlock>
</Decl>

Defines a type of object to be thrown as exception to report that an attempt was made to convert an ambiguous <Missing>`std::chrono::local_time`</Missing> to a <Missing>`std::chrono::sys_time`</Missing> without specifying a <Missing>`std::chrono::choose`</Missing> (such as `choose::earliest` or `choose::latest`).

This exception is thrown by <Missing>`std::chrono::time_zone::to_sys`</Missing> and functions that call it (such as the constructors of <Missing>`std::chrono::zoned_time`</Missing> that take a <Missing>`std::chrono::local_time`</Missing>).
</DeclDoc>

## Member functions

<DescList>
<Desc kind="constructor">
<Fragment slot="item">`(constructor)`</Fragment>
constructs the exception object
</Desc>
<Desc kind="function">
<Fragment slot="item">`operator=`</Fragment>
replaces the exception object
</Desc>
<Desc kind="function">
<Fragment slot="item">`what`</Fragment>
returns the explanatory string
</Desc>
</DescList>

## std::chrono::ambiguous_local_time::ambiguous_local_time

<DeclDoc id={1}>
<Decl slot="decl">
<RevisionBlock since="C++20" noborder>
```cpp
template< class Duration >
ambiguous_local_time( const std::chrono::local_time<Duration>& tp,
const std::chrono::local_info& i );
```
</RevisionBlock>
</Decl>

The explanatory string returned by `what()` is equivalent to that produced by `os.str()` after the following code:

```cpp
std::ostringstream os;
os << tp << " is ambiguous. It could be\n"
<< tp << ' ' << i.first.abbrev << " == "
<< tp - i.first.offset << " UTC or\n"
<< tp << ' ' << i.second.abbrev << " == "
<< tp - i.second.offset << " UTC";
```

The behavior is undefined if `i.result != std::chrono::local_info::ambiguous`.
</DeclDoc>

<DeclDoc id={2}>
<Decl slot="decl">
<RevisionBlock since="C++20" noborder>
```cpp
ambiguous_local_time( const ambiguous_local_time& other ) noexcept;
```
</RevisionBlock>
</Decl>

Copy constructor. If `*this` and `other` both have dynamic type `std::chrono::ambiguous_local_time` then `std::strcmp(what(), other.what()) == 0`.
</DeclDoc>

### Parameters

<ParamDocList>
<ParamDoc name="tp">
the time point for which conversion was attempted
</ParamDoc>
<ParamDoc name="i">
a <Missing>`std::chrono::local_info`</Missing> describing the result of the conversion attempt
</ParamDoc>
<ParamDoc name="other">
another `ambiguous_local_time` to copy
</ParamDoc>
</ParamDocList>

### Exceptions

May throw <Missing>`std::bad_alloc`</Missing>.

### Notes

Because copying a standard library class derived from <Missing>`std::exception`</Missing> is not permitted to throw exceptions, this message is typically stored internally as a separately-allocated reference-counted string.

## std::chrono::ambiguous_local_time::operator=

<DeclDoc>
<Decl slot="decl">
<RevisionBlock since="C++20" noborder>
```cpp
ambiguous_local_time& operator=( const ambiguous_local_time& other ) noexcept;
```
</RevisionBlock>
</Decl>

Assigns the contents with those of `other`. If `*this` and `other` both have dynamic type `std::chrono::ambiguous_local_time` then `std::strcmp(what(), other.what()) == 0` after assignment.
</DeclDoc>

### Parameters

<ParamDocList>
<ParamDoc name="other">
another exception object to assign with
</ParamDoc>
</ParamDocList>

### Return value

`*this`

## std::chrono::ambiguous_local_time::what

<DeclDoc>
<Decl slot="decl">
<RevisionBlock since="C++20" noborder>
```cpp
virtual const char* what() const noexcept;
```
</RevisionBlock>
</Decl>

Returns the explanatory string.
</DeclDoc>

### Parameters

(none)

### Return value

Pointer to a null-terminated string with explanatory information. The string is suitable for conversion and display as a <Missing>`std::wstring`</Missing>. The pointer is guaranteed to be valid at least until the exception object from which it is obtained is destroyed, or until a non-const member function (e.g. copy assignment operator) on the exception object is called.

### Notes

Implementations are allowed but not required to override `what()`.

## Inherited from std::runtime_error

Inherited from <Missing>`std::exception`</Missing>.

### Member functions

<DescList>
<Desc kind="virtual function">
<Fragment slot="item">`what`</Fragment>
returns an explanatory string
</Desc>
</DescList>

## See also

<DescList>
<Desc kind="class" autorevSince="C++20">
<Fragment slot="item">
<RevisionBlock noborder since="C++20" dir="v"><Missing>`nonexistent_local_time`</Missing></RevisionBlock>
</Fragment>
exception thrown to report that a local time is nonexistent
</Desc>
</DescList>
49 changes: 49 additions & 0 deletions src/content/docs/cpp/library/chrono/choose.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
title: std::chrono::choose
cppdoc:
keys: ["cpp.chrono.choose"]
revision:
since: C++20
---

import { CppHeader } from "@components/header";
import { Decl, DeclDoc } from "@components/decl-doc";
import { Desc, DescList } from "@components/desc-list";
import Missing from "@components/Missing.astro";
import { Revision, RevisionBlock } from "@components/revision";

Defined in header <CppHeader name="chrono" />.

<DeclDoc>
<Decl slot="decl">
<RevisionBlock since="C++20" noborder>
```cpp
enum class choose {
earliest,
latest
};
```
</RevisionBlock>
</Decl>

The scoped enumeration `choose` can be passed to certain member functions of <Missing>`std::chrono::time_zone`</Missing> and <Missing>`std::chrono::zoned_time`</Missing> to control how ambiguous or nonexistent local times should be resolved. Passing `choose::earliest` causes the earlier time point to be returned, while passing `choose::latest` causes the later time point to be returned. (For nonexistent local times, these two time points are identical.)

If a `choose` is not passed and an ambiguous or nonexistent local time is encountered, a <Missing>`std::chrono::ambiguous_local_time`</Missing> or <Missing>`std::chrono::nonexistent_local_time`</Missing> exception (as applicable) will be thrown.
</DeclDoc>

## See also

<DescList>
<Desc kind="constructor" autorevSince="C++20">
<Fragment slot="item">
<RevisionBlock noborder since="C++20" dir="v"><Missing>`zoned_time::zoned_time`</Missing></RevisionBlock>
</Fragment>
constructs a `zoned_time`
</Desc>
<Desc kind="function" autorevSince="C++20">
<Fragment slot="item">
<RevisionBlock noborder since="C++20" dir="v"><Missing>`time_zone::to_sys`</Missing></RevisionBlock>
</Fragment>
converts a `local_time` in this time zone to a `sys_time`
</Desc>
</DescList>
63 changes: 63 additions & 0 deletions src/content/docs/cpp/library/chrono/clock_cast.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
title: std::chrono::clock_cast
cppdoc:
keys: ["cpp.chrono.clock_cast"]
revision:
since: C++20
---

import { CppHeader } from "@components/header";
import { Decl, DeclDoc } from "@components/decl-doc";
import { Desc, DescList } from "@components/desc-list";
import { ParamDoc, ParamDocList } from "@components/param-doc";
import Missing from "@components/Missing.astro";
import { Revision, RevisionBlock } from "@components/revision";

Defined in header <CppHeader name="chrono" />.

<DeclDoc>
<Decl slot="decl">
<RevisionBlock since="C++20" noborder>
```cpp
template< class Dest, class Source, class Duration >
auto clock_cast( const std::chrono::time_point<Source, Duration>& t );
```
</RevisionBlock>
</Decl>

Converts the time point `t` of a clock `Source` to an equivalent time point of the clock `Dest`, using <Missing>`std::chrono::system_clock`</Missing> and/or <Missing>`std::chrono::utc_clock`</Missing> as intermediaries if necessary.

- If the expression `std::chrono::clock_time_conversion<Dest, Source>{}(t)` is well-formed, returns the result of that expression.
- Otherwise, if at least one of the following two expressions are well-formed, then
- If both expressions are well-formed, the conversion is ambiguous, and the program is ill-formed.
- Otherwise, exactly one of the two expressions is well-formed; the result of that expression is returned.
1. `std::chrono::clock_time_conversion<Dest, std::chrono::system_clock>{}(std::chrono::clock_time_conversion<std::chrono::system_clock, Source>{}(t))`
2. `std::chrono::clock_time_conversion<Dest, std::chrono::utc_clock>{}(std::chrono::clock_time_conversion<std::chrono::utc_clock, Source>{}(t))`
- Otherwise, if at least one of the following two expressions are well-formed, then
- If both expressions are well-formed, the conversion is ambiguous, and the program is ill-formed.
- Otherwise, exactly one of the two expressions is well-formed; the result of that expression is returned.
1. `std::chrono::clock_time_conversion<Dest, std::chrono::utc_clock>{}(std::chrono::clock_time_conversion<std::chrono::utc_clock, std::chrono::system_clock>{}(std::chrono::clock_time_conversion<std::chrono::system_clock, Source>{}(t)))`
2. `std::chrono::clock_time_conversion<Dest, std::chrono::system_clock>{}(std::chrono::clock_time_conversion<std::chrono::system_clock, std::chrono::utc_clock>{}(std::chrono::clock_time_conversion<std::chrono::utc_clock, Source>{}(t)))`
- Otherwise, this function does not participate in overload resolution.
</DeclDoc>

## Return value

The result of the conversion, determined as described above.

## Example

```cpp
// Example code here
```

## See also

<DescList>
<Desc kind="class template" autorevSince="C++20">
<Fragment slot="item">
<RevisionBlock noborder since="C++20" dir="v"><Missing>`clock_time_conversion`</Missing></RevisionBlock>
</Fragment>
traits class defining how to convert time points of one clock to another
</Desc>
</DescList>
Loading
Loading