Sophie

Sophie

distrib > Mandriva > 10.0 > i586 > by-pkgid > ef9bad9e14fc2a68cb7c992c11d75f5e > files > 2685

libboost1-devel-1.31.0-1mdk.i586.rpm

<!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 &lt;iostream&gt;</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 &lt;&lt; to_simple_string(dp) &lt;&lt; <font class="stringliteral">" contains "</font>
           &lt;&lt; to_simple_string(t)  &lt;&lt; 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 &lt;&lt; to_simple_string(dp) &lt;&lt; <font class="stringliteral">" intersected with\n"</font>
                &lt;&lt; to_simple_string(part_of_day) &lt;&lt; <font class="stringliteral">" is \n"</font>
           &lt;&lt; to_simple_string(result) &lt;&lt; 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&nbsp;&copy 2000-2002</small></address>
</body>
</html>