• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<?xml version="1.0" encoding="utf-8"?>
2<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
3"../../../tools/boostbook/dtd/boostbook.dtd">
4
5<!-- Copyright (c) 2001-2005 CrystalClear Software, Inc.
6     Subject to the Boost Software License, Version 1.0.
7     (See accompanying file LICENSE_1_0.txt or  http://www.boost.org/LICENSE_1_0.txt)
8-->
9
10<section id="date_time.gregorian.date_iterators">
11  <title>Date Iterators</title>
12
13  <link linkend="iterators_intro">Introduction</link> --
14  <link linkend="iterators_header">Header</link> --
15  <link linkend="iterators_overview">Overview</link>
16
17  <anchor id="iterators_intro" />
18  <bridgehead renderas="sect3">Introduction</bridgehead>
19  <para>
20    Date iterators provide a standard mechanism for iteration through dates. Date iterators are a model of <ulink url="http://www.sgi.com/tech/stl/BidirectionalIterator.html">Bidirectional Iterator</ulink> and can be used to populate collections with dates and other date generation tasks. For example, the <link linkend="date_time.examples.print_month">print month</link> example iterates through all the days in a month and prints them.
21  </para>
22  <para>
23    All of the iterators here derive from boost::gregorian::date_iterator.
24  </para>
25
26  <anchor id="iterators_header" />
27  <bridgehead renderas="sect3">Header</bridgehead>
28  <para>
29    <programlisting>#include "boost/date_time/gregorian/gregorian.hpp" //include all types plus i/o
30or
31#include "boost/date_time/gregorian/gregorian_types.hpp" //no i/o just types</programlisting>
32  </para>
33
34  <anchor id="iterators_overview" />
35  <bridgehead renderas="sect3">Overview</bridgehead>
36  <informaltable frame="all">
37    <tgroup cols="2">
38      <thead>
39	<row>
40	  <entry valign="top" morerows="1">Syntax</entry>
41	  <entry>Description</entry>
42	</row>
43	<row>
44	  <entry>Example</entry>
45	</row>
46      </thead>
47      <tbody>
48        <row>
49	  <entry valign="top" morerows="1"><screen>date_iterator</screen></entry>
50	  <entry>Common (abstract) base class for all day level iterators.</entry>
51	</row>
52	<row>
53	  <entry><screen></screen></entry>
54        </row>
55
56	<row>
57	  <entry valign="top" morerows="1"><screen>day_iterator(date start_date, int day_count=1)</screen></entry>
58          <entry>Iterate <code>day_count</code> days at a time. This iterator does not provide postfix increment/decrement operators. Only prefix operators are provided.</entry>
59	</row>
60	<row>
61          <entry><screen>day_iterator day_itr(date(2005,Jan,1));
62++d_itr; // 2005-Jan-02
63day_iterator 2day_itr(date(2005,Feb,1),2);
64++2d_itr; // 2005-Feb-03</screen></entry>
65        </row>
66
67	<row>
68          <entry valign="top" morerows="1"><screen>week_iterator(...)
69  Parameters:
70    date start_date
71    int week_offset (defaults to 1)</screen></entry>
72          <entry>Iterate <code>week_offset</code> weeks at a time. This iterator does not provide postfix increment/decrement operators. Only prefix operators are provided.</entry>
73	</row>
74	<row>
75          <entry><screen>week_iterator wk_itr(date(2005,Jan,1));
76++wk_itr; // 2005-Jan-08
77week_iterator 2wk_itr(date(2005,Jan,1),2);
78++2wk_itr; // 2005-Feb-15</screen></entry>
79        </row>
80
81	<row>
82          <entry valign="top" morerows="1"><screen>month_iterator(...)
83  Parameters:
84    date start_date
85    int month_offset (defaults to 1)</screen></entry>
86<entry>Iterate <code>month_offset</code> months. There are special rules for handling the end of the month. These are: if start date is last day of the month, always adjust to last day of the month. If date is beyond the end of the month (e.g. Jan 31 + 1 month) adjust back to end of month (for more details and examples of this, see <link linkend="snap_to_details">Reversibility of Operations Pitfall</link>. <emphasis role="strong">NOTE:</emphasis> the <code>month_iterator</code> is not effected by this pitfall.) This iterator does not provide postfix increment/decrement operators. Only prefix operators are provided.</entry>
87	</row>
88	<row>
89          <entry><screen>month_iterator m_itr(date(2005,Jan,1));
90++m_itr; // 2005-Feb-01
91month_iterator 2m_itr(date(2005,Feb,1),2);
92++2m_itr; // 2005-Apr-01</screen></entry>
93        </row>
94
95        <row>
96          <entry valign="top" morerows="1"><screen>year_iterator(...)
97  Parameters:
98    date start_date
99    int year_offset (defaults to 1)</screen></entry>
100	  <entry>Iterate year_offset years. The year_iterator will always land on the day of the date parameter except when date is Feb 28 in a non-leap year. In this case the iterator will return Feb 29 for leap years (eg: 2003-Feb-28, 2004-Feb-29, 2005-Feb-28). This iterator does not provide postfix increment/decrement operators. Only prefix operators are provided.</entry>
101	</row>
102	<row>
103          <entry><screen>year_iterator y_itr(date(2005,Jan,1));
104++y_itr; // 2006-Jan-01
105year_iterator 2y_itr(date(2005,Feb,1),2);
106++2y_itr; // 2007-Feb-01</screen></entry>
107	</row>
108      </tbody>
109    </tgroup>
110  </informaltable>
111
112
113</section>
114