命名空间
变体
操作

std::chrono::ambiguous_local_time

来自 cppreference.cn
< cpp‎ | chrono
 
 
日期和时间库
时间点
(C++11)
(C++20)
时长
(C++11)
时钟
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
一天中的时间
(C++20)(C++20)
(C++20)(C++20)
(C++20)
日历
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)(C++20)
chrono I/O
(C++20)

时区
(C++20)
(C++20)
(C++20)
(C++20)
ambiguous_local_time
(C++20)
(C++20)
(C++20)
(C++20)
C 风格日期和时间
 
定义于头文件 <chrono>
class ambiguous_local_time;
(自 C++20 起)

定义要作为异常抛出的对象类型,以报告尝试将不明确的 std::chrono::local_time 转换为 std::chrono::sys_time,而未指定 std::chrono::choose (例如 choose::earliestchoose::latest)。

此异常由 std::chrono::time_zone::to_sys 以及调用它的函数(例如,接受 std::chrono::local_timestd::chrono::zoned_time 的构造函数)抛出。

cpp/error/exceptioncpp/error/runtime errorstd-chrono-ambiguous local time-inheritance.svg

继承关系图

内容

[编辑] 成员函数

(构造函数)
构造异常对象
(公有成员函数)
operator=
替换异常对象
(公有成员函数)
what
返回解释性字符串
(公有成员函数)

std::chrono::ambiguous_local_time::ambiguous_local_time

template< class Duration >

ambiguous_local_time( const std::chrono::local_time<Duration>& tp,

                      const std::chrono::local_info& i );
(1) (自 C++20 起)
ambiguous_local_time( const ambiguous_local_time& other ) noexcept;
(2) (自 C++20 起)

构造异常对象。

1)what() 返回的解释性字符串等效于在以下代码之后由 os.str() 生成的字符串
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";
如果 i.result != std::chrono::local_info::ambiguous,则行为未定义。
2) 复制构造函数。如果 *thisother 都具有动态类型 std::chrono::ambiguous_local_time,则 std::strcmp(what(), other.what()) == 0

参数

tp - 尝试转换的时间点
i - 描述转换尝试结果的 std::chrono::local_info
other - 要复制的另一个 ambiguous_local_time

异常

可能抛出 std::bad_alloc

注解

由于不允许复制从 std::exception 派生的标准库类抛出异常,因此该消息通常在内部存储为单独分配的引用计数字符串。

std::chrono::ambiguous_locale_time::operator=

ambiguous_locale_time& operator=( const ambiguous_locale_time& other ) noexcept;
(自 C++20 起)

将内容赋值为 other 的内容。如果 *thisother 都具有动态类型 std::chrono::ambiguous_locale_time,则赋值后 std::strcmp(what(), other.what()) == 0

参数

other - 要赋值的另一个异常对象

返回值

*this

std::chrono::ambiguous_locale_time::what

virtual const char* what() const noexcept;
(自 C++20 起)

返回解释性字符串。

返回值

指向实现定义的空终止字符串的指针,其中包含解释性信息。该字符串适用于转换为 std::wstring 并显示。该指针保证至少在从中获取它的异常对象被销毁之前,或在该异常对象上调用非 const 成员函数(例如,复制赋值运算符)之前有效。

返回的字符串在使用常量求值期间以普通文字编码进行编码。

(自 C++26 起)

注解

允许但非强制实现重写 what()

继承自 std::runtime_error


继承自 std::exception

成员函数

[虚函数]
销毁异常对象
(std::exception 的虚公有成员函数) [编辑]
[虚函数]
返回解释性字符串
(std::exception 的虚公有成员函数) [编辑]

[编辑] 参见

抛出异常以报告本地时间不存在
(类) [编辑]