# posix_time::time_duration

Time Duration Documentation

## Introduction

`boost::posix_time::time_duration` クラスは時間の長さを確実に表現できる基底型である。 時間長(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
``````

``````#include "boost/date_time/posix_time/posix_time.hpp" //全ての型とI/Oを含む
``````

もしくは

``````#include "boost/date_time/posix_time/posix_time_types.hpp" //型のみでI/Oは含まない
``````

## Construction

Syntax Description Example
`time_duration(hours,minutes,seconds,fractional_seconds)` 数値から時間長(duration)を生成する `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);`
`milliseconds(long)` ミリ秒単位で生成 `time_duration td = milliseconds(3);`
`microseconds(long)` マイクロ秒単位で生成 `time_duration td = microseconds(3);`
`nanoseconds(long)` ナノ秒単位で生成 `time_duration td = nanoseconds(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()` 時間長(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);`