次の方法で共有


nonexistent_local_time クラス

この例外は、local_time を存在しない sys_time に変換しようとしたときにスローされます。

構文

class nonexistent_local_time : public runtime_error; // C++20

解説

春の標準時間から夏時間への移行中、時計は基本的に 1 時間を失います。 これは、夏時間への移行によって 1 時間増えるように思われるため、混乱を招く可能性があります。 "夏時間への切り替え" で 1 時間進めることで、移行後の 1 時間は実質的に削除されます。 ニューヨークで夏時間を変更することについて考えます。これは、3 月の第 2 日曜日に午前 2 時に行われます。 午前 2 時に、時計は夏時間に移行し、午前 3 時 00 分になります。 たとえば、変換される local_time が午前 2 時 30 分の場合、その時間は "削除" された期間に含まれるので、"存在しない" 状態になります。

次の例は、存在しない時間変換エラーを示しています。 この例では、ニューヨークの夏時間の開始時刻は午前 2 時です。 変換される時刻は午前 2 時 30 分です。 これは、標準時間から夏時間への移行によって削除される時間内に発生します。 そのため、nonexistent_local_time 例外がスローされます。

例: nonexistent_local_time

#include <chrono>
#include <iostream>

using namespace std::chrono;
    
int main()
{
    try
    {
        // The following will throw an exception because the local time being converted is during
        // the hour that is "removed" when the clock advances an hour for daylight saving time.
        auto zt = zoned_time{"America/New_York", local_days{Sunday[2]/March/2016} + 2h + 30min};
    } catch (const nonexistent_local_time& e)
    {
        std::cout << e.what() << '\n';
    }
    return 0;
}
2016-03-13 02:30:00 is in a gap between
2016-03-13 02:00:00 EST and
2016-03-13 03:00:00 EDT which are both equivalent to
2016-03-13 07:00:00 UTC

メンバー

名前 説明
コンストラクター nonexistent_local_time を構築します。
what 存在しない時刻を説明する文字列を取得します。

必要条件

ヘッダー:<chrono> (C++20 以降)

名前空間std::chrono:

コンパイラ オプション:/std:c++latest

Constructor

nonexistent_local_time を構築します。

template<class Duration>
nonexistent_local_time(const local_time<Duration>& tp, const local_info& i);

パラメーター

tp
変換に失敗した local_time。

i
試行された変換に関する情報。 詳細については、local_info を参照してください。

解説

通常、この例外は作成されません。 これは、local_timesys_time に変換する関数によってスローされます。

what

時刻が存在しない理由を説明する文字列を取得します。

[[nodiscard]] virtual const char* what() const noexcept;

戻り値

時刻が存在しない理由を説明する文字列。 次に例を示します。

2016-03-13 02:30:00 is in a gap between
2016-03-13 02:00:00 EST and
2016-03-13 03:00:00 EDT which are both equivalent to
2016-03-13 07:00:00 UTC

関連項目

<chrono>
to_sys
ambiguous_local_time
ヘッダー ファイル リファレンス