nlib
nn::nlib::TimeSpan クラスfinal

時間を表すクラスです。 [詳解]

#include "nn/nlib/DateTime.h"

公開メンバ関数

void Get (int *days, int *seconds, int *milliseconds, int *microseconds) noexcept
 時間を日数,秒,ミリ秒,マイクロ秒の単位に分けて取得します。 [詳解]
 
TimeValue ToTimeValue () const noexcept
 TimeValueオブジェクトに変換します。 [詳解]
 
int ToDays () const noexcept
 時間を日数にして返します。端数は切り捨てられます。
 
int ToHours () const noexcept
 時間を一時間単位の値として返します。端数は切り捨てられます。
 
int64_t ToMinutes () const noexcept
 時間を分数にして返します。端数は切り捨てられます。
 
int64_t ToSeconds () const noexcept
 時間を秒数にして返します。端数は切り捨てられます。
 
int64_t ToMilliSeconds () const noexcept
 時間をミリ秒数にして返します。端数は切り捨てられます。
 
int64_t ToMicroSeconds () const noexcept
 時間をマイクロ秒数にして返します。端数は切り捨てられます。
 
template<class TIMEVAL >
void ToTimeVal (TIMEVAL *tv) const noexcept
 データを秒数とマイクロ秒数に分割して格納します。 [詳解]
 
 TimeSpan (const struct timespec *tm) noexcept
 timespec構造体からオブジェクトを構築します。
 
void ToTimeSpec (struct timespec *tm) const noexcept
 timespec構造体の値に変換します。
 
TimeSpanoperator+= (const TimeSpan &rhs) noexcept
 時間を加算します。
 
TimeSpanoperator-= (const TimeSpan &rhs) noexcept
 時間を減算します。
 
TimeSpanoperator*= (int i) noexcept
 時間をi で乗算します。
 
TimeSpanoperator*= (double d) noexcept
 時間をd で乗算します。
 
void Abs () noexcept
 時間が負である場合には符号を反転します。
 
TimeSpan operator- () const noexcept
 単項演算子です。
 
TimeSpan operator+ () const noexcept
 単項演算子です。
 
コンストラクタ、デストラクタ、及び初期化
constexpr TimeSpan () noexcept
 デフォルトコンストラクタです。 時間を0で初期化します。
 
 TimeSpan (const TimeValue &rhs) noexcept
 TimeValue オブジェクトを用いて初期化します。
 
constexpr TimeSpan (int days) noexcept
 期間として日数を指定して初期化します。 [詳解]
 
constexpr TimeSpan (int days, int seconds) noexcept
 期間として日数と秒を指定して初期化します。 [詳解]
 
constexpr TimeSpan (int days, int seconds, int milliseconds, int microseconds=0) noexcept
 期間として日数,秒,ミリ秒,マイクロ秒を指定して初期化します。 [詳解]
 

詳解

時間を表すクラスです。

説明
100ナノ秒を1単位として64bit整数で時間を表しています。 各種演算子を用いてTimeSpanの加算・減算・比較等を行うことができます。
以下がコード例です。
SUCCEED_IF(e == 0);
dt.ToW3cDtf(w3cdtf);
nlib_printf("Now: %s\n", w3cdtf);
nlib_ns::TimeSpan span(0, 60 * 60 * 10);
dt += span;
dt.ToW3cDtf(w3cdtf);
nlib_printf("10 hours from now: %s\n", w3cdtf);
/*
Output:
Now: 2017-12-26T06:17:48.00Z
10 hours from now: 2017-12-26T16:17:48.00Z
*/
なお、うるう秒は考慮されていません。
各種例:
misc/datetime/datetime.cpp, misc/threading/tls/tls.cpp, msgpack/jsonrpc/jsonrpc.cpp, msgpack/jsonrpc/server.cpp.

DateTime.h97 行目に定義があります。

構築子と解体子

◆ TimeSpan() [1/3]

nn::nlib::TimeSpan::TimeSpan ( int  days)
inlineexplicitnoexcept

期間として日数を指定して初期化します。

引数
[in]days日数

DateTime.h101 行目に定義があります。

◆ TimeSpan() [2/3]

nn::nlib::TimeSpan::TimeSpan ( int  days,
int  seconds 
)
inlinenoexcept

期間として日数と秒を指定して初期化します。

引数
[in]days日数
[in]seconds秒数

DateTime.h103 行目に定義があります。

◆ TimeSpan() [3/3]

nn::nlib::TimeSpan::TimeSpan ( int  days,
int  seconds,
int  milliseconds,
int  microseconds = 0 
)
inlinenoexcept

期間として日数,秒,ミリ秒,マイクロ秒を指定して初期化します。

引数
[in]days日数
[in]seconds
[in]millisecondsミリ秒
[in]microsecondsマイクロ秒

DateTime.h106 行目に定義があります。

関数詳解

◆ Get()

nn::nlib::TimeSpan::Get ( int *  days,
int *  seconds,
int *  milliseconds,
int *  microseconds 
)
noexcept

時間を日数,秒,ミリ秒,マイクロ秒の単位に分けて取得します。

引数
[out]days日数が設定されます。
[out]seconds秒数が設定されます。
[out]millisecondsミリ秒が設定されます。
[out]microsecondsマイクロ秒が設定されます。

◆ ToTimeVal()

template<class TIMEVAL >
nn::nlib::TimeSpan::ToTimeVal ( TIMEVAL *  tv) const
inlinenoexcept

データを秒数とマイクロ秒数に分割して格納します。

引数
[in]tvtv_sec, tv_usecを公開データメンバに持つ構造体
説明
所謂timeval構造体へのポインタを渡して利用します。 tv_sectime_t型、tv_usecint32_t型以上の大きさである必要があります。

DateTime.h124 行目に定義があります。

◆ ToTimeValue()

nn::nlib::TimeSpan::ToTimeValue ( ) const
inlinenoexcept

TimeValueオブジェクトに変換します。

説明
nlib_speep()などのC-APIに値を渡したい場合に利用します。 以下がコード例です。
各種例:
misc/threading/tls/tls.cpp.

DateTime.h112 行目に定義があります。


このクラス詳解は次のファイルから抽出されました: