mirror of
https://github.com/boostorg/date_time.git
synced 2026-01-30 07:42:57 +00:00
208 lines
8.6 KiB
HTML
208 lines
8.6 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
|
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
|
|
<title>gregorian::date_period Documentation</title>
|
|
<link href="doxygen.css" rel="stylesheet" type="text/css">
|
|
</head>
|
|
|
|
<body>
|
|
<a href="../../../index.htm">
|
|
<img align="left" src="../../../c++boost.gif" alt="C++ Boost">
|
|
</a>
|
|
<h1>gregorian::date_period</h1>
|
|
<p> </p>
|
|
<hr>
|
|
<p>
|
|
<p>
|
|
<a href="index.html">Overall Index</a> --
|
|
<a href="gregorian.html">Gregorian Index</a> --
|
|
<a href="posix_time.html">Posix Time Index</a>
|
|
<p>
|
|
<font class="bold">Date Period Documentation</font>
|
|
<p>
|
|
<a href="class_date_period.html#header">Header</a> --
|
|
<a href="class_date_period.html#construct">Construction</a> --
|
|
<a href="class_date_period.html#accessors">Accessors</a> --
|
|
<a href="class_date_period.html#conversiontostring">Conversion To String</a> --
|
|
<a href="class_date_period.html#operators">Operators</a> --
|
|
<p>
|
|
<h2><a name="intro">Introduction</a></h2>
|
|
|
|
<p>
|
|
The class boost::gregorian::date_period provides direct representation
|
|
for ranges between two dates. Periods provide the ability to simplify
|
|
some types of calculations by simplifying the conditional logic of the
|
|
program. For example, testing if a date is within an irregular
|
|
schedule such as a weekend or holiday can be accomplished using
|
|
collections of date periods. This is facilitated by several methods
|
|
that allow evaluation if a date_period intersects with another date
|
|
period, and to generate the period resulting from the intersection.
|
|
The <a href="exp-period_calc.html">period calculation
|
|
example</a> provides an example of this.
|
|
|
|
|
|
<p>
|
|
Date periods used in combination with infinity values have the ability
|
|
to represent complex concepts such as 'until further notice'.
|
|
<p>
|
|
<p>
|
|
<p>
|
|
<p>
|
|
<h2><a name="header">Header</a></h2>
|
|
<pre>
|
|
#include "boost/date_time/gregorian/gregorian.hpp" //include all types plus i/o
|
|
or
|
|
#include "boost/date_time/gregorian/gregorian_types.hpp" //no i/o just types
|
|
</pre>
|
|
|
|
<p>
|
|
<h2><a name="construct">Construction</a></h2>
|
|
<p>
|
|
<table border=1 cellspacing=3 cellpadding=3>
|
|
<tr><td><b>Syntax</b></td><td><b>Description</b></td><td><b>Example</b></td></tr>
|
|
<tr><td class="nowrap">date_period(date begin, date end)</td>
|
|
<td>
|
|
Create a period as [begin, end). If last is <= begin then
|
|
the period will be defined as null.
|
|
</td>
|
|
<td>date_period dp(date(2002,Jan,10), date(2002,Jan,12));</td></tr>
|
|
<tr><td class="nowrap">date_period(date start, date_duration len)</td>
|
|
<td>
|
|
Create a period as [begin, begin+len). If len is <= zero then
|
|
the period will be defined as null.
|
|
</td>
|
|
<td>date_period dp(date(2002,Jan,10), date_duration(2));</td></tr>
|
|
<tr><td class="nowrap">date_period(date_period rhs)</td>
|
|
<td>Copy constructor</td>
|
|
<td>date_period dp1(dp)</td></tr>
|
|
|
|
</table>
|
|
|
|
<p>
|
|
|
|
<p>
|
|
|
|
<h2><a name="accessors">Accessors</a></h2>
|
|
|
|
<p>
|
|
<table border=1 cellspacing=3 cellpadding=3>
|
|
<tr><td><b>Syntax</b></td><td><b>Description</b></td><td><b>Example</b></td></tr>
|
|
<tr><td>date <font class="func">begin</font>() const</td>
|
|
<td>Return first day of period.</td>
|
|
<td>date_period dp(date(2002,Jan,1), date(2002,Jan,10));<br>
|
|
dp.begin() --> 2002-Jan-01</td></tr>
|
|
<tr><td>date <font class="func">last</font>() const</td>
|
|
<td>Return last date in the period</td>
|
|
<td>date_period dp(date(2002,Jan,1), date(2002,Jan,10));<br>
|
|
dp.last() --> 2002-Jan-09</td></tr>
|
|
<tr><td>date <font class="func">end</font>() const</td>
|
|
<td>Return one past the last in period</td>
|
|
<td>date_period dp(date(2002,Jan,1), date(2002,Jan,10));<br>
|
|
dp.end() --> 2002-Jan-10</td></tr>
|
|
<tr><td>date_duration <font class="func">length</font>() const</td>
|
|
<td>Return the length of the date_period</td>
|
|
<td>date_period dp(date(2002,Jan,1), date_duration(2));<br>
|
|
dp.length() --> 2</td></tr>
|
|
<tr><td>bool <font class="func">is_null</font>() const</td>
|
|
<td>True if period is not well formed. eg: start less than end </td>
|
|
<td>date_period dp(date(2002,Jan,10), date(2002,Jan,1));<br>
|
|
dp.begin() --> true</td></tr>
|
|
<tr><td>bool <font class="func">contains</font>(date) const</td>
|
|
<td>True if date is within the period</td>
|
|
<td>date_period dp(date(2002,Jan,1), date(2002,Jan,10));<br>
|
|
dp.contains(date(2002,Jan,2)) --> true</td></tr>
|
|
<tr><td>bool <font class="func">contains</font>(date_period) const</td>
|
|
<td>True if date period is within the period</td>
|
|
<td>date_period dp1(date(2002,Jan,1), date(2002,Jan,10));<br>
|
|
date_period dp2(date(2002,Jan,2), date(2002,Jan,3));<br>
|
|
dp1.contains(dp2) --> true<br>
|
|
dp2.contains(dp1) --> false</td></tr>
|
|
<tr><td>bool <font class="func">intersects</font>(date_period) const</td>
|
|
<td>True if periods overlap</td>
|
|
<td>date_period dp1(date(2002,Jan,1), date(2002,Jan,10));<br>
|
|
date_period dp2(date(2002,Jan,2), date(2002,Jan,3));<br>
|
|
dp2.intersects(dp1) --> true</td></tr>
|
|
<tr><td>date_period <font class="func">intersection</font>(date_period) const</td>
|
|
<td>Calculate the intersection of 2 periods. Null if no intersection.</td>
|
|
<td class="nowrap">date_period dp1(date(2002,Jan,1), date(2002,Jan,10));<br>
|
|
date_period dp2(date(2002,Jan,2), date(2002,Jan,3));<br>
|
|
dp2.intersection(dp1) --> dp2</td></tr>
|
|
<tr><td>date_period <font class="func">is_adjacent</font>(date_period) const</td>
|
|
<td>Check if two periods are adjacent, but not overlapping.</td>
|
|
<td>date_period dp1(date(2002,Jan,1), date(2002,Jan,3));<br>
|
|
date_period dp2(date(2002,Jan,3), date(2002,Jan,10));<br>
|
|
dp2.is_adjacent(dp1) --> true</td></tr>
|
|
<tr><td>date_period <font class="func">is_after</font>(date) const</td>
|
|
<td>Determine the period is after a given date.</td>
|
|
<td>date_period dp1(date(2002,Jan,10), date(2002,Jan,30));<br>
|
|
date d(2002,Jan,3);<br>
|
|
dp1.is_after(d) --> true</td></tr>
|
|
<tr><td>date_period <font class="func">is_before</font>(date) const</td>
|
|
<td>Determine the period is before a given date.</td>
|
|
<td>date_period dp1(date(2002,Jan,1), date(2002,Jan,3));<br>
|
|
date d(2002,Jan,10);<br>
|
|
dp1.is_before(d) --> true</td></tr>
|
|
<tr><td>date_period <font class="func">merge</font>(date_period) const</td>
|
|
<td>Returns union of two periods. Null if no intersection.</td>
|
|
<td>date_period dp1(date(2002,Jan,1), date(2002,Jan,10));<br>
|
|
date_period dp2(date(2002,Jan,9), date(2002,Jan,31));<br>
|
|
dp2.merge(dp1) --> 2002-Jan-01/2002-Jan-31</td></tr>
|
|
<tr><td>date_period <font class="func">span</font>(date_period) const</td>
|
|
<td>Combines two periods and any gap between them such that start = min(p1.start, p2.start) and end = max(p1.end , p2.end)
|
|
</td>
|
|
<td class="nowrap">date_period dp1(date(2002,Jan,1), date(2002,Jan,5));<br>
|
|
date_period dp2(date(2002,Jan,9), date(2002,Jan,31));<br>
|
|
dp2.hull(dp1) --> 2002-Jan-01/2002-Jan-31</td></tr>
|
|
<tr><td>date_period <font class="func">shift</font>(date_duration)</td>
|
|
<td>Add duration to both start and end.</td>
|
|
<td class="nowrap">date_period dp1(date(2002,Jan,1), date(2002,Jan,10));<br>
|
|
dp1.shift(date_duration(1)); --> 2002-Jan-02/2002-Jan-11</td></tr>
|
|
|
|
</table>
|
|
<p>
|
|
<h2><a name="conversiontostring">Conversion To String</a></h2>
|
|
|
|
<p>
|
|
<table border=1 cellspacing=3 cellpadding=3>
|
|
<tr><td><b>Syntax</b></td><td><b>Description</b></td><td><b>Example</b></td></tr>
|
|
<tr><td>std::string <font class="func">to_simple_string</font>(date_period dp)</td>
|
|
<td>To [YYYY-mmm-DD/YYYY-mmm-DD] string where mmm is 3 char month name.</td>
|
|
<td>[2002-Jan-01/2002-Jan-31]</td></tr>
|
|
|
|
</table>
|
|
<p>
|
|
|
|
|
|
<h2><a name="operators">Operators</a></h2>
|
|
|
|
|
|
<p>
|
|
<table border=1 cellspacing=3 cellpadding=3>
|
|
<tr><td><b>Syntax</b></td><td><b>Description</b></td><td><b>Example</b></td></tr>
|
|
<tr><td>operator<<</td>
|
|
<td>ostream operator for date_period. Uses facet to format time points. Typical output: [2002-Jan-01/2002-Jan-31].</td>
|
|
<td>std::cout << dp << std::endl;</td></tr>
|
|
<tr><td>operator==, operator!=,<br> operator>, operator<
|
|
<td>A full complement of comparison operators</td>
|
|
<td>dp1 == dp2, etc</td></tr>
|
|
<tr><td>operator<</td>
|
|
<td>True if dp1.end() less than dp2.begin()</td>
|
|
<td>dp1 < dp2, etc</td></tr>
|
|
<tr><td>operator></td>
|
|
<td>True if dp1.begin() greater than dp2.end()</td>
|
|
<td>dp1 > dp2, etc</td></tr>
|
|
</table>
|
|
|
|
<p>
|
|
|
|
|
|
<hr>
|
|
<address><small>
|
|
<!-- hhmts start -->
|
|
Last modified: Tue Aug 19 06:46:09 MST 2003
|
|
<!-- hhmts end -->
|
|
by <a href="mailto:jeff@crystalclearsoftware.com">Jeff Garland</a> © 2000-2003
|
|
</small></address>
|
|
</body>
|
|
</html>
|
|
|