Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/doc/html/nth_kday_of_month.html @ 25

Last change on this file since 25 was 12, checked in by landauf, 17 years ago

added boost

File size: 7.5 KB
Line 
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
4<title>Class template nth_kday_of_month</title>
5<link rel="stylesheet" href="boostbook.css" type="text/css">
6<meta name="generator" content="DocBook XSL Stylesheets V1.69.1">
7<link rel="start" href="index.html" title="The Boost C++ Libraries">
8<link rel="up" href="date_time/doxy.html#id2508942" title="Header &lt;boost/date_time/date_generators.hpp&gt;">
9<link rel="prev" href="partial_date.html" title="Class template partial_date">
10<link rel="next" href="first_kday_of_month.html" title="Class template first_kday_of_month">
11</head>
12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13<table cellpadding="2" width="100%">
14<td valign="top"><img alt="boost.png (6897 bytes)" width="277" height="86" src="../../boost.png"></td>
15<td align="center"><a href="../../index.htm">Home</a></td>
16<td align="center"><a href="../../libs/libraries.htm">Libraries</a></td>
17<td align="center"><a href="../../people/people.htm">People</a></td>
18<td align="center"><a href="../../more/faq.htm">FAQ</a></td>
19<td align="center"><a href="../../more/index.htm">More</a></td>
20</table>
21<hr>
22<div class="spirit-nav">
23<a accesskey="p" href="partial_date.html"><img src="images/prev.png" alt="Prev"></a><a accesskey="u" href="date_time/doxy.html#id2508942"><img src="images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="images/home.png" alt="Home"></a><a accesskey="n" href="first_kday_of_month.html"><img src="images/next.png" alt="Next"></a>
24</div>
25<div class="refentry" lang="en">
26<a name="nth_kday_of_month"></a><div class="titlepage"></div>
27<div class="refnamediv">
28<h2><span class="refentrytitle">Class template nth_kday_of_month</span></h2>
29<p>boost::date_time::nth_kday_of_month &#8212; Useful generator functor for finding holidays. </p>
30</div>
31<h2 xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv-title">Synopsis</h2>
32<div xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv"><pre class="synopsis"><span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> date_type&gt; 
33<span class="bold"><strong>class</strong></span> nth_kday_of_month
34  :  : <span class="bold"><strong>public</strong></span> boost::date_time::year_based_generator&lt; date_type &gt;
35{
36<span class="bold"><strong>public</strong></span>:
37  <span class="emphasis"><em>// types</em></span>
38  <span class="bold"><strong>typedef</strong></span> date_type::calendar_type        calendar_type;   
39  <span class="bold"><strong>typedef</strong></span> calendar_type::day_of_week_type day_of_week_type;
40  <span class="bold"><strong>typedef</strong></span> calendar_type::month_type       month_type;      
41  <span class="bold"><strong>typedef</strong></span> calendar_type::year_type        year_type;       
42  <span class="bold"><strong>typedef</strong></span> date_type::duration_type        duration_type;   
43
44  <span class="emphasis"><em>// <a href="nth_kday_of_month.html#nth_kday_of_monthconstruct-copy-destruct">construct/copy/destruct</a></em></span>
45  <a href="nth_kday_of_month.html#id2523941-bb">nth_kday_of_month</a>(week_num, day_of_week_type, month_type);
46
47  <span class="emphasis"><em>// <a href="nth_kday_of_month.html#id2405263-bb">public member functions</a></em></span>
48  <span class="type">date_type</span> <a href="nth_kday_of_month.html#id2405268-bb">get_date</a>(year_type) <span class="bold"><strong>const</strong></span>;
49  <span class="type">month_type</span> <a href="nth_kday_of_month.html#id2458799-bb">month</a>() <span class="bold"><strong>const</strong></span>;
50  <span class="type">week_num</span> <a href="nth_kday_of_month.html#id2413307-bb">nth_week</a>() <span class="bold"><strong>const</strong></span>;
51  <span class="type">day_of_week_type</span> <a href="nth_kday_of_month.html#id2413320-bb">day_of_week</a>() <span class="bold"><strong>const</strong></span>;
52  <span class="type"><span class="bold"><strong>const</strong></span> <span class="bold"><strong>char</strong></span> *</span> <a href="nth_kday_of_month.html#id2527806-bb">nth_week_as_str</a>() <span class="bold"><strong>const</strong></span>;
53  <span class="type"><span class="bold"><strong>virtual</strong></span> std::string</span> <a href="nth_kday_of_month.html#id2511093-bb">to_string</a>() <span class="bold"><strong>const</strong></span>;
54};</pre></div>
55<div class="refsect1" lang="en">
56<a name="id2625183"></a><h2>Description</h2>
57<p>Based on the idea in Cal. Calc. for finding holidays that are the 'first Monday of September'. When instantiated with 'fifth' kday of month, the result will be the last kday of month which can be the fourth or fifth depending on the structure of the month.</p>
58<p>The algorithm here basically guesses for the first day of the month. Then finds the first day of the correct type. That is, if the first of the month is a Tuesday and it needs Wenesday then we simply increment by a day and then we can add the length of a week until we get to the 'nth kday'. There are probably more efficient algorithms based on using a mod 7, but this one works reasonably well for basic applications. </p>
59<div class="refsect2" lang="en">
60<a name="id2625202"></a><h3>
61<a name="nth_kday_of_monthconstruct-copy-destruct"></a><code class="computeroutput">nth_kday_of_month</code> construct/copy/destruct</h3>
62<div class="orderedlist"><ol type="1"><li><pre class="literallayout"><a name="id2523941-bb"></a>nth_kday_of_month(week_num week_no, day_of_week_type dow, month_type m);</pre></li></ol></div>
63</div>
64<div class="refsect2" lang="en">
65<a name="id2625237"></a><h3>
66<a name="id2405263-bb"></a><code class="computeroutput">nth_kday_of_month</code> public member functions</h3>
67<div class="orderedlist"><ol type="1">
68<li><pre class="literallayout"><span class="type">date_type</span> <a name="id2405268-bb"></a>get_date(year_type y) <span class="bold"><strong>const</strong></span>;</pre></li>
69<li><pre class="literallayout"><span class="type">month_type</span> <a name="id2458799-bb"></a>month() <span class="bold"><strong>const</strong></span>;</pre></li>
70<li><pre class="literallayout"><span class="type">week_num</span> <a name="id2413307-bb"></a>nth_week() <span class="bold"><strong>const</strong></span>;</pre></li>
71<li><pre class="literallayout"><span class="type">day_of_week_type</span> <a name="id2413320-bb"></a>day_of_week() <span class="bold"><strong>const</strong></span>;</pre></li>
72<li><pre class="literallayout"><span class="type"><span class="bold"><strong>const</strong></span> <span class="bold"><strong>char</strong></span> *</span> <a name="id2527806-bb"></a>nth_week_as_str() <span class="bold"><strong>const</strong></span>;</pre></li>
73<li>
74<pre class="literallayout"><span class="type"><span class="bold"><strong>virtual</strong></span> std::string</span> <a name="id2511093-bb"></a>to_string() <span class="bold"><strong>const</strong></span>;</pre>
75<p>Returns a string formatted as "M4.3.0" ==&gt; 3rd Sunday in April. </p>
76</li>
77</ol></div>
78</div>
79</div>
80</div>
81<table width="100%"><tr>
82<td align="left"></td>
83<td align="right"><small>Copyright © 2001-2005 CrystalClear Software, Inc</small></td>
84</tr></table>
85<hr>
86<div class="spirit-nav">
87<a accesskey="p" href="partial_date.html"><img src="images/prev.png" alt="Prev"></a><a accesskey="u" href="date_time/doxy.html#id2508942"><img src="images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="images/home.png" alt="Home"></a><a accesskey="n" href="first_kday_of_month.html"><img src="images/next.png" alt="Next"></a>
88</div>
89</body>
90</html>
Note: See TracBrowser for help on using the repository browser.