150 lines
11 KiB
HTML
150 lines
11 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
|
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
|
|
<meta name="generator" content="Doxygen 1.8.6"/>
|
|
<title>Boost.Locale: calendar.cpp</title>
|
|
<link href="tabs.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="jquery.js"></script>
|
|
<script type="text/javascript" src="dynsections.js"></script>
|
|
<link href="navtree.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="resize.js"></script>
|
|
<script type="text/javascript" src="navtree.js"></script>
|
|
<script type="text/javascript">
|
|
$(document).ready(initResizable);
|
|
$(window).load(resizeHeight);
|
|
</script>
|
|
<link href="doxygen.css" rel="stylesheet" type="text/css" />
|
|
</head>
|
|
<body>
|
|
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
|
|
<div id="titlearea">
|
|
<table cellspacing="0" cellpadding="0">
|
|
<tbody>
|
|
<tr style="height: 56px;">
|
|
<td id="projectlogo"><img alt="Logo" src="boost-small.png"/></td>
|
|
<td style="padding-left: 0.5em;">
|
|
<div id="projectname">Boost.Locale
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<!-- end header part -->
|
|
<!-- Generated by Doxygen 1.8.6 -->
|
|
<div id="navrow1" class="tabs">
|
|
<ul class="tablist">
|
|
<li><a href="index.html"><span>Main Page</span></a></li>
|
|
<li><a href="pages.html"><span>Related Pages</span></a></li>
|
|
<li><a href="modules.html"><span>Modules</span></a></li>
|
|
<li><a href="namespaces.html"><span>Namespaces</span></a></li>
|
|
<li><a href="annotated.html"><span>Classes</span></a></li>
|
|
<li><a href="files.html"><span>Files</span></a></li>
|
|
<li><a href="examples.html"><span>Examples</span></a></li>
|
|
</ul>
|
|
</div>
|
|
</div><!-- top -->
|
|
<div id="side-nav" class="ui-resizable side-nav-resizable">
|
|
<div id="nav-tree">
|
|
<div id="nav-tree-contents">
|
|
<div id="nav-sync" class="sync"></div>
|
|
</div>
|
|
</div>
|
|
<div id="splitbar" style="-moz-user-select:none;"
|
|
class="ui-resizable-handle">
|
|
</div>
|
|
</div>
|
|
<script type="text/javascript">
|
|
$(document).ready(function(){initNavTree('calendar_8cpp-example.html','');});
|
|
</script>
|
|
<div id="doc-content">
|
|
<div class="header">
|
|
<div class="headertitle">
|
|
<div class="title">calendar.cpp</div> </div>
|
|
</div><!--header-->
|
|
<div class="contents">
|
|
<p>Example of using date_time functions for generating calendar for current year.</p>
|
|
<div class="fragment"><div class="line"><span class="comment">//</span></div>
|
|
<div class="line"><span class="comment">// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)</span></div>
|
|
<div class="line"><span class="comment">//</span></div>
|
|
<div class="line"><span class="comment">// Distributed under the Boost Software License, Version 1.0. (See</span></div>
|
|
<div class="line"><span class="comment">// accompanying file LICENSE_1_0.txt or copy at</span></div>
|
|
<div class="line"><span class="comment">// http://www.boost.org/LICENSE_1_0.txt)</span></div>
|
|
<div class="line"><span class="comment">//</span></div>
|
|
<div class="line"><span class="preprocessor">#include <boost/locale.hpp></span></div>
|
|
<div class="line"><span class="preprocessor">#include <iostream></span></div>
|
|
<div class="line"><span class="preprocessor">#include <iomanip></span></div>
|
|
<div class="line"><span class="preprocessor">#include <ctime></span></div>
|
|
<div class="line"></div>
|
|
<div class="line"><span class="keywordtype">int</span> main()</div>
|
|
<div class="line">{</div>
|
|
<div class="line"> <span class="keyword">using namespace </span>boost::locale;</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <a name="_a0"></a><a class="code" href="classboost_1_1locale_1_1generator.html">generator</a> gen;</div>
|
|
<div class="line"> std::locale::global(gen(<span class="stringliteral">""</span>));</div>
|
|
<div class="line"> std::cout.imbue(std::locale());</div>
|
|
<div class="line"> <span class="comment">// Setup environment</span></div>
|
|
<div class="line"></div>
|
|
<div class="line"> <a name="_a1"></a><a class="code" href="classboost_1_1locale_1_1date__time.html">boost::locale::date_time</a> now;</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <a class="code" href="classboost_1_1locale_1_1date__time.html">date_time</a> start=now;</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <span class="comment">// Set the first day of the first month of this year</span></div>
|
|
<div class="line"> start.<a name="a2"></a><a class="code" href="classboost_1_1locale_1_1date__time.html#a4c0ed3be4d5d3bb44014a2ea12927ff8">set</a>(<a name="a3"></a><a class="code" href="namespaceboost_1_1locale_1_1period.html#aa6aafbd111a9c729266f2aa28b895d68">period::month</a>(),now.minimum(<a class="code" href="namespaceboost_1_1locale_1_1period.html#aa6aafbd111a9c729266f2aa28b895d68">period::month</a>()));</div>
|
|
<div class="line"> start.set(<a name="a4"></a><a class="code" href="namespaceboost_1_1locale_1_1period.html#a72438d8d7da8493457e043aa442f0d9d">period::day</a>(),start.minimum(<a class="code" href="namespaceboost_1_1locale_1_1period.html#a72438d8d7da8493457e043aa442f0d9d">period::day</a>()));</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <span class="keywordtype">int</span> current_year = <a name="a5"></a><a class="code" href="namespaceboost_1_1locale_1_1period.html#a9ea8d1453bed512ee16bea3199fd92af">period::year</a>(now);</div>
|
|
<div class="line"></div>
|
|
<div class="line"></div>
|
|
<div class="line"> <span class="comment">// Display current year</span></div>
|
|
<div class="line"> std::cout << <a name="a6"></a><a class="code" href="group__format.html#gad7914df7b54382c1ad7f5360676fe2e8">format</a>(<span class="stringliteral">"{1,ftime='%Y'}"</span>) % now << std::endl;</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <span class="comment">//</span></div>
|
|
<div class="line"> <span class="comment">// Run forward untill current year is the date</span></div>
|
|
<div class="line"> <span class="comment">//</span></div>
|
|
<div class="line"> <span class="keywordflow">for</span>(now=start; <a class="code" href="namespaceboost_1_1locale_1_1period.html#a9ea8d1453bed512ee16bea3199fd92af">period::year</a>(now) == current_year;) {</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <span class="comment">// Print heading of month</span></div>
|
|
<div class="line"> <span class="keywordflow">if</span>(<a name="_a7"></a><a class="code" href="classboost_1_1locale_1_1calendar.html">calendar</a>().<a name="a8"></a><a class="code" href="classboost_1_1locale_1_1calendar.html#a657ece3d3d59b8fc3c817bc05227620b">is_gregorian</a>()) </div>
|
|
<div class="line"> std::cout << <a class="code" href="group__format.html#gad7914df7b54382c1ad7f5360676fe2e8">format</a>(<span class="stringliteral">"{1,ftime='%B'}"</span>) % now <<std::endl;</div>
|
|
<div class="line"> <span class="keywordflow">else</span></div>
|
|
<div class="line"> std::cout << <a class="code" href="group__format.html#gad7914df7b54382c1ad7f5360676fe2e8">format</a>(<span class="stringliteral">"{1,ftime='%B'} ({1,ftime='%Y-%m-%d',locale=en} - {2,locale=en,ftime='%Y-%m-%d'})"</span>)</div>
|
|
<div class="line"> % now </div>
|
|
<div class="line"> % <a class="code" href="classboost_1_1locale_1_1date__time.html">date_time</a>(now,now.maximum(<a class="code" href="namespaceboost_1_1locale_1_1period.html#a72438d8d7da8493457e043aa442f0d9d">period::day</a>())*<a class="code" href="namespaceboost_1_1locale_1_1period.html#a72438d8d7da8493457e043aa442f0d9d">period::day</a>()) << std::endl;</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <span class="keywordtype">int</span> first = <a class="code" href="classboost_1_1locale_1_1calendar.html">calendar</a>().<a name="a9"></a><a class="code" href="classboost_1_1locale_1_1calendar.html#a8144b98a316798476040348483fe2a6e">first_day_of_week</a>();</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <span class="comment">// Print weeks days</span></div>
|
|
<div class="line"> <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i=0;i<7;i++) {</div>
|
|
<div class="line"> <a class="code" href="classboost_1_1locale_1_1date__time.html">date_time</a> tmp(now,<a name="a10"></a><a class="code" href="namespaceboost_1_1locale_1_1period.html#ac1b424cae5ed4ab32aed3c3aedc306e9">period::day_of_week</a>() * (first + i));</div>
|
|
<div class="line"> std::cout << <a class="code" href="group__format.html#gad7914df7b54382c1ad7f5360676fe2e8">format</a>(<span class="stringliteral">"{1,w=8,ftime='%a'} "</span>) % tmp;</div>
|
|
<div class="line"> }</div>
|
|
<div class="line"> std::cout << std::endl;</div>
|
|
<div class="line"></div>
|
|
<div class="line"> <span class="keywordtype">int</span> current_month = now / <a class="code" href="namespaceboost_1_1locale_1_1period.html#aa6aafbd111a9c729266f2aa28b895d68">period::month</a>();</div>
|
|
<div class="line"> <span class="keywordtype">int</span> <a name="a11"></a><a class="code" href="group__codepage.html#gga8e3c5a274f57107ec5745e227c26ba84ae9b554a2955deddf714757788819edf9">skip</a> = now / <a name="a12"></a><a class="code" href="namespaceboost_1_1locale_1_1period.html#a57d6b8f97bd6604e13c6982ed0953678">period::day_of_week_local</a>() - 1;</div>
|
|
<div class="line"> <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i=0;i<skip*9;i++)</div>
|
|
<div class="line"> std::cout << <span class="charliteral">' '</span>;</div>
|
|
<div class="line"> <span class="keywordflow">for</span>(;now / <a class="code" href="namespaceboost_1_1locale_1_1period.html#aa6aafbd111a9c729266f2aa28b895d68">period::month</a>() == current_month ;now += <a class="code" href="namespaceboost_1_1locale_1_1period.html#a72438d8d7da8493457e043aa442f0d9d">period::day</a>()) {</div>
|
|
<div class="line"> std::cout << <a class="code" href="group__format.html#gad7914df7b54382c1ad7f5360676fe2e8">format</a>(<span class="stringliteral">"{1,w=8,ftime='%e'} "</span>) % now; </div>
|
|
<div class="line"> <span class="keywordflow">if</span>(now / <a class="code" href="namespaceboost_1_1locale_1_1period.html#a57d6b8f97bd6604e13c6982ed0953678">period::day_of_week_local</a>() == 7)</div>
|
|
<div class="line"> std::cout << std::endl;</div>
|
|
<div class="line"> }</div>
|
|
<div class="line"> std::cout << std::endl;</div>
|
|
<div class="line"> }</div>
|
|
<div class="line"></div>
|
|
<div class="line">}</div>
|
|
<div class="line"><span class="comment">// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4</span></div>
|
|
</div><!-- fragment --> </div><!-- contents -->
|
|
</div><!-- doc-content -->
|
|
|
|
<li class="footer">
|
|
© Copyright 2009-2012 Artyom Beilis, Distributed under the <a href="http://www.boost.org/LICENSE_1_0.txt">Boost Software License</a>, Version 1.0.
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</body>
|
|
</html>
|