Home | Libraries | People | FAQ | More |
boost::date_time::period — Provides generalized period type useful in date-time systems.
template<typename point_rep, typename duration_rep> class period { public: // types typedef point_rep point_type; typedef duration_rep duration_type; // construct/copy/destruct period(point_rep, point_rep); period(point_rep, duration_rep); // public member functions point_rep begin() const; point_rep end() const; point_rep last() const; duration_rep length() const; bool is_null() const; bool operator==(const period &) const; bool operator<(const period &) const; void shift(const duration_rep &) ; bool contains(const point_rep &) const; bool contains(const period &) const; bool intersects(const period &) const; bool is_adjacent(const period &) const; bool is_before(const point_rep &) const; bool is_after(const point_rep &) const; period intersection(const period &) const; period merge(const period &) const; period span(const period &) const; };
This template uses a class to represent a time point within the period and another class to represent a duration. As a result, this class is not appropriate for use when the number and duration representation are the same (eg: in the regular number domain).
A period can be specified by providing either the begining point and a duration or the begining point and the end point( end is NOT part of the period but 1 unit past it. A period will be "invalid" if either end_point <= begin_point or the given duration is <= 0. Any valid period will return false for is_null().
Zero length periods are also considered invalid. Zero length periods are periods where the begining and end points are the same, or, the given duration is zero. For a zero length period, the last point will be one unit less than the begining point.
In the case that the begin and last are the same, the period has a length of one unit.
The best way to handle periods is usually to provide a begining point and a duration. So, day1 + 7 days is a week period which includes all of the first day and 6 more days (eg: Sun to Sat).
period
public member functionspoint_rep begin() const;
point_rep end() const;
point_rep last() const;
duration_rep length() const;
bool is_null() const;
bool operator==(const period & rhs) const;
bool operator<(const period & rhs) const;
void shift(const duration_rep & d) ;
bool contains(const point_rep & point) const;
bool contains(const period & other) const;
bool intersects(const period & other) const;
bool is_adjacent(const period & other) const;
bool is_before(const point_rep & point) const;
bool is_after(const point_rep & point) const;
period intersection(const period & other) const;
period merge(const period & other) const;
period span(const period & other) const;
Combines two periods and any gap between them such that start = min(p1.start, p2.start) end = max(p1.end , p2.end)
[---p1---) [---p2---) result: [-----------p3----------) *
Copyright © 2001-2005 CrystalClear Software, Inc |