| <!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"/> |
| <title>Boost.Locale: calendar.cpp</title> |
| |
| <link href="tabs.css" rel="stylesheet" type="text/css"/> |
| <link href="doxygen.css" rel="stylesheet" type="text/css" /> |
| <link href="navtree.css" rel="stylesheet" type="text/css"/> |
| <script type="text/javascript" src="jquery.js"></script> |
| <script type="text/javascript" src="resize.js"></script> |
| <script type="text/javascript" src="navtree.js"></script> |
| <script type="text/javascript"> |
| $(document).ready(initResizable); |
| </script> |
| |
| |
| </head> |
| <body> |
| <div id="top"><!-- do not remove this div! --> |
| |
| |
| <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> |
| |
| <!-- Generated by Doxygen 1.7.6.1 --> |
| <div id="navrow1" class="tabs"> |
| <ul class="tablist"> |
| <li><a href="index.html"><span>Main Page</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> |
| <div id="side-nav" class="ui-resizable side-nav-resizable"> |
| <div id="nav-tree"> |
| <div id="nav-tree-contents"> |
| </div> |
| </div> |
| <div id="splitbar" style="-moz-user-select:none;" |
| class="ui-resizable-handle"> |
| </div> |
| </div> |
| <script type="text/javascript"> |
| 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"><pre class="fragment"><span class="comment">//</span> |
| <span class="comment">// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)</span> |
| <span class="comment">//</span> |
| <span class="comment">// Distributed under the Boost Software License, Version 1.0. (See</span> |
| <span class="comment">// accompanying file LICENSE_1_0.txt or copy at</span> |
| <span class="comment">// http://www.boost.org/LICENSE_1_0.txt)</span> |
| <span class="comment">//</span> |
| <span class="preprocessor">#include <boost/locale.hpp></span> |
| <span class="preprocessor">#include <iostream></span> |
| <span class="preprocessor">#include <iomanip></span> |
| <span class="preprocessor">#include <ctime></span> |
| |
| <span class="keywordtype">int</span> main() |
| { |
| <span class="keyword">using namespace </span>boost::locale; |
| |
| <a name="_a0"></a><a class="code" href="classboost_1_1locale_1_1generator.html" title="the major class used for locale generation">generator</a> gen; |
| std::locale::global(gen(<span class="stringliteral">""</span>)); |
| std::cout.imbue(std::locale()); |
| <span class="comment">// Setup environment</span> |
| |
| <a name="_a1"></a><a class="code" href="classboost_1_1locale_1_1date__time.html" title="this class represents a date time and allows to perform various operation according to the locale set...">boost::locale::date_time</a> now; |
| |
| <a class="code" href="classboost_1_1locale_1_1date__time.html" title="this class represents a date time and allows to perform various operation according to the locale set...">date_time</a> start=now; |
| |
| <span class="comment">// Set the first day of the first month of this year</span> |
| 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>())); |
| 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>())); |
| |
| <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); |
| |
| |
| <span class="comment">// Display current year</span> |
| 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; |
| |
| <span class="comment">//</span> |
| <span class="comment">// Run forward untill current year is the date</span> |
| <span class="comment">//</span> |
| <span class="keywordflow">for</span>(now=start; <a class="code" href="namespaceboost_1_1locale_1_1period.html#a9ea8d1453bed512ee16bea3199fd92af">period::year</a>(now) == current_year;) { |
| |
| <span class="comment">// Print heading of month</span> |
| <span class="keywordflow">if</span>(<a name="_a7"></a><a class="code" href="classboost_1_1locale_1_1calendar.html" title="this class provides an access to general calendar information.">calendar</a>().<a name="a8"></a><a class="code" href="classboost_1_1locale_1_1calendar.html#a657ece3d3d59b8fc3c817bc05227620b">is_gregorian</a>()) |
| std::cout << <a class="code" href="group__format.html#gad7914df7b54382c1ad7f5360676fe2e8">format</a>(<span class="stringliteral">"{1,ftime='%B'}"</span>) % now <<std::endl; |
| <span class="keywordflow">else</span> |
| 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>) |
| % now |
| % <a class="code" href="classboost_1_1locale_1_1date__time.html" title="this class represents a date time and allows to perform various operation according to the locale set...">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; |
| |
| <span class="keywordtype">int</span> first = <a class="code" href="classboost_1_1locale_1_1calendar.html" title="this class provides an access to general calendar information.">calendar</a>().<a name="a9"></a><a class="code" href="classboost_1_1locale_1_1calendar.html#a8144b98a316798476040348483fe2a6e">first_day_of_week</a>(); |
| |
| <span class="comment">// Print weeks days</span> |
| <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i=0;i<7;i++) { |
| <a class="code" href="classboost_1_1locale_1_1date__time.html" title="this class represents a date time and allows to perform various operation according to the locale set...">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)); |
| std::cout << <a class="code" href="group__format.html#gad7914df7b54382c1ad7f5360676fe2e8">format</a>(<span class="stringliteral">"{1,w=8,ftime='%a'} "</span>) % tmp; |
| } |
| std::cout << std::endl; |
| |
| <span class="keywordtype">int</span> current_month = now / <a class="code" href="namespaceboost_1_1locale_1_1period.html#aa6aafbd111a9c729266f2aa28b895d68">period::month</a>(); |
| <span class="keywordtype">int</span> <a name="a11"></a><a class="code" href="group__codepage.html#gga8e3c5a274f57107ec5745e227c26ba84ae9b554a2955deddf714757788819edf9" title="Skip illegal/unconvertable characters.">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; |
| <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i=0;i<skip*9;i++) |
| std::cout << <span class="charliteral">' '</span>; |
| <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>()) { |
| std::cout << <a class="code" href="group__format.html#gad7914df7b54382c1ad7f5360676fe2e8">format</a>(<span class="stringliteral">"{1,w=8,ftime='%e'} "</span>) % now; |
| <span class="keywordflow">if</span>(now / <a class="code" href="namespaceboost_1_1locale_1_1period.html#a57d6b8f97bd6604e13c6982ed0953678">period::day_of_week_local</a>() == 7) |
| std::cout << std::endl; |
| } |
| std::cout << std::endl; |
| } |
| |
| } |
| <span class="comment">// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4</span> |
| </pre></div> </div><!-- contents --> |
| </div><!-- contents --> |
| </div> |
| <div id="nav-path" class="navpath"> |
| <ul> |
| |
| <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> |