date_iterators.xml 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. <!-- Copyright (c) 2001-2005 CrystalClear Software, Inc.
  5. Subject to the Boost Software License, Version 1.0.
  6. (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
  7. -->
  8. <section id="date_time.gregorian.date_iterators">
  9. <title>Date Iterators</title>
  10. <link linkend="iterators_intro">Introduction</link> --
  11. <link linkend="iterators_header">Header</link> --
  12. <link linkend="iterators_overview">Overview</link>
  13. <anchor id="iterators_intro" />
  14. <bridgehead renderas="sect3">Introduction</bridgehead>
  15. <para>
  16. 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.
  17. </para>
  18. <para>
  19. All of the iterators here derive from boost::gregorian::date_iterator.
  20. </para>
  21. <anchor id="iterators_header" />
  22. <bridgehead renderas="sect3">Header</bridgehead>
  23. <para>
  24. <programlisting>#include "boost/date_time/gregorian/gregorian.hpp" //include all types plus i/o
  25. or
  26. #include "boost/date_time/gregorian/gregorian_types.hpp" //no i/o just types</programlisting>
  27. </para>
  28. <anchor id="iterators_overview" />
  29. <bridgehead renderas="sect3">Overview</bridgehead>
  30. <informaltable frame="all">
  31. <tgroup cols="2">
  32. <thead>
  33. <row>
  34. <entry valign="top" morerows="1">Syntax</entry>
  35. <entry>Description</entry>
  36. </row>
  37. <row>
  38. <entry>Example</entry>
  39. </row>
  40. </thead>
  41. <tbody>
  42. <row>
  43. <entry valign="top" morerows="1"><screen>date_iterator</screen></entry>
  44. <entry>Common (abstract) base class for all day level iterators.</entry>
  45. </row>
  46. <row>
  47. <entry><screen></screen></entry>
  48. </row>
  49. <row>
  50. <entry valign="top" morerows="1"><screen>day_iterator(date start_date, int day_count=1)</screen></entry>
  51. <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>
  52. </row>
  53. <row>
  54. <entry><screen>day_iterator day_itr(date(2005,Jan,1));
  55. ++d_itr; // 2005-Jan-02
  56. day_iterator 2day_itr(date(2005,Feb,1),2);
  57. ++2d_itr; // 2005-Feb-03</screen></entry>
  58. </row>
  59. <row>
  60. <entry valign="top" morerows="1"><screen>week_iterator(...)
  61. Parameters:
  62. date start_date
  63. int week_offset (defaults to 1)</screen></entry>
  64. <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>
  65. </row>
  66. <row>
  67. <entry><screen>week_iterator wk_itr(date(2005,Jan,1));
  68. ++wk_itr; // 2005-Jan-08
  69. week_iterator 2wk_itr(date(2005,Jan,1),2);
  70. ++2wk_itr; // 2005-Feb-15</screen></entry>
  71. </row>
  72. <row>
  73. <entry valign="top" morerows="1"><screen>month_iterator(...)
  74. Parameters:
  75. date start_date
  76. int month_offset (defaults to 1)</screen></entry>
  77. <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>
  78. </row>
  79. <row>
  80. <entry><screen>month_iterator m_itr(date(2005,Jan,1));
  81. ++m_itr; // 2005-Feb-01
  82. month_iterator 2m_itr(date(2005,Feb,1),2);
  83. ++2m_itr; // 2005-Apr-01</screen></entry>
  84. </row>
  85. <row>
  86. <entry valign="top" morerows="1"><screen>year_iterator(...)
  87. Parameters:
  88. date start_date
  89. int year_offset (defaults to 1)</screen></entry>
  90. <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>
  91. </row>
  92. <row>
  93. <entry><screen>year_iterator y_itr(date(2005,Jan,1));
  94. ++y_itr; // 2006-Jan-01
  95. year_iterator 2y_itr(date(2005,Feb,1),2);
  96. ++2y_itr; // 2007-Feb-01</screen></entry>
  97. </row>
  98. </tbody>
  99. </tgroup>
  100. </informaltable>
  101. </section>