<!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>Example Documentation</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> </head><body bgcolor="#ffffff"> <!-- Generated by Doxygen 1.2.17 --> <hr><h1>time_periods.cpp</h1> Demonstrate some simple uses of time periods. <p> <div class="fragment"><pre><font class="comment">//Some simple examples of constructing and calculating with times</font> <font class="comment">//Returns:</font> <font class="comment">//[2002-Feb-01 00:00:00/2002-Feb-01 23:59:59.999999999] contains 2002-Feb-01 03:00:05</font> <font class="comment">//[2002-Feb-01 00:00:00/2002-Feb-01 23:59:59.999999999] intersected with</font> <font class="comment">//[2002-Feb-01 00:00:00/2002-Feb-01 03:00:04.999999999] is </font> <font class="comment">//[2002-Feb-01 00:00:00/2002-Feb-01 03:00:04.999999999]</font> <font class="preprocessor">#include "boost/date_time/posix_time/posix_time.hpp"</font> <font class="preprocessor">#include <iostream></font> <font class="keyword">using</font> <font class="keyword">namespace </font>boost::posix_time; using namespace boost::gregorian; <font class="comment">//Create a simple period class to contain all the times in a day</font> class day_period : <font class="keyword">public</font> time_period { <font class="keyword">public</font>: day_period(date d) : time_period(ptime(d),<font class="comment">//midnight</font> ptime(d,hours(24))) {} }; <font class="keywordtype">int</font> main() { date d(2002,Feb,1); <font class="comment">//an arbitrary date</font> <font class="comment">//a period that represents a day </font> day_period dp(d); ptime t(d, hours(3)+seconds(5)); <font class="comment">//an arbitray time on that day</font> <font class="keywordflow">if</font> (dp.contains(t)) { std::cout << to_simple_string(dp) << <font class="stringliteral">" contains "</font> << to_simple_string(t) << std::endl; } <font class="comment">//a period that represents part of the day</font> time_period part_of_day(ptime(d, hours(0)), t); <font class="comment">//intersect the 2 periods and print the results</font> <font class="keywordflow">if</font> (part_of_day.intersects(dp)) { time_period result = part_of_day.intersection(dp); std::cout << to_simple_string(dp) << <font class="stringliteral">" intersected with\n"</font> << to_simple_string(part_of_day) << <font class="stringliteral">" is \n"</font> << to_simple_string(result) << std::endl; } <font class="keywordflow">return</font> 0; } </pre></div><hr><address><small> Generated Thu Sep 5 05:52:10 2002 by Doxygen for CrystalClear Software © 2000-2002</small></address> </body> </html>