Overall Index -- Gregorian Index -- Posix Time Index
Time Period Documentation
Header -- Construction -- Accessors -- Conversion To String -- Operators --
The class boost::posix_time::time_period provides direct representation for ranges between two times. Periods provide the ability to simplify some types of caculations by simplifing the conditional logic of the program.
The time periods example provides an example of using time periods.
#include "boost/date_time/posix_time/posix_time.hpp" //include all types plus i/o or #include "boost/date_time/posix_time/posix_time_types.hpp" //no i/o just types
Syntax | Description | Example |
time_period(ptime begin, ptime last) | Create a period as [begin, last). If last is <= begin then the period will be defined as null. | date d(2002,Jan,01); ptime t(d, seconds(10)); //10 sec after midnight time_period tp(t, hours(3)); |
time_period(ptime start, ptime end) | Create a period as [begin, begin+len). If len is <= zero then the period will be defined as null. | date d(2002,Jan,01); ptime t1(d, seconds(10)); //10 sec after midnight ptime t2(d, hours(10)); //10 hours after midnight time_period tp(t1, t2); |
time_period(time_period rhs) | Copy constructor | time_period tp1(tp) |
Syntax | Description | Example |
ptime begin() const | Return first time of period. | date d(2002,Jan,01); ptime t1(d, seconds(10)); //10 sec after midnight ptime t2(d, hours(10)); //10 hours after midnight time_period tp(t1, t2); tp.begin() --> 2002-Jan-01 00:00:10 |
ptime last() const | Return last time in the period | date d(2002,Jan,01); ptime t1(d, seconds(10)); //10 sec after midnight ptime t2(d, hours(10)); //10 hours after midnight time_period tp(t1, t2); tp.last() --> 2002-Jan-01 09:59:59.999999999 |
ptime end() const | Return one past the last in period | date d(2002,Jan,01); ptime t1(d, seconds(10)); //10 sec after midnight ptime t2(d, hours(10)); //10 hours after midnight time_period tp(t1, t2); tp.last() --> 2002-Jan-01 10:00:00 |
bool is_null() const | True if period is not well formed. eg: start less than end | |
bool contains(ptime) const | True if ptime is within the period | date d(2002,Jan,01); ptime t1(d, seconds(10)); //10 sec after midnight ptime t2(d, hours(10)); //10 hours after midnight ptime t3(d, hours(2)); //2 hours after midnight time_period tp(t1, t2); tp.contains(t3) --> true |
bool contains(time_period) const | True if period is within the period | time_period tp1(ptime(d,hours(1)), ptime(d,hours(12))); time_period tp2(ptime(d,hours(2)), ptime(d,hours(4))); tp1.contains(tp2) --> true tp2.contains(tp1) --> false |
bool intersects(time_period) const | True if periods overlap | time_period tp1(ptime(d,hours(1)), ptime(d,hours(12))); time_period tp2(ptime(d,hours(2)), ptime(d,hours(4))); tp2.intersects(tp1) --> true |
time_period intersection(time_period) const | Calculate the intersection of 2 periods. Null if no intersection. | |
time_period merge(time_period) const | Returns union of two periods. Null if no intersection. | |
time_period shift(date_duration) | Add duration to both start and end. |
Syntax | Description | Example |
std::string to_simple_string(time_period dp) | To [YYYY-mmm-DD hh:mm:ss.fffffffff/YYYY-mmm-DD hh:mm:ss.fffffffff] string where mmm is 3 char month name. | [2002-Jan-01 01:25:10.000000001/2002-Jan-31 01:25:10.123456789] |
Syntax | Description | Example |
operator==, operator!=, operator>, operator< | A full complement of comparison operators | tp1 == tp2, etc |
operator< | True if tp1.end() less than tp2.begin() | tp1 < tp2, etc |
operator> | True if tp1.begin() greater than tp2.end() | tp1 > tp2, etc |