mirror of
https://github.com/boostorg/date_time.git
synced 2026-02-23 15:42:20 +00:00
63 lines
3.1 KiB
HTML
63 lines
3.1 KiB
HTML
<!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.10 -->
|
|
<hr><h1>print_month.cpp</h1> Simple utility to print out days of the month with the days of a month. Demontstrates date iteration (gdtl::date_itr).
|
|
<p>
|
|
<div class="fragment"><pre><font class="comment">/*</font>
|
|
<font class="comment">This example prints all the dates in a month. It demonstrates</font>
|
|
<font class="comment">the use of iterators as well as functions of the gregorian_calendar</font>
|
|
<font class="comment"></font>
|
|
<font class="comment">Output:</font>
|
|
<font class="comment">Enter Year: 2002</font>
|
|
<font class="comment">Enter Month(1..12): 2</font>
|
|
<font class="comment">2002-Feb-01 [Fri]</font>
|
|
<font class="comment">2002-Feb-02 [Sat]</font>
|
|
<font class="comment">2002-Feb-03 [Sun]</font>
|
|
<font class="comment">2002-Feb-04 [Mon]</font>
|
|
<font class="comment">2002-Feb-05 [Tue]</font>
|
|
<font class="comment">2002-Feb-06 [Wed]</font>
|
|
<font class="comment">2002-Feb-07 [Thu]</font>
|
|
<font class="comment">*/</font>
|
|
|
|
<font class="preprocessor">#include "boost/gdtl/gregorian/gregorian.hpp"</font>
|
|
<font class="preprocessor">#include <iostream></font>
|
|
|
|
<font class="keywordtype">int</font>
|
|
main()<font class="keyword"></font>
|
|
<font class="keyword"></font>{
|
|
std::cout << <font class="stringliteral">"Enter Year: "</font>;
|
|
<font class="keywordtype">int</font> year, month;
|
|
std::cin >> year;
|
|
std::cout << <font class="stringliteral">"Enter Month(1..12): "</font>;
|
|
std::cin >> month;
|
|
|
|
<font class="keyword">using</font> <font class="keyword">namespace </font>gregorian;
|
|
<font class="keywordflow">try</font> {
|
|
<font class="comment">//Use the calendar to get the last day of the month</font>
|
|
<font class="keywordtype">int</font> eom_day = gregorian_calendar::end_of_month_day(year,month);
|
|
date endOfMonth(year,month,eom_day);
|
|
|
|
<font class="comment">//construct an iterator starting with firt day of the month</font>
|
|
day_iterator ditr(gregorian::date(year,month,1));
|
|
<font class="comment">//loop thru the days and print each one</font>
|
|
<font class="keywordflow">for</font> (; ditr <= endOfMonth; ++ditr) {
|
|
std::cout << gregorian::to_simple_string(*ditr) << <font class="stringliteral">" ["</font>
|
|
<< ditr->day_of_week().as_short_string() << <font class="stringliteral">"]"</font>
|
|
<< std::endl;
|
|
}
|
|
}
|
|
<font class="keywordflow">catch</font>(std::exception& e) {
|
|
|
|
std::cout << <font class="stringliteral">"Error bad date, check your entry: \n"</font>
|
|
<< <font class="stringliteral">" Details: "</font> << e.what() << std::endl;
|
|
}
|
|
<font class="keywordflow">return</font> 0;
|
|
}
|
|
</pre></div><hr><address><small>
|
|
Generated Wed Mar 13 13:38:03 2002 by <a href="http://www.doxygen.org">Doxygen</a> for <a href="http://www.crystalclearsoftware.com">CrystalClear Software</a> © 2000-2002</small></address>
|
|
</body>
|
|
</html>
|