|
| 1 | +--- |
| 2 | +title: std::chrono::ambiguous_local_time |
| 3 | +cppdoc: |
| 4 | + keys: ["cpp.chrono.ambiguous_local_time"] |
| 5 | + revision: |
| 6 | + since: C++20 |
| 7 | +--- |
| 8 | + |
| 9 | +import { CppHeader } from "@components/header"; |
| 10 | +import { Decl, DeclDoc } from "@components/decl-doc"; |
| 11 | +import { Desc, DescList } from "@components/desc-list"; |
| 12 | +import { ParamDoc, ParamDocList } from "@components/param-doc"; |
| 13 | +import Missing from "@components/Missing.astro"; |
| 14 | +import { Revision, RevisionBlock } from "@components/revision"; |
| 15 | + |
| 16 | +Defined in header <CppHeader name="chrono" />. |
| 17 | + |
| 18 | +<DeclDoc> |
| 19 | + <Decl slot="decl"> |
| 20 | + <RevisionBlock since="C++20" noborder> |
| 21 | + ```cpp |
| 22 | + class ambiguous_local_time; |
| 23 | + ``` |
| 24 | + </RevisionBlock> |
| 25 | + </Decl> |
| 26 | + |
| 27 | + 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`). |
| 28 | + |
| 29 | + 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>). |
| 30 | +</DeclDoc> |
| 31 | + |
| 32 | +## Member functions |
| 33 | + |
| 34 | +<DescList> |
| 35 | + <Desc kind="constructor"> |
| 36 | + <Fragment slot="item">`(constructor)`</Fragment> |
| 37 | + constructs the exception object |
| 38 | + </Desc> |
| 39 | + <Desc kind="function"> |
| 40 | + <Fragment slot="item">`operator=`</Fragment> |
| 41 | + replaces the exception object |
| 42 | + </Desc> |
| 43 | + <Desc kind="function"> |
| 44 | + <Fragment slot="item">`what`</Fragment> |
| 45 | + returns the explanatory string |
| 46 | + </Desc> |
| 47 | +</DescList> |
| 48 | + |
| 49 | +## std::chrono::ambiguous_local_time::ambiguous_local_time |
| 50 | + |
| 51 | +<DeclDoc id={1}> |
| 52 | + <Decl slot="decl"> |
| 53 | + <RevisionBlock since="C++20" noborder> |
| 54 | + ```cpp |
| 55 | + template< class Duration > |
| 56 | + ambiguous_local_time( const std::chrono::local_time<Duration>& tp, |
| 57 | + const std::chrono::local_info& i ); |
| 58 | + ``` |
| 59 | + </RevisionBlock> |
| 60 | + </Decl> |
| 61 | + |
| 62 | + The explanatory string returned by `what()` is equivalent to that produced by `os.str()` after the following code: |
| 63 | + |
| 64 | + ```cpp |
| 65 | + std::ostringstream os; |
| 66 | + os << tp << " is ambiguous. It could be\n" |
| 67 | + << tp << ' ' << i.first.abbrev << " == " |
| 68 | + << tp - i.first.offset << " UTC or\n" |
| 69 | + << tp << ' ' << i.second.abbrev << " == " |
| 70 | + << tp - i.second.offset << " UTC"; |
| 71 | + ``` |
| 72 | + |
| 73 | + The behavior is undefined if `i.result != std::chrono::local_info::ambiguous`. |
| 74 | +</DeclDoc> |
| 75 | + |
| 76 | +<DeclDoc id={2}> |
| 77 | + <Decl slot="decl"> |
| 78 | + <RevisionBlock since="C++20" noborder> |
| 79 | + ```cpp |
| 80 | + ambiguous_local_time( const ambiguous_local_time& other ) noexcept; |
| 81 | + ``` |
| 82 | + </RevisionBlock> |
| 83 | + </Decl> |
| 84 | + |
| 85 | + Copy constructor. If `*this` and `other` both have dynamic type `std::chrono::ambiguous_local_time` then `std::strcmp(what(), other.what()) == 0`. |
| 86 | +</DeclDoc> |
| 87 | + |
| 88 | +### Parameters |
| 89 | + |
| 90 | +<ParamDocList> |
| 91 | + <ParamDoc name="tp"> |
| 92 | + the time point for which conversion was attempted |
| 93 | + </ParamDoc> |
| 94 | + <ParamDoc name="i"> |
| 95 | + a <Missing>`std::chrono::local_info`</Missing> describing the result of the conversion attempt |
| 96 | + </ParamDoc> |
| 97 | + <ParamDoc name="other"> |
| 98 | + another `ambiguous_local_time` to copy |
| 99 | + </ParamDoc> |
| 100 | +</ParamDocList> |
| 101 | + |
| 102 | +### Exceptions |
| 103 | + |
| 104 | +May throw <Missing>`std::bad_alloc`</Missing>. |
| 105 | + |
| 106 | +### Notes |
| 107 | + |
| 108 | +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. |
| 109 | + |
| 110 | +## std::chrono::ambiguous_local_time::operator= |
| 111 | + |
| 112 | +<DeclDoc> |
| 113 | + <Decl slot="decl"> |
| 114 | + <RevisionBlock since="C++20" noborder> |
| 115 | + ```cpp |
| 116 | + ambiguous_local_time& operator=( const ambiguous_local_time& other ) noexcept; |
| 117 | + ``` |
| 118 | + </RevisionBlock> |
| 119 | + </Decl> |
| 120 | + |
| 121 | + 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. |
| 122 | +</DeclDoc> |
| 123 | + |
| 124 | +### Parameters |
| 125 | + |
| 126 | +<ParamDocList> |
| 127 | + <ParamDoc name="other"> |
| 128 | + another exception object to assign with |
| 129 | + </ParamDoc> |
| 130 | +</ParamDocList> |
| 131 | + |
| 132 | +### Return value |
| 133 | + |
| 134 | +`*this` |
| 135 | + |
| 136 | +## std::chrono::ambiguous_local_time::what |
| 137 | + |
| 138 | +<DeclDoc> |
| 139 | + <Decl slot="decl"> |
| 140 | + <RevisionBlock since="C++20" noborder> |
| 141 | + ```cpp |
| 142 | + virtual const char* what() const noexcept; |
| 143 | + ``` |
| 144 | + </RevisionBlock> |
| 145 | + </Decl> |
| 146 | + |
| 147 | + Returns the explanatory string. |
| 148 | +</DeclDoc> |
| 149 | + |
| 150 | +### Parameters |
| 151 | + |
| 152 | +(none) |
| 153 | + |
| 154 | +### Return value |
| 155 | + |
| 156 | +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. |
| 157 | + |
| 158 | +### Notes |
| 159 | + |
| 160 | +Implementations are allowed but not required to override `what()`. |
| 161 | + |
| 162 | +## Inherited from std::runtime_error |
| 163 | + |
| 164 | +Inherited from <Missing>`std::exception`</Missing>. |
| 165 | + |
| 166 | +### Member functions |
| 167 | + |
| 168 | +<DescList> |
| 169 | + <Desc kind="virtual function"> |
| 170 | + <Fragment slot="item">`what`</Fragment> |
| 171 | + returns an explanatory string |
| 172 | + </Desc> |
| 173 | +</DescList> |
| 174 | + |
| 175 | +## See also |
| 176 | + |
| 177 | +<DescList> |
| 178 | + <Desc kind="class" autorevSince="C++20"> |
| 179 | + <Fragment slot="item"> |
| 180 | + <RevisionBlock noborder since="C++20" dir="v"><Missing>`nonexistent_local_time`</Missing></RevisionBlock> |
| 181 | + </Fragment> |
| 182 | + exception thrown to report that a local time is nonexistent |
| 183 | + </Desc> |
| 184 | +</DescList> |
0 commit comments