# posix_time::time_duration

Overall Index -- Gregorian Index -- Posix Time Index

### Time Duration Documentation

Header -- Construction -- Count Based Construction -- Construct from String -- Accessors -- Conversion To String -- Operators

## Introduction

The class boost::posix_time::time_duration the base type reponsible for representing a length of time. A duration can be either positive or negative.
boost::posix_time::time_duration クラスは時間の長さを確実に表現できる基底型である。 時間長(duration)は正あるいは負の値を取り得る。
reponsible は responsible のtypoと思われる

Several small helper classes that derive from a base time_duration, as shown below, to adjust for different resolutions. These classes can shorten code and make the intent clearer.
以下に示すように、異なった分解能を調整するために基底の time_duration から継承するいくつかの小さなヘルパークラスがある。 これらのクラスによって、コードを短く、意図をより明確にすることができる。

例:

      using namespace boost::gregorian;
      using namespace boost::posix_time;

      time_duration td = hours(1) + seconds(10); //01:00:01
      td = hours(1) + nanosec(5); //01:00:00.000000005

## Header

    #include "boost/date_time/posix_time/posix_time.hpp" //include all types plus i/o
    or
    #include "boost/date_time/posix_time/posix_time/posix_time_types.hpp" //no i/o just types

## Construction

Syntax | Description | Example
--- | --- | ---
time_duration(hours,minutes,seconds,fractional_seconds) | Construct ad duration from the counts 数値から時間長(duration)を生成する ad は as のtypo と思われる | time_duration td(1,2,3,9); //1 hr 2 min 3 sec 9 nanoseconds

## Construction By Count

Syntax | Description | Example
--- | --- | ---
hours(long) | 時間単位で生成 | time_duration td = hours(3);
minutes(long) | 分単位で生成 | time_duration td = minutes(3);
seconds(long) | 秒単位で生成 | time_duration td = seconds(3);
millisec(long) | ミリ秒単位で生成 | time_duration td = millisec(3);
nanosec(long) | ナノ秒単位で生成 | time_duration td = nanosec(3);

## Construction From String

Syntax | Description | Example
--- | --- | ---
time_duration duration_from_string(const std::string&) | 区切られた文字列から生成 | std::string ts("23:59:59.000"); time_duraton td(duration_from_string(ts))

## Accessors

Syntax | Description | Example
--- | --- | ---
long hours() const | 時間の部分を取得 | time_duration td(1,2,3); td.hours() --> 1
long minutes() const | 正規化された分の部分を取得 | time_duration td(1,2,3); td.minutes() --> 2
long seconds() const | 秒の部分を取得 | time_duration td(1,2,3); td.hours() --> 3
long fractional_seconds() const | 秒の小数部を取得 | time_duration td(1,2,3, 1000); td.fractional_seconds() --> 1000
bool is_negative() const | 時間長(duration)が負の時 true | time_duration td(-1,0,0); td.is_negative() --> true
time_duration invert_sign() const | 符号を反転させた時間長(duration)を新たに生成 | time_duration td(-1,0,0); td.invert_sign() --> 01:00:00
static gdtl::time_resolutions resolution() | time_duration クラスが表現可能な分解能 | time_duration::resolution() --> nano
boost::int64_t ticks() | Return the raw count of the duration type. 時間長(duration)型の生の数を返す | time_duration td(0,0,0, 1000); td.ticks() --> 1000
static time_duration unit() | 時間長(duration)型の扱える最小単位を返す(1ナノ秒) | time_duration::unit() --> time_duration(0,0,0,1)

## Conversion To String

Syntax | Description | Example
--- | --- | ---
std::string to_simple_string(time_duration) | HH:MM:SS.fffffffff 形式に変換する(fff...部は、秒の小数部が0でないときのみ含まれる) | 10:00:01.123456789
std::string to_iso_string(time_duration) | HHMMSS,fffffffff 形式に変換する | 100001,123456789

## Operators

Syntax | Description | Example
--- | --- | ---
operator==, operator!=, operator>, operator< operator>=, operator<= | サポートする比較演算子 | dd1 == dd2, etc
time_duration operator+(time_duration) const | 時間長(durations)を加算する | time_duration td1(hours(1)+minutes(2)); time_duration td2(seconds(10)); time_duration td3 = td1 + td2;
time_duration operator-(time_duration) const | 時間長(durations)を減算する | time_duration td1(hours(1)+nanosec(2)); time_duration td2 = td1 - minutes(1);