1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 2<html> 3<head> 4<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 5<title>Date Time Input/Output</title> 6<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css"> 7<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 8<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset"> 9<link rel="up" href="../date_time.html" title="Chapter 13. Boost.Date_Time"> 10<link rel="prev" href="local_time.html" title="Local Time"> 11<link rel="next" href="serialization.html" title="Serialization"> 12</head> 13<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 14<table cellpadding="2" width="100%"><tr> 15<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td> 16<td align="center"><a href="../../../index.html">Home</a></td> 17<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td> 18<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 19<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 20<td align="center"><a href="../../../more/index.htm">More</a></td> 21</tr></table> 22<hr> 23<div class="spirit-nav"> 24<a accesskey="p" href="local_time.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../date_time.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="serialization.html"><img src="../../../doc/src/images/next.png" alt="Next"></a> 25</div> 26<div class="section"> 27<div class="titlepage"><div><div><h2 class="title" style="clear: both"> 28<a name="date_time.date_time_io"></a>Date Time Input/Output</h2></div></div></div> 29<div class="toc"><dl class="toc"> 30<dt><span class="section"><a href="date_time_io.html#date_time.format_flags">Format Flags</a></span></dt> 31<dt><span class="section"><a href="date_time_io.html#date_time.date_facet">Date Facet</a></span></dt> 32<dt><span class="section"><a href="date_time_io.html#date_time.date_input_facet">Date Input Facet</a></span></dt> 33<dt><span class="section"><a href="date_time_io.html#date_time.time_facet">Time Facet</a></span></dt> 34<dt><span class="section"><a href="date_time_io.html#date_time.time_input_facet">Time Input Facet</a></span></dt> 35<dt><span class="section"><a href="date_time_io.html#date_time.io_objects">Date Time Formatter/Parser Objects</a></span></dt> 36<dt><span class="section"><a href="date_time_io.html#date_time.io_tutorial">Date Time IO Tutorial</a></span></dt> 37</dl></div> 38<h3> 39<a name="id-1.3.14.11.2"></a>Date Time IO System</h3> 40<p> 41 <a class="link" href="date_time_io.html#streaming_exceptions">Exception Handling on Streams</a> 42 </p> 43<p>As of version 1.33, the date_time library utilizes a new IO streaming system. This new system gives the user great control over how dates and times can be represented. The customization options can be broken down into two groups: format flags and string elements. Format flags provide flexibility in the order of the date elements as well as the type. Customizing the string elements allows the replacement of built in strings from month names, weekday names, and other strings used in the IO.</p> 44<p>The output system is based on a date_facet (derived from std::facet), while the input system is based on a date_input_facet (also derived from std::facet). The time and local_time facets are derived from these base types. The output system utilizes three formatter objects, whereas the input system uses four parser objects. These formatter and parser objetcs are also customizable.</p> 45<p>It is important to note, that while all the examples shown here use narrow streams, there are wide stream facets available as well (see <a class="link" href="date_time_io.html#io_objects_table">IO Objects</a> for a complete list).</p> 46<p>It should be further noted that not all compilers are capable of using this IO system. For those compilers the IO system used in previous <code class="computeroutput">date_time</code> versions is still available. The "legacy IO" is automatically selected for these compilers, however, the legacy IO system can be manually selected by defining <code class="computeroutput">USE_DATE_TIME_PRE_1_33_FACET_IO</code>. See the <a class="link" href="details.html#date_time.buildinfo" title="Build-Compiler Information">Build-Compiler Information</a> for more information.</p> 47<a name="streaming_exceptions"></a><h6> 48<a name="id-1.3.14.11.9"></a>Exception Handling on Streams</h6> 49<p>When an error occurs during the input streaming process, the <code class="computeroutput">std::ios_base::failbit</code> will (always) be set on the stream. It is also possible to have exceptions thrown when an error occurs. To "turn on" these exceptions, call the stream's <code class="computeroutput">exceptions</code> function with a parameter of <code class="computeroutput">std::ios_base::failbit</code>.</p> 50<pre class="screen">// "Turning on" exceptions 51date d(not_a_date_time); 52std::stringstream ss; 53ss.exceptions(std::ios_base::failbit); 54ss.str("204-Jan-01"); 55ss >> d; // throws bad_year exception AND sets failbit on stream</pre> 56<h6> 57<a name="id-1.3.14.11.12"></a>A simple example of this new system:</h6> 58<pre class="screen">//example to customize output to be "LongWeekday LongMonthname day, year" 59// "%A %b %d, %Y" 60date d(2005,Jun,25); 61date_facet* facet(new date_facet("%A %B %d, %Y")); 62std::cout.imbue(std::locale(std::cout.getloc(), facet)); 63std::cout << d << std::endl; 64// "Saturday June 25, 2005"</pre> 65<div class="section"> 66<div class="titlepage"><div><div><h3 class="title"> 67<a name="date_time.format_flags"></a>Format Flags</h3></div></div></div> 68<p>Many of the format flags this new system uses for output are those used by <code class="computeroutput">strftime(...)</code>, but not all. Some new flags have been added, and others overridden. The input system supports only specific flags, therefore, not all flags that work for output will work with input (we are currently working to correct this situation).</p> 69<p>The following tables list the all the flags available for both date_time IO as well as strftime. Format flags marked with a single asterisk (*) have a behavior unique to date_time. Those flags marked with an exclamation point (!) are not usable for input (at this time). The flags marked with a hash sign (#) are implemented by system locale and are known to be missing on some platforms. The first table is for dates, and the second table is for times. 70 </p> 71<p> 72 <a name="date_time_io.date_format_flags"></a> 73 Date Facet Format Flags 74 </p> 75<div class="informaltable"><table class="table"> 76<colgroup> 77<col> 78<col> 79</colgroup> 80<thead> 81<tr> 82<th rowspan="2" valign="top">Format Specifier</th> 83<th>Description</th> 84</tr> 85<tr><th>Example</th></tr> 86</thead> 87<tbody> 88<tr> 89<td rowspan="2" valign="top"><pre class="screen">%a</pre></td> 90<td>Abbreviated weekday name</td> 91</tr> 92<tr><td><pre class="screen">"Mon" => Monday</pre></td></tr> 93<tr> 94<td rowspan="2" valign="top"><pre class="screen">%A</pre></td> 95<td>Long weekday name</td> 96</tr> 97<tr><td><pre class="screen">"Monday"</pre></td></tr> 98<tr> 99<td rowspan="2" valign="top"><pre class="screen">%b</pre></td> 100<td>Abbreviated month name</td> 101</tr> 102<tr><td><pre class="screen">"Feb" => February</pre></td></tr> 103<tr> 104<td rowspan="2" valign="top"><pre class="screen">%B</pre></td> 105<td>Full month name</td> 106</tr> 107<tr><td><pre class="screen">"February"</pre></td></tr> 108<tr> 109<td rowspan="2" valign="top"><pre class="screen">%c !</pre></td> 110<td>The preferred date and time representation for the current locale.</td> 111</tr> 112<tr><td><pre class="screen"></pre></td></tr> 113<tr> 114<td rowspan="2" valign="top"><pre class="screen">%C !#</pre></td> 115<td>The century number (year/100) as a 2-digit integer.</td> 116</tr> 117<tr><td><pre class="screen"></pre></td></tr> 118<tr> 119<td rowspan="2" valign="top"><pre class="screen">%d</pre></td> 120<td> 121 Day of the month as decimal 01 to 31. When used to parse input, the leading zero is optional. 122 </td> 123</tr> 124<tr><td><pre class="screen"></pre></td></tr> 125<tr> 126<td rowspan="2" valign="top"><pre class="screen">%D !#</pre></td> 127<td>Equivalent to %m/%d/%y</td> 128</tr> 129<tr><td><pre class="screen"></pre></td></tr> 130<tr> 131<td rowspan="2" valign="top"><pre class="screen">%e #</pre></td> 132<td> 133 Like %d, the day of the month as a decimal number, but a leading zero is replaced by a space. 134 When used to parse input, the leading space is optional. 135 </td> 136</tr> 137<tr><td><pre class="screen"></pre></td></tr> 138<tr> 139<td rowspan="2" valign="top"><pre class="screen">%G !</pre></td> 140<td>This has the same format and value as %y, except that if the ISO week number belongs to the previous or next year, that year is used instead.</td> 141</tr> 142<tr><td><pre class="screen"></pre></td></tr> 143<tr> 144<td rowspan="2" valign="top"><pre class="screen">%g !</pre></td> 145<td>Like %G, but without century.</td> 146</tr> 147<tr><td><pre class="screen"></pre></td></tr> 148<tr> 149<td rowspan="2" valign="top"><pre class="screen">%h !#</pre></td> 150<td> Equivalent to %b</td> 151</tr> 152<tr><td><pre class="screen"></pre></td></tr> 153<tr> 154<td rowspan="2" valign="top"><pre class="screen">%j</pre></td> 155<td>Day of year as decimal from 001 to 366 for leap years, 001 - 365 for non-leap years.</td> 156</tr> 157<tr><td><pre class="screen">"060" => Feb-29</pre></td></tr> 158<tr> 159<td rowspan="2" valign="top"><pre class="screen">%m</pre></td> 160<td>Month name as a decimal 01 to 12</td> 161</tr> 162<tr><td><pre class="screen">"01" => January</pre></td></tr> 163<tr> 164<td rowspan="2" valign="top"><pre class="screen">%u !</pre></td> 165<td>The day of the week as a decimal, range 1 to 7, Monday being 1.</td> 166</tr> 167<tr><td><pre class="screen"></pre></td></tr> 168<tr> 169<td rowspan="2" valign="top"><pre class="screen">%U</pre></td> 170<td>The week number of the current year as a decimal number, range 00 to 53, starting with the first Sunday as the first day of week 01. In 2005, Jan 1st falls on a Saturday, so therefore it falls within week 00 of 2005 (week 00 spans 2004-Dec-26 to 2005-Jan-01. This also happens to be week 53 of 2004).</td> 171</tr> 172<tr><td><pre class="screen">date d(2005, Jan, 1); // Saturday 173// with format %U 174ss << d; // "00" 175d += day(1); // Sunday 176ss << d; // "01" beginning of week 1</pre></td></tr> 177<tr> 178<td rowspan="2" valign="top"><pre class="screen">%V !#</pre></td> 179<td>The ISO 8601:1988 week number of the current year as a decimal number, range 01 to 53, where week 1 is the first week that has at least 4 days in the current year, and with Monday as the first day of the week.</td> 180</tr> 181<tr><td><pre class="screen"></pre></td></tr> 182<tr> 183<td rowspan="2" valign="top"><pre class="screen">%w</pre></td> 184<td>Weekday as decimal number 0 to 6</td> 185</tr> 186<tr><td><pre class="screen">"0" => Sunday</pre></td></tr> 187<tr> 188<td rowspan="2" valign="top"><pre class="screen">%W</pre></td> 189<td>Week number 00 to 53 where Monday is first day of week 1</td> 190</tr> 191<tr><td><pre class="screen">date d(2005, Jan, 2); // Sunday 192// with format %W 193ss << d; // "00" 194d += day(1); // Monday 195ss << d; // "01" beginning of week 1</pre></td></tr> 196<tr> 197<td rowspan="2" valign="top"><pre class="screen">%x</pre></td> 198<td>Implementation defined date format from the locale.</td> 199</tr> 200<tr><td><pre class="screen">date d(2005,Oct,31); 201date_facet* f = new date_facet("%x"); 202 203locale loc = locale(locale("en_US"), f); 204cout.imbue(loc); 205cout << d; // "10/31/2005" 206 207loc = locale(locale("de_DE"), f); 208cout.imbue(loc); 209cout << d; // "31.10.2005"</pre></td></tr> 210<tr> 211<td rowspan="2" valign="top"><pre class="screen">%y</pre></td> 212<td>Two digit year</td> 213</tr> 214<tr><td><pre class="screen">"05" => 2005</pre></td></tr> 215<tr> 216<td rowspan="2" valign="top"><pre class="screen">%Y</pre></td> 217<td>Four digit year</td> 218</tr> 219<tr><td><pre class="screen">"2005"</pre></td></tr> 220<tr> 221<td rowspan="2" valign="top"><pre class="screen">%Y-%b-%d</pre></td> 222<td>Default date format</td> 223</tr> 224<tr><td><pre class="screen">"2005-Apr-01"</pre></td></tr> 225<tr> 226<td rowspan="2" valign="top"><pre class="screen">%Y%m%d</pre></td> 227<td>ISO format</td> 228</tr> 229<tr><td><pre class="screen">"20050401"</pre></td></tr> 230<tr> 231<td rowspan="2" valign="top"><pre class="screen">%Y-%m-%d</pre></td> 232<td>ISO extended format</td> 233</tr> 234<tr><td><pre class="screen">"2005-04-01"</pre></td></tr> 235</tbody> 236</table></div> 237<p> 238 239 240 <a name="date_time_io.time_format_flags"></a> 241 Time Facet Format Flags 242 </p> 243<div class="informaltable"><table class="table"> 244<colgroup> 245<col> 246<col> 247</colgroup> 248<thead> 249<tr> 250<th rowspan="2" valign="top">Format Specifier</th> 251<th>Description</th> 252</tr> 253<tr><th>Example</th></tr> 254</thead> 255<tbody> 256<tr> 257<td rowspan="2" valign="top"><pre class="screen">%- *!</pre></td> 258<td>Placeholder for the sign of a duration. Only displays when the duration is negative.</td> 259</tr> 260<tr><td><pre class="screen">"-13:15:16"</pre></td></tr> 261<tr> 262<td rowspan="2" valign="top"><pre class="screen">%+ *!</pre></td> 263<td>Placeholder for the sign of a duration. Always displays for both positive and negative.</td> 264</tr> 265<tr><td><pre class="screen">"+13:15:16"</pre></td></tr> 266<tr> 267<td rowspan="2" valign="top"><pre class="screen">%f</pre></td> 268<td>Fractional seconds are always used, even when their value is zero</td> 269</tr> 270<tr><td><pre class="screen">"13:15:16.000000"</pre></td></tr> 271<tr> 272<td rowspan="2" valign="top"><pre class="screen">%F *</pre></td> 273<td>Fractional seconds are used only when their value is not zero.</td> 274</tr> 275<tr><td><pre class="screen">"13:15:16" 276"05:04:03.001234"</pre></td></tr> 277<tr> 278<td rowspan="2" valign="top"><pre class="screen">%H</pre></td> 279<td>The hour as a decimal number using a 24-hour clock (range 00 to 23).</td> 280</tr> 281<tr><td> </td></tr> 282<tr> 283<td rowspan="2" valign="top"><pre class="screen">%I !</pre></td> 284<td>The hour as a decimal number using a 12-hour clock (range 01 to 12).</td> 285</tr> 286<tr><td> </td></tr> 287<tr> 288<td rowspan="2" valign="top"><pre class="screen">%k !</pre></td> 289<td>The hour (24-hour clock) as a decimal number (range 0 to 23); single digits are preceded by a blank.</td> 290</tr> 291<tr><td> </td></tr> 292<tr> 293<td rowspan="2" valign="top"><pre class="screen">%l !</pre></td> 294<td>The hour (12-hour clock) as a decimal number (range 1 to 12); single digits are preceded by a blank.</td> 295</tr> 296<tr><td> </td></tr> 297<tr> 298<td rowspan="2" valign="top"><pre class="screen">%M</pre></td> 299<td>The minute as a decimal number (range 00 to 59).</td> 300</tr> 301<tr><td> </td></tr> 302<tr> 303<td rowspan="2" valign="top"><pre class="screen">%O</pre></td> 304<td>The number of hours in a time duration as a decimal number (range 0 to max. representable duration); single digits are preceded by a zero.</td> 305</tr> 306<tr><td> </td></tr> 307<tr> 308<td rowspan="2" valign="top"><pre class="screen">%p !</pre></td> 309<td>Either `AM' or `PM' according to the given time value, or the corresponding strings for the current locale.</td> 310</tr> 311<tr><td> </td></tr> 312<tr> 313<td rowspan="2" valign="top"><pre class="screen">%P !#</pre></td> 314<td>Like %p but in lowercase: `am' or `pm' or a corresponding string for the current locale.</td> 315</tr> 316<tr><td> </td></tr> 317<tr> 318<td rowspan="2" valign="top"><pre class="screen">%r !#</pre></td> 319<td>The time in a.m. or p.m. notation. In the POSIX locale this is equivalent to `%I:%M:%S %p'</td> 320</tr> 321<tr><td> </td></tr> 322<tr> 323<td rowspan="2" valign="top"><pre class="screen">%R !</pre></td> 324<td>The time in 24-hour notation (%H:%M)</td> 325</tr> 326<tr><td> </td></tr> 327<tr> 328<td rowspan="2" valign="top"><pre class="screen">%s *</pre></td> 329<td>Seconds with fractional seconds.</td> 330</tr> 331<tr><td><pre class="screen">"59.000000"</pre></td></tr> 332<tr> 333<td rowspan="2" valign="top"><pre class="screen">%S</pre></td> 334<td>Seconds only</td> 335</tr> 336<tr><td><pre class="screen">"59"</pre></td></tr> 337<tr> 338<td rowspan="2" valign="top"><pre class="screen">%T !</pre></td> 339<td>The time in 24-hour notation (%H:%M:%S)</td> 340</tr> 341<tr><td> </td></tr> 342<tr> 343<td rowspan="2" valign="top"><pre class="screen">%q</pre></td> 344<td>ISO time zone (output only). This flag is ignored when using the time_facet with a ptime.</td> 345</tr> 346<tr><td><pre class="screen">"-0700" // Mountain Standard Time</pre></td></tr> 347<tr> 348<td rowspan="2" valign="top"><pre class="screen">%Q</pre></td> 349<td>ISO extended time zone (output only). This flag is ignored when using the time_facet with a ptime.</td> 350</tr> 351<tr><td><pre class="screen">"-05:00" // Eastern Standard Time</pre></td></tr> 352<tr> 353<td rowspan="2" valign="top"><pre class="screen">%z *!</pre></td> 354<td>Abbreviated time zone (output only). This flag is ignored when using the time_facet with a ptime.</td> 355</tr> 356<tr><td><pre class="screen">"MST" // Mountain Standard Time</pre></td></tr> 357<tr> 358<td rowspan="2" valign="top"><pre class="screen">%Z *!</pre></td> 359<td>Full time zone name (output only). This flag is ignored when using the time_facet with a ptime.</td> 360</tr> 361<tr><td><pre class="screen">"EDT" // Eastern Daylight Time</pre></td></tr> 362<tr> 363<td rowspan="2" valign="top"><pre class="screen">%ZP *</pre></td> 364<td>Posix time zone string (available to both input and output). This flag is ignored when using the time_facet with a ptime. For complete details on posix time zone strings, see <a class="link" href="local_time.html#date_time.local_time.posix_time_zone" title="Posix Time Zone">posix_time_zone class</a>.</td> 365</tr> 366<tr><td><pre class="screen">"EST-05EDT+01,M4.1.0/02:00,M10.5.0/02:00"</pre></td></tr> 367<tr> 368<td rowspan="2" valign="top"><pre class="screen">%x %X</pre></td> 369<td>Implementation defined date/time format from the locale.</td> 370</tr> 371<tr><td><pre class="screen">date d(2005,Oct,31); 372ptime pt(d, hours(20)); 373time_facet* f = new time_facet("%x %X"); 374 375locale loc = locale(locale("en_US"), f); 376cout.imbue(loc); 377cout << pt; // "10/31/2005 08:00:00 PM" 378 379loc = locale(locale("de_DE"), f); 380cout.imbue(loc); 381cout << pt; // "31.10.2005 20:00:00"</pre></td></tr> 382<tr> 383<td rowspan="2" valign="top"><pre class="screen">%Y%m%dT%H%M%S%F%q</pre></td> 384<td>ISO format</td> 385</tr> 386<tr><td><pre class="screen">"20051015T131211-0700" // Oct 15, 2005 13:12:11 MST</pre></td></tr> 387<tr> 388<td rowspan="2" valign="top"><pre class="screen">%Y-%m-%d %H:%M:%S%F%Q</pre></td> 389<td>Extended ISO format</td> 390</tr> 391<tr><td><pre class="screen">"2005-10-15 13:12:11-07:00"</pre></td></tr> 392<tr> 393<td rowspan="2" valign="top"><pre class="screen">%Y-%b-%d %H:%M:%S%F %z</pre></td> 394<td>Default format used when outputting ptime and local_date_time.</td> 395</tr> 396<tr><td><pre class="screen">"2005-Oct-15 13:12:11 MST"</pre></td></tr> 397<tr> 398<td rowspan="2" valign="top"><pre class="screen">%Y-%b-%d %H:%M:%S%F %ZP</pre></td> 399<td>Default format used when inputting ptime and local_date_time.</td> 400</tr> 401<tr><td><pre class="screen">"2005-Oct-15 13:12:11 MST-07"</pre></td></tr> 402<tr> 403<td rowspan="2" valign="top"><pre class="screen">%-%H:%M:%S%F !</pre></td> 404<td>Default time_duration format for output. Sign will only be displayed for negative durations.</td> 405</tr> 406<tr><td><pre class="screen">"-13:14:15.003400"</pre></td></tr> 407<tr> 408<td rowspan="2" valign="top"><pre class="screen">%H:%M:%S%F</pre></td> 409<td>Default time_duration format for input.</td> 410</tr> 411<tr><td><pre class="screen">"13:14:15.003400"</pre></td></tr> 412</tbody> 413</table></div> 414<p> 415 </p> 416<p>* Signifies flags that have a behavior unique to <code class="computeroutput">date_time</code>.</p> 417<p># Signifies flags that have a platform-dependent behavior. These may not be supported everywhere.</p> 418<p>! Signifies flags that currently do not work for input.</p> 419</div> 420<p>The following table lists the available facets.</p> 421<a name="io_objects_table"></a><h4> 422<a name="id-1.3.14.11.17"></a>IO Objects</h4> 423<p> 424 </p> 425<div class="informaltable"><table class="table"> 426<colgroup> 427<col> 428<col> 429</colgroup> 430<thead><tr> 431<th>Output</th> 432<th>Input</th> 433</tr></thead> 434<tbody> 435<tr> 436<td><code class="computeroutput"><a class="link" href="../boost/date_time/date_facet.html" title="Class template date_facet">date_facet</a></code></td> 437<td><code class="computeroutput"><a class="link" href="../boost/date_time/date_input_facet.html" title="Class template date_input_facet">date_input_facet</a></code></td> 438</tr> 439<tr> 440<td><code class="computeroutput"><a class="link" href="../boost/date_time/date_facet.html" title="Class template date_facet">wdate_facet</a></code></td> 441<td><code class="computeroutput"><a class="link" href="../boost/date_time/date_input_facet.html" title="Class template date_input_facet">wdate_input_facet</a></code></td> 442</tr> 443<tr> 444<td><code class="computeroutput"><a class="link" href="../boost/date_time/time_facet.html" title="Class template time_facet">time_facet</a></code></td> 445<td><code class="computeroutput"><a class="link" href="../boost/date_time/time_input_facet.html" title="Class template time_input_facet">time_input_facet</a></code></td> 446</tr> 447<tr> 448<td><code class="computeroutput"><a class="link" href="../boost/date_time/time_facet.html" title="Class template time_facet">wtime_facet</a></code></td> 449<td><code class="computeroutput"><a class="link" href="../boost/date_time/time_input_facet.html" title="Class template time_input_facet">wtime_input_facet</a></code></td> 450</tr> 451<tr> 452<td> 453<code class="computeroutput"><a class="link" href="../boost/date_time/time_facet.html" title="Class template time_facet">local_time_facet</a></code>*</td> 454<td> 455<code class="computeroutput"><a class="link" href="../boost/date_time/time_input_facet.html" title="Class template time_input_facet">local_time_input_facet</a></code>*</td> 456</tr> 457<tr> 458<td> 459<code class="computeroutput"><a class="link" href="../boost/date_time/time_facet.html" title="Class template time_facet">wlocal_time_facet</a></code>*</td> 460<td> 461<code class="computeroutput"><a class="link" href="../boost/date_time/time_input_facet.html" title="Class template time_input_facet">wlocal_time_input_facet</a></code>*</td> 462</tr> 463</tbody> 464</table></div> 465<p> 466 * These links lead to the <code class="computeroutput">time_facet</code> and <code class="computeroutput">time_input_facet</code> reference sections. They are not actual classes but typedefs. 467 </p> 468<h4> 469<a name="id-1.3.14.11.19"></a>Formatter/Parser Objects</h4> 470<p>To implement the new i/o facets the date-time library uses a number of new parsers and formatters. These classes are available for users that want to implement specialized input/output routines.</p> 471<p> 472 </p> 473<div class="informaltable"><table class="table"> 474<colgroup> 475<col> 476<col> 477</colgroup> 478<thead><tr> 479<th>Output</th> 480<th>Input</th> 481</tr></thead> 482<tbody> 483<tr> 484<td><code class="computeroutput"><a class="link" href="../boost/date_time/period_formatter.html" title="Class template period_formatter">period_formatter</a></code></td> 485<td><code class="computeroutput"><a class="link" href="../boost/date_time/period_parser.html" title="Class template period_parser">period_parser</a></code></td> 486</tr> 487<tr> 488<td><code class="computeroutput"><a class="link" href="../boost/date_time/date_generator_formatter.html" title="Class template date_generator_formatter">date_generator_formatter</a></code></td> 489<td><code class="computeroutput"><a class="link" href="../boost/date_time/date_generator_parser.html" title="Class template date_generator_parser">date_generator_parser</a></code></td> 490</tr> 491<tr> 492<td><code class="computeroutput"><a class="link" href="../boost/date_time/special_values_formatter.html" title="Class template special_values_formatter">special_values_formatter</a></code></td> 493<td><code class="computeroutput"><a class="link" href="../boost/date_time/special_values_parser.html" title="Class template special_values_parser">special_values_parser</a></code></td> 494</tr> 495<tr> 496<td> </td> 497<td><code class="computeroutput"><a class="link" href="../boost/date_time/format_date_parser.html" title="Class template format_date_parser">format_date_parser</a></code></td> 498</tr> 499</tbody> 500</table></div> 501<p> 502 </p> 503<div class="section"> 504<div class="titlepage"><div><div><h3 class="title"> 505<a name="date_time.date_facet"></a>Date Facet</h3></div></div></div> 506<a class="link" href="date_time_io.html#date_facet_intro">Introduction</a> - 507 <a class="link" href="date_time_io.html#date_facet_constr">Construction</a> - 508 <a class="link" href="date_time_io.html#date_facet_accessors">Accessors</a><a name="date_facet_intro"></a><h4> 509<a name="id-1.3.14.11.22.6"></a>Introduction</h4> 510<p>The <code class="computeroutput">boost::date_time::date_facet</code> enables users to have significant control over the output streaming of dates (and other gregorian objects). The date_facet is typedef'd in the <code class="computeroutput">gregorian</code> namespace as <code class="computeroutput">date_facet</code> and <code class="computeroutput">wdate_facet</code>. 511 </p> 512<a name="date_facet_constr"></a><h4> 513<a name="id-1.3.14.11.22.9"></a>Construction</h4> 514<p> 515 </p> 516<div class="informaltable"><table class="table"> 517<colgroup> 518<col> 519<col> 520</colgroup> 521<thead><tr> 522<th>Syntax</th> 523<th>Description</th> 524</tr></thead> 525<tbody> 526<tr> 527<td valign="top"><pre class="screen">date_facet()</pre></td> 528<td>Default constructor</td> 529</tr> 530<tr> 531<td valign="top"><pre class="screen">date_facet(...) 532 Parameters: 533 char_type* format 534 input_collection_type</pre></td> 535<td>Format given will be used for date output. All other formats will use their defaults. Collection is the set of short names to be used for months. All other name collections will use their defaults.</td> 536</tr> 537<tr> 538<td valign="top"><pre class="screen">date_facet(...) 539 Parameters: 540 char_type* format 541 period_formatter_type 542 special_values_formatter_type 543 date_gen_formatter_type</pre></td> 544<td>Format given will be used for date output. The remaining parameters are formatter objects. Further details on these objects can be found <a class="link" href="date_time_io.html#date_time.io_objects" title="Date Time Formatter/Parser Objects">here</a>. This constructor also provides default arguments for all parameters except the format. Therefore, <code class="computeroutput">date_facet("%m %d %Y")</code> will work.</td> 545</tr> 546</tbody> 547</table></div> 548<p> 549 </p> 550<a name="date_facet_accessors"></a><h4> 551<a name="id-1.3.14.11.22.12"></a>Accessors</h4> 552<p> 553 </p> 554<div class="informaltable"><table class="table"> 555<colgroup> 556<col> 557<col> 558</colgroup> 559<thead> 560<tr> 561<th rowspan="2" valign="top">Syntax</th> 562<th>Description</th> 563</tr> 564<tr><th>Example</th></tr> 565</thead> 566<tbody> 567<tr> 568<td rowspan="2" valign="top"><pre class="screen">void format(char_type*)</pre></td> 569<td>Set the format for dates.</td> 570</tr> 571<tr><td><pre class="screen">date_facet* f = new date_facet(); 572f->format("%m %d %Y");</pre></td></tr> 573<tr> 574<td rowspan="2" valign="top"><pre class="screen">void set_iso_format()</pre></td> 575<td>Sets the date format to ISO</td> 576</tr> 577<tr><td><pre class="screen">f->set_iso_format(); 578// "%Y%m%d"</pre></td></tr> 579<tr> 580<td rowspan="2" valign="top"><pre class="screen">void set_iso_extended_format()</pre></td> 581<td>Sets the date format to ISO Extended</td> 582</tr> 583<tr><td><pre class="screen">f->set_iso_extended_format(); 584// "%Y-%m-%d"</pre></td></tr> 585<tr> 586<td rowspan="2" valign="top"><pre class="screen">void month_format(char_type*)</pre></td> 587<td>Set the format for months when they are 'put' individually.</td> 588</tr> 589<tr><td><pre class="screen">f->month_format("%B"); 590ss << greg_month(12); // "December"</pre></td></tr> 591<tr> 592<td rowspan="2" valign="top"><pre class="screen">void weekday_format(char_type*)</pre></td> 593<td>Set the format for weekdays when they are 'put' individually.</td> 594</tr> 595<tr><td><pre class="screen">f->weekday_format("%a"); 596ss << greg_weekday(2); // "Tue"</pre></td></tr> 597<tr> 598<td rowspan="2" valign="top"><pre class="screen">void period_formatter(...) 599 Parameter: 600 period_formatter_type</pre></td> 601<td>Replaces the period formatter object with a user created one.</td> 602</tr> 603<tr><td>see the <a class="link" href="date_time_io.html#date_time.io_tutorial" title="Date Time IO Tutorial">tutorial</a> for a complete example.</td></tr> 604<tr> 605<td rowspan="2" valign="top"><pre class="screen">void special_values_formatter(...) 606 Parameter: 607 special_values_formatter_type</pre></td> 608<td>Replaces the special_values formatter object with a user created one.</td> 609</tr> 610<tr><td>see the <a class="link" href="date_time_io.html#date_time.io_tutorial" title="Date Time IO Tutorial">tutorial</a> for a complete example.</td></tr> 611<tr> 612<td rowspan="2" valign="top"><pre class="screen">void date_gen_phrase_strings(...) 613 Parameters: 614 input_collection_type 615 date_gen_formatter_type:: 616 phrase_elements</pre></td> 617<td>Sets new date generator phrase strings in date_gen_formatter. The input collection is a vector of strings (for details on these strings see <a class="link" href="date_time_io.html#io_objects.date_generators">date generator formatter/parser documentation</a>). The phrase_elements parameter is an enum, defined in the date_generator_formatter object, that has a default value of 'first'. It is used to indicate what the position of the first string in the collection will be.</td> 618</tr> 619<tr><td><pre class="screen"></pre></td></tr> 620<tr> 621<td rowspan="2" valign="top"><pre class="screen">void short_weekday_names(...) 622 Parameter: 623 input_collection_type</pre></td> 624<td>Replace strings used when 'putting' short weekdays.</td> 625</tr> 626<tr><td>see the <a class="link" href="date_time_io.html#date_time.io_tutorial" title="Date Time IO Tutorial">tutorial</a> for a complete example.</td></tr> 627<tr> 628<td rowspan="2" valign="top"><pre class="screen">void long_weekday_names(...) 629 Parameter: 630 input_collection_type</pre></td> 631<td>Replace strings used when 'putting' long weekdays.</td> 632</tr> 633<tr><td>see the <a class="link" href="date_time_io.html#date_time.io_tutorial" title="Date Time IO Tutorial">tutorial</a> for a complete example.</td></tr> 634<tr> 635<td rowspan="2" valign="top"><pre class="screen">void short_month_names(...) 636 Parameter: 637 input_collection_type</pre></td> 638<td>Replace strings used when 'putting' short months.</td> 639</tr> 640<tr><td>see the <a class="link" href="date_time_io.html#date_time.io_tutorial" title="Date Time IO Tutorial">tutorial</a> for a complete example.</td></tr> 641<tr> 642<td rowspan="2" valign="top"><pre class="screen">void long_month_names(...) 643 Parameter: 644 input_collection_type</pre></td> 645<td>Replace strings used when 'putting' long months.</td> 646</tr> 647<tr><td>see the <a class="link" href="date_time_io.html#date_time.io_tutorial" title="Date Time IO Tutorial">tutorial</a> for a complete example.</td></tr> 648<tr> 649<td rowspan="2" valign="top"><pre class="screen">OutItrT put(...) 650 Common parameters for all 651 'put' functions: 652 OutItrT 653 ios_base 654 char_type 655 Unique parameter for 'put' funcs: 656 gregorian object</pre></td> 657<td>There are 12 put functions in the date_facet. The common paraeters are: an iterator pointing to the next item in the stream, an ios_base object, and the fill character. Each unique gregorian object has it's own put function. Each unique put function is described below.</td> 658</tr> 659<tr><td><pre class="screen"></pre></td></tr> 660<tr> 661<td rowspan="2" valign="top"><pre class="screen">OutItrT put(..., date)</pre></td> 662<td>Puts a date object into the stream using the format set by <code class="computeroutput">format(...)</code> or the default.</td> 663</tr> 664<tr><td><pre class="screen"></pre></td></tr> 665<tr> 666<td rowspan="2" valign="top"><pre class="screen">OutItrT put(..., days)</pre></td> 667<td>Puts a days object into the stream as a number.</td> 668</tr> 669<tr><td><pre class="screen"></pre></td></tr> 670<tr> 671<td rowspan="2" valign="top"><pre class="screen">OutItrT put(..., month)</pre></td> 672<td>Puts a month object into the stream using the format set by <code class="computeroutput">month_format(...)</code> or the default.</td> 673</tr> 674<tr><td><pre class="screen"></pre></td></tr> 675<tr> 676<td rowspan="2" valign="top"><pre class="screen">OutItrT put(..., day)</pre></td> 677<td>Puts a day of month object into the stream as a two digit number.</td> 678</tr> 679<tr><td><pre class="screen">"01" // January 1st</pre></td></tr> 680<tr> 681<td rowspan="2" valign="top"><pre class="screen">OutItrT put(..., day_of_week)</pre></td> 682<td>Puts a day of week object into the stream using the format set by <code class="computeroutput">weekday_format(...)</code> or the default.</td> 683</tr> 684<tr><td><pre class="screen"></pre></td></tr> 685<tr> 686<td rowspan="2" valign="top"><pre class="screen">OutItrT put(..., date_period)</pre></td> 687<td>Puts a date_period into the stream. The format of the dates will use the format set by <code class="computeroutput">format(..)</code> or the default date format. The type of period (open or closed range) and the delimiters used are those used by the period_formatter.</td> 688</tr> 689<tr><td><pre class="screen"></pre></td></tr> 690<tr> 691<td rowspan="2" valign="top"><pre class="screen">OutItrT put(..., partial_date)</pre></td> 692<td>Puts a partial_date date_generator object into the stream. The month format used is set by <code class="computeroutput">month_format(..)</code> or the default. The day of month is represented as a two digit number.</td> 693</tr> 694<tr><td><pre class="screen">"01 Jan" // default formats 695"01 January" // long month format</pre></td></tr> 696<tr> 697<td rowspan="2" valign="top"><pre class="screen">OutItrT put(..., date_generator) 698 Date Generator Type: 699 nth_day_of_the_week_in_month</pre></td> 700<td>Puts a nth_day_of_the_week_in_month object into the stream. The month format is set by <code class="computeroutput">month_format(...)</code> or the default. The weekday format is set by <code class="computeroutput">weekday_format(...)</code> or the default. The remaining phrase elements are set in the <a class="link" href="date_time_io.html#io_objects.date_generators">date_generator_formatter</a>.</td> 701</tr> 702<tr><td><pre class="screen">"third Fri in May" // defaults</pre></td></tr> 703<tr> 704<td rowspan="2" valign="top"><pre class="screen">OutItrT put(..., date_generator) 705 Date Generator Type: 706 first_day_of_the_week_in_month</pre></td> 707<td>Puts a first_day_of_the_week_in_month object into the stream. The month format is set by <code class="computeroutput">month_format(...)</code> or the default. The weekday format is set by <code class="computeroutput">weekday_format(...)</code> or the default. The remaining phrase elements are set in the <a class="link" href="date_time_io.html#io_objects.date_generators">date_generator_formatter</a>.</td> 708</tr> 709<tr><td><pre class="screen">"first Wed of Jun" // defaults</pre></td></tr> 710<tr> 711<td rowspan="2" valign="top"><pre class="screen">OutItrT put(..., date_generator) 712 Date Generator Type: 713 last_day_of_the_week_in_month</pre></td> 714<td>Puts a last_day_of_the_week_in_month object into the stream. The month format is set by <code class="computeroutput">month_format(...)</code> or the default. The weekday format is set by <code class="computeroutput">weekday_format(...)</code> or the default. The remaining phrase elements are set in the <a class="link" href="date_time_io.html#io_objects.date_generators">date_generator_formatter</a>.</td> 715</tr> 716<tr><td><pre class="screen">"last Tue of Mar" // defaults</pre></td></tr> 717<tr> 718<td rowspan="2" valign="top"><pre class="screen">OutItrT put(..., date_generator) 719 Date Generator Type: 720 first_day_of_the_week_after</pre></td> 721<td>Puts a first_day_of_the_week_after object into the stream. The weekday format is set by <code class="computeroutput">weekday_format(...)</code> or the default. The remaining phrase elements are set in the <a class="link" href="date_time_io.html#io_objects.date_generators">date_generator_formatter</a>.</td> 722</tr> 723<tr><td><pre class="screen">"first Sat after" // defaults</pre></td></tr> 724<tr> 725<td rowspan="2" valign="top"><pre class="screen">OutItrT put(..., date_generator) 726 Date Generator Type: 727 first_day_of_the_week_before</pre></td> 728<td>Puts a first_day_of_the_week_before object into the stream. The weekday format is set by <code class="computeroutput">weekday_format(...)</code> or the default. The remaining phrase elements are set in the <a class="link" href="date_time_io.html#io_objects.date_generators">date_generator_formatter</a>.</td> 729</tr> 730<tr><td><pre class="screen">"first Mon before" // defaults</pre></td></tr> 731</tbody> 732</table></div> 733<p> 734 </p> 735</div> 736<div class="section"> 737<div class="titlepage"><div><div><h3 class="title"> 738<a name="date_time.date_input_facet"></a>Date Input Facet</h3></div></div></div> 739<a class="link" href="date_time_io.html#date_input_facet_intro">Introduction</a> - 740 <a class="link" href="date_time_io.html#date_input_facet_constr">Construction</a> - 741 <a class="link" href="date_time_io.html#date_input_facet_accessors">Accessors</a><a name="date_input_facet_intro"></a><h4> 742<a name="id-1.3.14.11.23.6"></a>Introduction</h4> 743<p>The <code class="computeroutput">boost::date_time::date_input_facet</code> enables users to have significant control how dates (and other gregorian objects) are streamed in. The date_input_facet is typedef'd in the <code class="computeroutput">gregorian</code> namespace as <code class="computeroutput">date_input_facet</code> and <code class="computeroutput">wdate_input_facet</code>. 744 </p> 745<a name="date_input_facet_constr"></a><h4> 746<a name="id-1.3.14.11.23.9"></a>Construction</h4> 747<p> 748 </p> 749<div class="informaltable"><table class="table"> 750<colgroup> 751<col> 752<col> 753</colgroup> 754<thead><tr> 755<th>Syntax</th> 756<th>Description</th> 757</tr></thead> 758<tbody> 759<tr> 760<td valign="top"><pre class="screen">date_input_facet()</pre></td> 761<td>Default constructor</td> 762</tr> 763<tr> 764<td valign="top"><pre class="screen">date_input_facet(string_type format)</pre></td> 765<td>Format given will be used for date input. All other formats will use their defaults.</td> 766</tr> 767<tr> 768<td valign="top"><pre class="screen">date_input_facet(...) 769 Parameters: 770 string_type format 771 format_date_parser_type 772 special_values_parser_type 773 period_parser_type 774 date_gen_parser_type</pre></td> 775<td>Format given will be used for date input. The remaining parameters are parser objects. Further details on these objects can be found <a class="link" href="date_time_io.html#date_time.io_objects" title="Date Time Formatter/Parser Objects">here</a>.</td> 776</tr> 777</tbody> 778</table></div> 779<p> 780 </p> 781<a name="date_input_facet_accessors"></a><h4> 782<a name="id-1.3.14.11.23.12"></a>Accessors</h4> 783<p> 784 </p> 785<div class="informaltable"><table class="table"> 786<colgroup> 787<col> 788<col> 789</colgroup> 790<thead> 791<tr> 792<th rowspan="2" valign="top">Syntax</th> 793<th>Description</th> 794</tr> 795<tr><th>Example</th></tr> 796</thead> 797<tbody> 798<tr> 799<td rowspan="2" valign="top"><pre class="screen">void format(char_type*)</pre></td> 800<td>Set the format for dates.</td> 801</tr> 802<tr><td><pre class="screen">date_input_facet* f = 803 new date_input_facet(); 804f->format("%m %d %Y");</pre></td></tr> 805<tr> 806<td rowspan="2" valign="top"><pre class="screen">void set_iso_format()</pre></td> 807<td>Sets the date format to ISO</td> 808</tr> 809<tr><td><pre class="screen">f->set_iso_format(); 810// "%Y%m%d"</pre></td></tr> 811<tr> 812<td rowspan="2" valign="top"><pre class="screen">void set_iso_extended_format()</pre></td> 813<td>Sets the date format to ISO Extended</td> 814</tr> 815<tr><td><pre class="screen">f->set_iso_extended_format(); 816// "%Y-%m-%d"</pre></td></tr> 817<tr> 818<td rowspan="2" valign="top"><pre class="screen">void month_format(char_type*)</pre></td> 819<td>Set the format when 'get'ing months individually.</td> 820</tr> 821<tr><td><pre class="screen">f->month_format("%B"); 822ss.str("March"); 823ss >> m; // March</pre></td></tr> 824<tr> 825<td rowspan="2" valign="top"><pre class="screen">void weekday_format(char_type*)</pre></td> 826<td>Set the format when 'get'ing weekdays individually.</td> 827</tr> 828<tr><td><pre class="screen">f->weekday_format("%a"); 829ss.str("Sun"); 830ss >> wd; // Sunday</pre></td></tr> 831<tr> 832<td rowspan="2" valign="top"><pre class="screen">void year_format(char_type*)</pre></td> 833<td>Set the format when 'get'ing years individually.</td> 834</tr> 835<tr><td><pre class="screen">f->weekday_format("%y"); 836ss.str("04"); 837ss >> year; // 2004</pre></td></tr> 838<tr> 839<td rowspan="2" valign="top"><pre class="screen">void period_parser(...) 840 Parameter: 841 period_parser_type</pre></td> 842<td>Replaces the period parser object with a user created one.</td> 843</tr> 844<tr><td>see the <a class="link" href="date_time_io.html#date_time.io_tutorial" title="Date Time IO Tutorial">tutorial</a> for a complete example.</td></tr> 845<tr> 846<td rowspan="2" valign="top"><pre class="screen">void special_values_parser(...) 847 Parameter: 848 special_values_parser_type</pre></td> 849<td>Replaces the special_values parser object with a user created one.</td> 850</tr> 851<tr><td>see the <a class="link" href="date_time_io.html#date_time.io_tutorial" title="Date Time IO Tutorial">tutorial</a> for a complete example.</td></tr> 852<tr> 853<td rowspan="2" valign="top"><pre class="screen">void date_gen_phrase_strings(...) 854 Parameters: 855 input_collection_type</pre></td> 856<td>Sets new date generator phrase strings in date_gen_parser. The input collection is a vector of strings (for details on these strings see <a class="link" href="date_time_io.html#io_objects.date_generators">date generator formatter/parser documentation</a>).</td> 857</tr> 858<tr><td><pre class="screen"></pre></td></tr> 859<tr> 860<td rowspan="2" valign="top"><pre class="screen">void short_weekday_names(...) 861 Parameter: 862 input_collection_type</pre></td> 863<td>Replace strings used when 'getting' short weekdays.</td> 864</tr> 865<tr><td>see the <a class="link" href="date_time_io.html#date_time.io_tutorial" title="Date Time IO Tutorial">tutorial</a> for a complete example.</td></tr> 866<tr> 867<td rowspan="2" valign="top"><pre class="screen">void long_weekday_names(...) 868 Parameter: 869 input_collection_type</pre></td> 870<td>Replace strings used when 'getting' long weekdays.</td> 871</tr> 872<tr><td>see the <a class="link" href="date_time_io.html#date_time.io_tutorial" title="Date Time IO Tutorial">tutorial</a> for a complete example.</td></tr> 873<tr> 874<td rowspan="2" valign="top"><pre class="screen">void short_month_names(...) 875 Parameter: 876 input_collection_type</pre></td> 877<td>Replace strings used when 'getting' short months.</td> 878</tr> 879<tr><td>see the <a class="link" href="date_time_io.html#date_time.io_tutorial" title="Date Time IO Tutorial">tutorial</a> for a complete example.</td></tr> 880<tr> 881<td rowspan="2" valign="top"><pre class="screen">void long_month_names(...) 882 Parameter: 883 input_collection_type</pre></td> 884<td>Replace strings used when 'getting' long months.</td> 885</tr> 886<tr><td>see the <a class="link" href="date_time_io.html#date_time.io_tutorial" title="Date Time IO Tutorial">tutorial</a> for a complete example.</td></tr> 887<tr> 888<td rowspan="2" valign="top"><pre class="screen">InItrT get(...) 889 Common parameters for all 890 'get' functions: 891 InItrT from 892 InItrT to 893 ios_base 894 Unique parameter for 'get' funcs: 895 gregorian object</pre></td> 896<td>There are 13 get functions in the date_input_facet. The common parameters are: an iterator pointing to the begining of the stream, an iterator pointing to the end of the stream, and an ios_base object. Each unique gregorian object has it's own get function. Each unique get function is described below.</td> 897</tr> 898<tr><td><pre class="screen"></pre></td></tr> 899<tr> 900<td rowspan="2" valign="top"><pre class="screen">InItrT get(..., date)</pre></td> 901<td>Gets a date object from the stream using the format set by <code class="computeroutput">format(...)</code> or the default.</td> 902</tr> 903<tr><td><pre class="screen">ss.str("2005-Jan-01"); 904ss >> d; // default format</pre></td></tr> 905<tr> 906<td rowspan="2" valign="top"><pre class="screen">InItrT get(..., month)</pre></td> 907<td>Gets a month object from the stream using the format set by <code class="computeroutput">month_format(...)</code> or the default.</td> 908</tr> 909<tr><td><pre class="screen">ss.str("Feb"); 910ss >> m; // default format</pre></td></tr> 911<tr> 912<td rowspan="2" valign="top"><pre class="screen">InItrT get(..., day_of_week)</pre></td> 913<td>Gets a day of week object from the stream using the format set by <code class="computeroutput">weekday_format(...)</code> or the default.</td> 914</tr> 915<tr><td><pre class="screen">ss.str("Sun"); 916ss >> dow; // default format</pre></td></tr> 917<tr> 918<td rowspan="2" valign="top"><pre class="screen">InItrT get(..., day)</pre></td> 919<td>Gets a day of month object from the stream as a two digit number.</td> 920</tr> 921<tr><td><pre class="screen">"01" // January 1st</pre></td></tr> 922<tr> 923<td rowspan="2" valign="top"><pre class="screen">InItrT get(..., year)</pre></td> 924<td>Gets a year object from the stream as a number. The number of expected digits depends on the year format.</td> 925</tr> 926<tr><td><pre class="screen">ss/str("2005"); 927ss >> y; // default format</pre></td></tr> 928<tr> 929<td rowspan="2" valign="top"><pre class="screen">InItrT get(..., days)</pre></td> 930<td>Gets a days object from the stream as a number.</td> 931</tr> 932<tr><td><pre class="screen">ss.str("356"); 933ss >> dys; // a full year</pre></td></tr> 934<tr> 935<td rowspan="2" valign="top"><pre class="screen">InItrT get(..., date_period)</pre></td> 936<td>Gets a date_period from the stream. The format of the dates will use the format set by <code class="computeroutput">format(..)</code> or the default date format. The type of period (open or closed range) and the delimiters used are those used by the period_parser.</td> 937</tr> 938<tr><td>see the <a class="link" href="date_time_io.html#date_time.io_tutorial" title="Date Time IO Tutorial">tutorial</a> for a complete example.</td></tr> 939<tr> 940<td rowspan="2" valign="top"><pre class="screen">InItrT get(..., partial_date)</pre></td> 941<td>Gets a partial_date date_generator object from the stream. The month format used is set by <code class="computeroutput">month_format(..)</code> or the default. The day of month is represented as a two digit number.</td> 942</tr> 943<tr><td><pre class="screen">"01 Jan" // default formats 944"01 January" // long month format</pre></td></tr> 945<tr> 946<td rowspan="2" valign="top"><pre class="screen">InItrT get(..., date_generator) 947 Date Generator Type: 948 nth_day_of_the_week_in_month</pre></td> 949<td>Gets a nth_day_of_the_week_in_month object from the stream. The month format is set by <code class="computeroutput">month_format(...)</code> or the default. The weekday format is set by <code class="computeroutput">weekday_format(...)</code> or the default. The remaining phrase elements are set in the <a class="link" href="date_time_io.html#io_objects.date_generators">date_generator_parser</a>.</td> 950</tr> 951<tr><td><pre class="screen">"third Fri in May" // defaults</pre></td></tr> 952<tr> 953<td rowspan="2" valign="top"><pre class="screen">InItrT get(..., date_generator) 954 Date Generator Type: 955 first_day_of_the_week_in_month</pre></td> 956<td>Gets a first_day_of_the_week_in_month object from the stream. The month format is set by <code class="computeroutput">month_format(...)</code> or the default. The weekday format is set by <code class="computeroutput">weekday_format(...)</code> or the default. The remaining phrase elements are set in the <a class="link" href="date_time_io.html#io_objects.date_generators">date_generator_parser</a>.</td> 957</tr> 958<tr><td><pre class="screen">"first Wed of Jun" // defaults</pre></td></tr> 959<tr> 960<td rowspan="2" valign="top"><pre class="screen">InItrT get(..., date_generator) 961 Date Generator Type: 962 last_day_of_the_week_in_month</pre></td> 963<td>Gets a last_day_of_the_week_in_month object from the stream. The month format is set by <code class="computeroutput">month_format(...)</code> or the default. The weekday format is set by <code class="computeroutput">weekday_format(...)</code> or the default. The remaining phrase elements are set in the <a class="link" href="date_time_io.html#io_objects.date_generators">date_generator_parser</a>.</td> 964</tr> 965<tr><td><pre class="screen">"last Tue of Mar" // defaults</pre></td></tr> 966<tr> 967<td rowspan="2" valign="top"><pre class="screen">InItrT get(..., date_generator) 968 Date Generator Type: 969 first_day_of_the_week_after</pre></td> 970<td>Gets a first_day_of_the_week_after object from the stream. The weekday format is set by <code class="computeroutput">weekday_format(...)</code> or the default. The remaining phrase elements are set in the <a class="link" href="date_time_io.html#io_objects.date_generators">date_generator_parser</a>.</td> 971</tr> 972<tr><td><pre class="screen">"first Sat after" // defaults</pre></td></tr> 973<tr> 974<td rowspan="2" valign="top"><pre class="screen">InItrT get(..., date_generator) 975 Date Generator Type: 976 first_day_of_the_week_before</pre></td> 977<td>Gets a first_day_of_the_week_before object from the stream. The weekday format is set by <code class="computeroutput">weekday_format(...)</code> or the default. The remaining phrase elements are set in the <a class="link" href="date_time_io.html#io_objects.date_generators">date_generator_parser</a>.</td> 978</tr> 979<tr><td><pre class="screen">"first Mon before" // defaults</pre></td></tr> 980</tbody> 981</table></div> 982<p> 983 </p> 984</div> 985<div class="section"> 986<div class="titlepage"><div><div><h3 class="title"> 987<a name="date_time.time_facet"></a>Time Facet</h3></div></div></div> 988<a class="link" href="date_time_io.html#time_facet_intro">Introduction</a> - 989 <a class="link" href="date_time_io.html#time_facet_constr">Construction</a> - 990 <a class="link" href="date_time_io.html#time_facet_accessors">Accessors</a><a name="time_facet_intro"></a><h4> 991<a name="id-1.3.14.11.24.6"></a>Introduction</h4> 992<p>The <code class="computeroutput">boost::date_time::time_facet</code> is an extension of the <code class="computeroutput">boost::date_time::date_facet</code>. The time_facet is typedef'ed in the <code class="computeroutput">posix_time</code> namespace as <code class="computeroutput">time_facet</code> and <code class="computeroutput">wtime_facet</code>. It is typedef'd in the <code class="computeroutput">local_time</code> namespace as <code class="computeroutput">local_time_facet</code> and <code class="computeroutput">wlocal_time_facet</code>. 993 </p> 994<a name="time_facet_constr"></a><h4> 995<a name="id-1.3.14.11.24.9"></a>Construction</h4> 996<p> 997 </p> 998<div class="informaltable"><table class="table"> 999<colgroup> 1000<col> 1001<col> 1002</colgroup> 1003<thead><tr> 1004<th>Syntax</th> 1005<th>Description</th> 1006</tr></thead> 1007<tbody> 1008<tr> 1009<td valign="top"><pre class="screen">time_facet()</pre></td> 1010<td>Default constructor</td> 1011</tr> 1012<tr> 1013<td valign="top"><pre class="screen">time_facet(...) 1014 Parameters: 1015 char_type* format 1016 period_formatter_type 1017 special_values_formatter_type 1018 date_gen_formatter_type</pre></td> 1019<td>Format given will be used for time output. The remaining parameters are formatter objects. Further details on these objects can be found <a class="link" href="date_time_io.html#date_time.io_objects" title="Date Time Formatter/Parser Objects">here</a>. This constructor also provides default arguments for all parameters except the format. Therefore, <code class="computeroutput">time_facet("%H:%M:S %m %d %Y")</code> will work.</td> 1020</tr> 1021</tbody> 1022</table></div> 1023<p> 1024 </p> 1025<a name="time_facet_accessors"></a><h4> 1026<a name="id-1.3.14.11.24.12"></a>Accessors</h4> 1027<p> 1028 The time_facet inherits all the public date_facet methods. Therefore, the date_facet methods are not listed here. Instead, they can be found by following <a class="link" href="date_time_io.html#date_time.date_facet" title="Date Facet">this</a> link. 1029 </p> 1030<div class="informaltable"><table class="table"> 1031<colgroup> 1032<col> 1033<col> 1034</colgroup> 1035<thead> 1036<tr> 1037<th rowspan="2" valign="top">Syntax</th> 1038<th>Description</th> 1039</tr> 1040<tr><th>Example</th></tr> 1041</thead> 1042<tbody> 1043<tr> 1044<td rowspan="2" valign="top"><pre class="screen">void time_duration_format(...) 1045 Parameter: 1046 char_type*</pre></td> 1047<td>Sets the time_duration format. The time_duration format has the ability to display the sign of the duration. The <code class="computeroutput">'%+'</code> flag will always display the sign. The <code class="computeroutput">'%-'</code> will only display if the sign is negative. Currently the '-' and '+' characters are used to denote the sign.</td> 1048</tr> 1049<tr><td><pre class="screen">f->time_duration_format("%+%H:%M"); 1050// hours and minutes only w/ sign always displayed 1051time_duration td1(3, 15, 56); 1052time_duration td2(-12, 25, 32); 1053ss << td1; // "+03:15:56" 1054ss << td2; // "-12:25:56" 1055 </pre></td></tr> 1056<tr> 1057<td rowspan="2" valign="top"><pre class="screen">void set_iso_format()</pre></td> 1058<td>Sets the date and time format to ISO.</td> 1059</tr> 1060<tr><td><pre class="screen">f->set_iso_format(); 1061// "%Y%m%dT%H%M%S%F%q"</pre></td></tr> 1062<tr> 1063<td rowspan="2" valign="top"><pre class="screen">void set_iso_extended_format()</pre></td> 1064<td>Sets the date and time format to ISO Extended</td> 1065</tr> 1066<tr><td><pre class="screen">f->set_iso_extended_format(); 1067// "%Y-%m-%d %H:%M:%S%F%Q"</pre></td></tr> 1068<tr> 1069<td rowspan="2" valign="top"><pre class="screen">OutItrT put(...) 1070 Common parameters for all 1071 'put' functions: 1072 OutItrT 1073 ios_base 1074 char_type 1075 Unique parameter for 'put' funcs: 1076 posix_time object</pre></td> 1077<td>There are 3 put functions in the time_facet. The common parameters are: an iterator pointing to the next item in the stream, an ios_base object, and the fill character. Each unique posix_time object has it's own put function. Each unique put function is described below.</td> 1078</tr> 1079<tr><td><pre class="screen"></pre></td></tr> 1080<tr> 1081<td rowspan="2" valign="top"><pre class="screen">OutItrT put(..., ptime)</pre></td> 1082<td>Puts a ptime object into the stream using the format set by <code class="computeroutput">format(...)</code> or the default.</td> 1083</tr> 1084<tr><td><pre class="screen"></pre></td></tr> 1085<tr> 1086<td rowspan="2" valign="top"><pre class="screen">OutItrT put(..., time_duration)</pre></td> 1087<td>Puts a time_duration object into the stream using the format set by <code class="computeroutput">time_duration_format(...)</code> or the default.</td> 1088</tr> 1089<tr><td><pre class="screen"></pre></td></tr> 1090<tr> 1091<td rowspan="2" valign="top"><pre class="screen">OutItrT put(..., time_period)</pre></td> 1092<td>Puts a time_period into the stream. The format of the dates and times will use the format set by <code class="computeroutput">format(..)</code> or the default date/time format. The type of period (open or closed range) and the delimiters used are those used by the period_formatter.</td> 1093</tr> 1094<tr><td><pre class="screen"></pre></td></tr> 1095</tbody> 1096</table></div> 1097<p> 1098 </p> 1099</div> 1100<div class="section"> 1101<div class="titlepage"><div><div><h3 class="title"> 1102<a name="date_time.time_input_facet"></a>Time Input Facet</h3></div></div></div> 1103<a class="link" href="date_time_io.html#time_input_facet_intro">Introduction</a> - 1104 <a class="link" href="date_time_io.html#time_input_facet_constr">Construction</a> - 1105 <a class="link" href="date_time_io.html#time_input_facet_accessors">Accessors</a><a name="time_input_facet_intro"></a><h4> 1106<a name="id-1.3.14.11.25.6"></a>Introduction</h4> 1107<p>The <code class="computeroutput">boost::date_time::time_input_facet</code> is an extension of the <code class="computeroutput">date_input_facet</code>. It is typedef'ed in the <code class="computeroutput">boost::posix_time</code> namespace as <code class="computeroutput">time_input_facet</code> and <code class="computeroutput">wtime_input_facet</code>. It is typedef'ed in the <code class="computeroutput">boost::local_time</code> namespace as <code class="computeroutput">local_time_input_facet</code> and <code class="computeroutput">wlocal_time_input_facet</code>. 1108 </p> 1109<a name="time_input_facet_constr"></a><h4> 1110<a name="id-1.3.14.11.25.9"></a>Construction</h4> 1111<p> 1112 </p> 1113<div class="informaltable"><table class="table"> 1114<colgroup> 1115<col> 1116<col> 1117</colgroup> 1118<thead><tr> 1119<th>Syntax</th> 1120<th>Description</th> 1121</tr></thead> 1122<tbody> 1123<tr> 1124<td valign="top"><pre class="screen">time_input_facet()</pre></td> 1125<td>Default constructor</td> 1126</tr> 1127<tr> 1128<td valign="top"><pre class="screen">time_input_facet(string_type)</pre></td> 1129<td>Format given will be used for date/time input. All other formats will use their defaults.</td> 1130</tr> 1131<tr> 1132<td valign="top"><pre class="screen">time_input_facet(...) 1133 Parameters: 1134 string_type format 1135 format_date_parser_type 1136 special_values_parser_type 1137 period_parser_type 1138 date_gen_parser_type</pre></td> 1139<td>Format given will be used for date/time input. The remaining parameters are parser objects. Further details on these objects can be found <a class="link" href="date_time_io.html#date_time.io_objects" title="Date Time Formatter/Parser Objects">here</a>.</td> 1140</tr> 1141</tbody> 1142</table></div> 1143<p> 1144 </p> 1145<a name="time_input_facet_accessors"></a><h4> 1146<a name="id-1.3.14.11.25.12"></a>Accessors</h4> 1147<p> 1148 The time_input_facet inherits all the public date_input_facet methods. Therefore, the date_input_facet methods are not listed here. Instead, they can be found by following <a class="link" href="date_time_io.html#date_time.date_input_facet" title="Date Input Facet">this</a> link. 1149 </p> 1150<div class="informaltable"><table class="table"> 1151<colgroup> 1152<col> 1153<col> 1154</colgroup> 1155<thead> 1156<tr> 1157<th rowspan="2" valign="top">Syntax</th> 1158<th>Description</th> 1159</tr> 1160<tr><th>Example</th></tr> 1161</thead> 1162<tbody> 1163<tr> 1164<td rowspan="2" valign="top"><pre class="screen">void set_iso_format()</pre></td> 1165<td>Sets the time format to ISO</td> 1166</tr> 1167<tr><td><pre class="screen">f->set_iso_format(); 1168// "%Y%m%dT%H%M%S%F%q" 1169"20051225T132536.789-0700"</pre></td></tr> 1170<tr> 1171<td rowspan="2" valign="top"><pre class="screen">void set_iso_extended_format()</pre></td> 1172<td>Sets the date format to ISO Extended</td> 1173</tr> 1174<tr><td><pre class="screen">f->set_iso_extended_format(); 1175// "%Y-%m-%d %H:%M:%S%F %Q" 1176"2005-12-25 13:25:36.789 -07:00"</pre></td></tr> 1177<tr> 1178<td rowspan="2" valign="top"><pre class="screen">void time_duration_format(...) 1179 Parameter: 1180 char_type*</pre></td> 1181<td>Sets the time_duration format.</td> 1182</tr> 1183<tr><td><pre class="screen">f->time_duration_format("%H:%M"); 1184// hours and minutes only</pre></td></tr> 1185<tr> 1186<td rowspan="2" valign="top"><pre class="screen">InItrT get(...) 1187 Common parameters for all 1188 'get' functions: 1189 InItrT from 1190 InItrT to 1191 ios_base 1192 Unique parameter for 'get' funcs: 1193 gregorian object</pre></td> 1194<td>There are 3 get functions in the time_input_facet. The common parameters are: an iterator pointing to the begining of the stream, an iterator pointing to the end of the stream, and an ios_base object. Each unique gregorian object has it's own get function. Each unique get function is described below.</td> 1195</tr> 1196<tr><td><pre class="screen"></pre></td></tr> 1197<tr> 1198<td rowspan="2" valign="top"><pre class="screen">InItrT get(..., ptime)</pre></td> 1199<td>Gets a ptime object from the stream using the format set by <code class="computeroutput">format(...)</code> or the default.</td> 1200</tr> 1201<tr><td><pre class="screen">ss.str("2005-Jan-01 13:12:01"); 1202ss >> pt; // default format</pre></td></tr> 1203<tr> 1204<td rowspan="2" valign="top"><pre class="screen">InItrT get(..., time_duration)</pre></td> 1205<td>Gets a time_duration object from the stream using the format set by <code class="computeroutput">time_duration_format(...)</code> or the default.</td> 1206</tr> 1207<tr><td><pre class="screen">ss.str("01:25:15.000123000"); 1208ss >> td; // default format</pre></td></tr> 1209<tr> 1210<td rowspan="2" valign="top"><pre class="screen">InItrT get(..., time_period)</pre></td> 1211<td>Gets a time_period from the stream. The format of the dates/times will use the format set by <code class="computeroutput">format(..)</code> or the default date and time format. The type of period (open or closed range) and the delimiters used are those used by the period_parser.</td> 1212</tr> 1213<tr><td>see the <a class="link" href="date_time_io.html#date_time.io_tutorial" title="Date Time IO Tutorial">tutorial</a> for a complete example.</td></tr> 1214</tbody> 1215</table></div> 1216<p> 1217 </p> 1218</div> 1219<div class="section"> 1220<div class="titlepage"><div><div><h3 class="title"> 1221<a name="date_time.io_objects"></a>Date Time Formatter/Parser Objects</h3></div></div></div> 1222<h3> 1223<a name="id-1.3.14.11.26.2"></a>Date Time Formatter/Parser Objects</h3> 1224<a class="link" href="date_time_io.html#io_objects.periods">Periods</a> | 1225 <a class="link" href="date_time_io.html#io_objects.date_generators">Date Generators</a> | 1226 <a class="link" href="date_time_io.html#io_objects.special_values">Special Values</a> | 1227 <a class="link" href="date_time_io.html#io_objects.format_date_parser">Format Date Parser</a><a name="io_objects.periods"></a><h4> 1228<a name="id-1.3.14.11.26.8"></a>Periods</h4> 1229<p>The period_formatter and period_parser provide a uniform interface for the input and output of date_periods, time_periods, and in a future release, local_date_time_periods. The user has control over the delimiters, formats of the date/time components, and the form the period takes. The format of the date/time components is controlled via the date_time input and output facets.</p> 1230<h5> 1231<a name="id-1.3.14.11.26.10"></a>Period Form</h5> 1232<p>Periods are constructed with open ranged parameters. The first value is the starting point, and is included in the period. The end value is not included but immediately follows the last value: [begin/end). However, a period can be streamed as either an open range or a closed range.</p> 1233<pre class="screen">[2003-Jan-01/2003-Dec-31] <-- period holding 365 days 1234[2003-Jan-01/2004-Jan-01) <-- period holding 365 days</pre> 1235<h5> 1236<a name="id-1.3.14.11.26.13"></a>Delimiters</h5> 1237<p>There are four delimiters. The default values are</p> 1238<table border="0" summary="Simple list" class="simplelist"> 1239<tr><td>"\" - separator</td></tr> 1240<tr><td>"[" - start delimiter</td></tr> 1241<tr><td>")" - open range end delimiter</td></tr> 1242<tr><td>"]" - closed range end delimiter</td></tr> 1243</table> 1244<p>A user can provide a custom set of delimiters. Custom delimiters may contain spaces.</p> 1245<h5> 1246<a name="id-1.3.14.11.26.15"></a>Customization</h5> 1247<p>The period form and delimiters can be set as construction parameters or by means of accessor functions. A custom period parser/formatter can then be used as a construction parameter to a new facet, or can be set in an existing facet via an accessor function.</p> 1248<h5> 1249<a name="id-1.3.14.11.26.17"></a>Period Formatter/Parser Reference</h5> 1250 The complete class reference can be found here: <code class="computeroutput"><a class="link" href="../boost/date_time/period_formatter.html" title="Class template period_formatter">Period Formatter Doxygen Reference</a></code> and here: <code class="computeroutput"><a class="link" href="../boost/date_time/period_parser.html" title="Class template period_parser">Period Parser Doxygen Reference</a></code><p> 1251 </p> 1252<h5> 1253<a name="id-1.3.14.11.26.20.1"></a>Period Formatter Construction</h5> 1254<p> 1255 </p> 1256<div class="informaltable"><table class="table"> 1257<colgroup> 1258<col> 1259<col> 1260</colgroup> 1261<thead><tr> 1262<th valign="top">Syntax</th> 1263<th>Description</th> 1264</tr></thead> 1265<tbody><tr> 1266<td valign="top"><pre class="screen">period_formatter(...) 1267 Parameters: 1268 range_display_options 1269 char_type* 1270 char_type* 1271 char_type* 1272 char_type*</pre></td> 1273<td>NOTE: All five construction parameters have default values so this constructor also doubles as the default constructor. The <code class="computeroutput">range_display_options</code> is a public type enum of the <code class="computeroutput">period_formatter</code> class. The possible choices are AS_OPEN_RANGE or AS_CLOSED_RANGE. The closed range is the default. A period has three significant points: the begining, the last, and the end. A closed range period takes the form [begin,end), where an open range period takes the form [begin,last]. The four char_type* parameters are: the period separator, the start delimiter, the open range end delimiter, and the closed range end delimiter.</td> 1274</tr></tbody> 1275</table></div> 1276<p> 1277 </p> 1278<h5> 1279<a name="id-1.3.14.11.26.20.3"></a>Period Formatter Accessors</h5> 1280<p> 1281 </p> 1282<div class="informaltable"><table class="table"> 1283<colgroup> 1284<col> 1285<col> 1286</colgroup> 1287<thead> 1288<tr> 1289<th rowspan="2" valign="top">Syntax</th> 1290<th>Description</th> 1291</tr> 1292<tr><th>Example</th></tr> 1293</thead> 1294<tbody> 1295<tr> 1296<td rowspan="2" valign="top"><pre class="screen">range_display_options range_option()</pre></td> 1297<td>Returns the current setting for the range display (either AS_OPEN_RANGE or AS_CLOSED_RANGE).</td> 1298</tr> 1299<tr><td><pre class="screen"></pre></td></tr> 1300<tr> 1301<td rowspan="2" valign="top"><pre class="screen">void range_option(...) 1302 Parameter: 1303 range_display_options</pre></td> 1304<td>Sets the option for range display (either AS_OPEN_RANGE or AS_CLOSED_RANGE).</td> 1305</tr> 1306<tr><td><pre class="screen"></pre></td></tr> 1307<tr> 1308<td rowspan="2" valign="top"><pre class="screen">void delimiter_strings(...) 1309 Parameters: 1310 string_type 1311 string_type 1312 string_type 1313 string_type</pre></td> 1314<td>Set new delimiter strings in the formatter.</td> 1315</tr> 1316<tr><td><pre class="screen">string beg("->| "); 1317string sep(" || "); 1318string opn(" ->|"); 1319string clo(" |<-"); 1320pf.delimiter_strings(beg, sep, 1321 opn, clo);</pre></td></tr> 1322<tr> 1323<td rowspan="2" valign="top"><pre class="screen">put_period_start_delimeter(...) 1324 Return Type: 1325 OutItrT 1326 Parameter: 1327 OutItrT</pre></td> 1328<td>Puts the start delimiter into the stream at position pointed to by OutItrT parameter.</td> 1329</tr> 1330<tr><td><pre class="screen"></pre></td></tr> 1331<tr> 1332<td rowspan="2" valign="top"><pre class="screen">put_period_sepatator(...) 1333 Return Type: 1334 OutItrT 1335 Parameter: 1336 OutItrT</pre></td> 1337<td>Puts the separator into the stream at position pointed to by OutItrT parameter.</td> 1338</tr> 1339<tr><td><pre class="screen"></pre></td></tr> 1340<tr> 1341<td rowspan="2" valign="top"><pre class="screen">put_period_end_delimeter(...) 1342 Return Type: 1343 OutItrT 1344 Parameter: 1345 OutItrT</pre></td> 1346<td>Puts the end delimiter into the stream at position pointed to by OutItrT parameter.</td> 1347</tr> 1348<tr><td><pre class="screen"></pre></td></tr> 1349<tr> 1350<td rowspan="2" valign="top"><pre class="screen">OutItrT put_period(...) 1351 Parameters: 1352 OutItrT 1353 ios_base 1354 char_type 1355 period_type 1356 facet_type</pre></td> 1357<td>Puts a period into the stream using the set values for delimiters, separator, and range display. The facet parameter is used to put the date (or time) objects of the period.</td> 1358</tr> 1359<tr><td><pre class="screen"></pre></td></tr> 1360</tbody> 1361</table></div> 1362<p> 1363 </p> 1364<p> 1365 </p> 1366<h5> 1367<a name="id-1.3.14.11.26.21.1"></a>Period Parser Construction</h5> 1368<p> 1369 </p> 1370<div class="informaltable"><table class="table"> 1371<colgroup> 1372<col> 1373<col> 1374</colgroup> 1375<thead><tr> 1376<th valign="top">Syntax</th> 1377<th>Description</th> 1378</tr></thead> 1379<tbody> 1380<tr> 1381<td valign="top"><pre class="screen">period_parser(...) 1382 Parameters: 1383 period_range_option 1384 char_type* 1385 char_type* 1386 char_type* 1387 char_type*</pre></td> 1388<td>NOTE: All five construction parameters have default values so this constructor also doubles as the default constructor. The <code class="computeroutput">period_range_option</code> is a public type enum of the <code class="computeroutput">period_parser</code> class. The possible choices are AS_OPEN_RANGE or AS_CLOSED_RANGE. The closed range is the default. A period has three significant points: the begining, the last, and the end. A closed range period takes the form [begin,end), where an open range period takes the form [begin,last]. The four char_type* parameters are: the period separator, the start delimiter, the open range end delimiter, and the closed range end delimiter.</td> 1389</tr> 1390<tr> 1391<td valign="top"><pre class="screen">period_parser(period_parser)</pre></td> 1392<td>Copy constructor</td> 1393</tr> 1394</tbody> 1395</table></div> 1396<p> 1397 </p> 1398<h5> 1399<a name="id-1.3.14.11.26.21.3"></a>Period Parser Accessors</h5> 1400<p> 1401 </p> 1402<div class="informaltable"><table class="table"> 1403<colgroup> 1404<col> 1405<col> 1406</colgroup> 1407<thead> 1408<tr> 1409<th rowspan="2" valign="top">Syntax</th> 1410<th>Description</th> 1411</tr> 1412<tr><th>Example</th></tr> 1413</thead> 1414<tbody> 1415<tr> 1416<td rowspan="2" valign="top"><pre class="screen">period_range_option range_option()</pre></td> 1417<td>Returns the current setting for the period range (either AS_OPEN_RANGE or AS_CLOSED_RANGE).</td> 1418</tr> 1419<tr><td><pre class="screen"></pre></td></tr> 1420<tr> 1421<td rowspan="2" valign="top"><pre class="screen">void range_option(...) 1422 Parameter: 1423 period_range_option </pre></td> 1424<td>Sets the option for period range (either AS_OPEN_RANGE or AS_CLOSED_RANGE).</td> 1425</tr> 1426<tr><td><pre class="screen"></pre></td></tr> 1427<tr> 1428<td rowspan="2" valign="top"><pre class="screen">void delimiter_strings(...) 1429 Parameters: 1430 string_type 1431 string_type 1432 string_type 1433 string_type</pre></td> 1434<td>Set new delimiter strings in the parser.</td> 1435</tr> 1436<tr><td><pre class="screen">string beg("->| "); 1437string sep(" || "); 1438string opn(" ->|"); 1439string clo(" |<-"); 1440pp.delimiter_strings(beg, sep, 1441 opn, clo);</pre></td></tr> 1442<tr> 1443<td rowspan="2" valign="top"><pre class="screen">collection_type delimiter_strings()</pre></td> 1444<td>Returns the set of delimiter strings currently held in the parser.</td> 1445</tr> 1446<tr><td><pre class="screen"></pre></td></tr> 1447<tr> 1448<td rowspan="2" valign="top"><pre class="screen">period_type get_period(...) 1449 Parameters: 1450 stream_itr_type 1451 stream_itr_type 1452 ios_base 1453 period_type 1454 duration_type 1455 facet_type</pre></td> 1456<td>Parses a period from the stream. The iterator parameters point to the begining and end of the stream. The duration_type is relevant to the period type, for example: A <code class="computeroutput">date_period</code> would use <code class="computeroutput">days</code> as a duration_type. The period will be parsed according to the formats and strings found in the facet parameter.</td> 1457</tr> 1458<tr><td><pre class="screen"></pre></td></tr> 1459</tbody> 1460</table></div> 1461<p> 1462 </p> 1463<p>_____________________________________________________</p> 1464<a name="io_objects.date_generators"></a><h4> 1465<a name="id-1.3.14.11.26.24"></a>Date Generators</h4> 1466<p>The date_generator formatter and parser provide flexibility by allowing the user to use custom "phrase elements". These phrase elements are the "in-between" words in the date_generators. For example, in the date_generator "Second Monday of March", "Second" and "of" are the phrase elements, where "Monday" and "March" are the date elements. Customization of the date elements is done with the facet. The order of the date and phrase elements cannot be changed. When parsing, all elements of the date_generator phrase must parse correctly or an ios_base::failure exception will be thrown.</p> 1467<h5> 1468<a name="id-1.3.14.11.26.26"></a>Customization</h5> 1469<p>The default "phrase_strings" are: 1470 </p> 1471<table border="0" summary="Simple list" class="simplelist"><tr> 1472<td>"first"</td> 1473<td>"second"</td> 1474<td>"third"</td> 1475<td>"fourth"</td> 1476<td>"fifth"</td> 1477<td>"last"</td> 1478<td>"before"</td> 1479<td>"after"</td> 1480<td>"of"</td> 1481</tr></table> 1482<p> 1483 A custom set of phrase_strings must maintain this order of occurance (Ex: "1st", "2nd", "3rd", "4th", "5th", "last", "prior", "past", "in").</p> 1484<p> Examples using default phrase_strings and default facet formats for weekday & month: </p> 1485<pre class="screen">"first Tue of Mar"</pre> 1486<p>And using custom phrase_strings: </p> 1487<pre class="screen">"1st Tue in Mar"</pre> 1488<p> 1489 </p> 1490<p>The custom set of phrase elements can be set as construction parameters or through an accessor function.A custom date_generator parser/formatter can then be used as a construction parameter to a new facet, or can be set in an existing facet via an accessor function.</p> 1491<p>IMPORTANT NOTE: Prior to 1.33, partial_date was output as "1 Jan" with a single *or* double digit number for the day. The new behavior is to *always* place a double digit number for the day - "01 Jan".</p> 1492<h5> 1493<a name="id-1.3.14.11.26.31"></a>Date Generator Reference</h5> 1494 The complete class references can be found here: <code class="computeroutput"><a class="link" href="../boost/date_time/date_generator_formatter.html" title="Class template date_generator_formatter">Date Generator Formatter Doxygen Reference</a></code> and here: <code class="computeroutput"><a class="link" href="../boost/date_time/date_generator_parser.html" title="Class template date_generator_parser">Date Generator Parser Doxygen Reference</a></code><p> 1495 </p> 1496<h5> 1497<a name="id-1.3.14.11.26.34.1"></a>Date Generator Formatter Construction</h5> 1498<p> 1499 </p> 1500<div class="informaltable"><table class="table"> 1501<colgroup> 1502<col> 1503<col> 1504</colgroup> 1505<thead><tr> 1506<th valign="top">Syntax</th> 1507<th>Description</th> 1508</tr></thead> 1509<tbody> 1510<tr> 1511<td valign="top"><pre class="screen">date_generator_formatter()</pre></td> 1512<td>Uses the default date generator elements.</td> 1513</tr> 1514<tr> 1515<td valign="top"><pre class="screen">date_generator_formatter(...) 1516 Parameters: 1517 string_type first_element 1518 string_type second_element 1519 string_type third_element 1520 string_type fourth_element 1521 string_type fifth_element 1522 string_type last_element 1523 string_type before_element 1524 string_type after_element 1525 string_type of_element</pre></td> 1526<td>Constructs a date_generator_formatter using the given element strings.</td> 1527</tr> 1528</tbody> 1529</table></div> 1530<p> 1531 </p> 1532<h5> 1533<a name="id-1.3.14.11.26.34.3"></a>Date Generator Formatter Accessors</h5> 1534<p> 1535 </p> 1536<div class="informaltable"><table class="table"> 1537<colgroup> 1538<col> 1539<col> 1540</colgroup> 1541<thead> 1542<tr> 1543<th rowspan="2" valign="top">Syntax</th> 1544<th>Description</th> 1545</tr> 1546<tr><th>Example</th></tr> 1547</thead> 1548<tbody> 1549<tr> 1550<td rowspan="2" valign="top"><pre class="screen">void elements(...) 1551 Parameters: 1552 collection_type 1553 phrase_elements</pre></td> 1554<td>Replace the current phrase elements with a collection of new ones. The <code class="computeroutput">phrase_elements</code> parameter is an enum that indicates what the first element in the new collection is (defaults to first).</td> 1555</tr> 1556<tr><td><pre class="screen">// col is a collection holding 1557// "final", "prior", "following", 1558// and "in" 1559typedef date_generator_formatter dgf; 1560dgf formatter(); 1561formatter.elements(col, dgf::last); 1562// complete elements in dgf are now: 1563"first", "second", "third", 1564"fourth", "fifth", "final", 1565"prior", "following", and "in"</pre></td></tr> 1566<tr> 1567<td rowspan="2" valign="top"><pre class="screen">put_partial_date(...) 1568 Return Type: 1569 facet_type::OutItrT 1570 Parameters: 1571 OutItrT next 1572 ios_base 1573 char_type fill 1574 partial_date 1575 facet_type</pre></td> 1576<td>A put function for partial_date. This is a templated function that takes a facet_type as a parameter.</td> 1577</tr> 1578<tr><td>Put a partial_date => "dd Month".</td></tr> 1579<tr> 1580<td rowspan="2" valign="top"><pre class="screen">put_nth_kday(...) 1581 Return Type: 1582 facet_type::OutItrT 1583 Parameters: 1584 OutItrT next 1585 ios_base 1586 char_type fill 1587 nth_kday_type 1588 facet_type</pre></td> 1589<td>A put function for nth_kday_type. This is a templated function that takes a facet_type as a parameter.</td> 1590</tr> 1591<tr><td>Put an nth_day_of_the_week_in_month => "nth weekday of month".</td></tr> 1592<tr> 1593<td rowspan="2" valign="top"><pre class="screen">put_first_kday(...) 1594 Return Type: 1595 facet_type::OutItrT 1596 Parameters: 1597 OutItrT next 1598 ios_base 1599 char_type fill 1600 first_kday_type 1601 facet_type</pre></td> 1602<td>A put function for first_kday_type. This is a templated function that takes a facet_type as a parameter.</td> 1603</tr> 1604<tr><td>Put a first_day_of_the_week_in_month => "first weekday of month".</td></tr> 1605<tr> 1606<td rowspan="2" valign="top"><pre class="screen">put_last_kday(...) 1607 Return Type: 1608 facet_type::OutItrT 1609 Parameters: 1610 OutItrT next 1611 ios_base 1612 char_type fill 1613 last_kday_type 1614 facet_type</pre></td> 1615<td>A put function for last_kday_type. This is a templated function that takes a facet_type as a parameter.</td> 1616</tr> 1617<tr><td>Put a last_day_of_the_week_in_month => "last weekday of month".</td></tr> 1618<tr> 1619<td rowspan="2" valign="top"><pre class="screen">put_kday_before(...) 1620 Return Type: 1621 facet_type::OutItrT 1622 Parameters: 1623 OutItrT next 1624 ios_base 1625 char_type fill 1626 kday_before_type 1627 facet_type</pre></td> 1628<td>A put function for kday_before_type. This is a templated function that takes a facet_type as a parameter.</td> 1629</tr> 1630<tr><td>Put a first_day_of_the_week_before => "weekday before"</td></tr> 1631<tr> 1632<td rowspan="2" valign="top"><pre class="screen">put_kday_after(...) 1633 Return Type: 1634 facet_type::OutItrT 1635 Parameters: 1636 OutItrT next 1637 ios_base 1638 char_type fill 1639 kday_after_type 1640 facet_type</pre></td> 1641<td>A put function for kday_after_type. This is a templated function that takes a facet_type as a parameter.</td> 1642</tr> 1643<tr><td>Put a first_day_of_the_week_after => "weekday after".</td></tr> 1644</tbody> 1645</table></div> 1646<p> 1647 </p> 1648<p> 1649 </p> 1650<h5> 1651<a name="id-1.3.14.11.26.35.1"></a>Date Generator Parser Construction</h5> 1652<p> 1653 </p> 1654<div class="informaltable"><table class="table"> 1655<colgroup> 1656<col> 1657<col> 1658</colgroup> 1659<thead><tr> 1660<th valign="top">Syntax</th> 1661<th>Description</th> 1662</tr></thead> 1663<tbody> 1664<tr> 1665<td valign="top"><pre class="screen">date_generator_parser()</pre></td> 1666<td>Uses the default date generator elements.</td> 1667</tr> 1668<tr> 1669<td valign="top"><pre class="screen">date_generator_parser(...) 1670 Parameter: 1671 date_generator_parser</pre></td> 1672<td>Copy Constructor</td> 1673</tr> 1674<tr> 1675<td valign="top"><pre class="screen">date_generator_parser(...) 1676 Parameters: 1677 string_type first_element 1678 string_type second_element 1679 string_type third_element 1680 string_type fourth_element 1681 string_type fifth_element 1682 string_type last_element 1683 string_type before_element 1684 string_type after_element 1685 string_type of_element</pre></td> 1686<td>Constructs a date_generator_parser using the given element strings.</td> 1687</tr> 1688</tbody> 1689</table></div> 1690<p> 1691 </p> 1692<h5> 1693<a name="id-1.3.14.11.26.35.3"></a>Date Generator Parser Accessors</h5> 1694<p> 1695 </p> 1696<div class="informaltable"><table class="table"> 1697<colgroup> 1698<col> 1699<col> 1700</colgroup> 1701<thead> 1702<tr> 1703<th rowspan="2" valign="top">Syntax</th> 1704<th>Description</th> 1705</tr> 1706<tr><th>Example</th></tr> 1707</thead> 1708<tbody> 1709<tr> 1710<td rowspan="2" valign="top"><pre class="screen">void element_strings(...) 1711 Parameter: 1712 collection_type</pre></td> 1713<td>Replace the set of date generator element string with a new set.</td> 1714</tr> 1715<tr><td><pre class="screen"></pre></td></tr> 1716<tr> 1717<td rowspan="2" valign="top"><pre class="screen">void element_strings(...) 1718 Parameters: 1719 string_type first 1720 string_type second 1721 string_type third 1722 string_type fourth 1723 string_type fifth 1724 string_type last 1725 string_type before 1726 string_type after 1727 string_type of</pre></td> 1728<td>Replace the set of date generator elements with new values.</td> 1729</tr> 1730<tr><td><pre class="screen"></pre></td></tr> 1731<tr> 1732<td rowspan="2" valign="top"><pre class="screen">get_partial_date_type(...) 1733 Return Type: 1734 facet_type::partial_date_type 1735 Parameters: 1736 stream_itr_type next 1737 stream_itr_type str_end 1738 ios_base 1739 facet_type</pre></td> 1740<td>A templated function that parses a date_generator from the stream.</td> 1741</tr> 1742<tr><td>Parses a partial_date => "dd Month".</td></tr> 1743<tr> 1744<td rowspan="2" valign="top"><pre class="screen">get_nth_kday_type(...) 1745 Return Type: 1746 facet_type::nth_kday_type 1747 Parameters: 1748 stream_itr_type next 1749 stream_itr_type str_end 1750 ios_base 1751 facet_type</pre></td> 1752<td>A templated function that parses a date_generator from the stream.</td> 1753</tr> 1754<tr><td>Parses an nth_day_of_the_week_in_month => "nth weekday of month".</td></tr> 1755<tr> 1756<td rowspan="2" valign="top"><pre class="screen">get_first_kday_type(...) 1757 Return Type: 1758 facet_type::firat_kday_type 1759 Parameters: 1760 stream_itr_type next 1761 stream_itr_type str_end 1762 ios_base 1763 facet_type</pre></td> 1764<td>A templated function that parses a date_generator from the stream.</td> 1765</tr> 1766<tr><td>Parses a first_day_of_the_week_in_month => "first weekday of month".</td></tr> 1767<tr> 1768<td rowspan="2" valign="top"><pre class="screen">get_last_kday_type(...) 1769 Return Type: 1770 facet_type::last_kday_type 1771 Parameters: 1772 stream_itr_type next 1773 stream_itr_type str_end 1774 ios_base 1775 facet_type</pre></td> 1776<td>A templated function that parses a date_generator from the stream.</td> 1777</tr> 1778<tr><td>Parses a last_day_of_the_week_in_month => "last weekday of month".</td></tr> 1779<tr> 1780<td rowspan="2" valign="top"><pre class="screen">get_kday_before_type(...) 1781 Return Type: 1782 facet_type::kday_before_type 1783 Parameters: 1784 stream_itr_type next 1785 stream_itr_type str_end 1786 ios_base 1787 facet_type</pre></td> 1788<td>A templated function that parses a date_generator from the stream.</td> 1789</tr> 1790<tr><td>Parses a first_day_of_the_week_before => "weekday before"</td></tr> 1791<tr> 1792<td rowspan="2" valign="top"><pre class="screen">get_kday_after_type(...) 1793 Return Type: 1794 facet_type::kday_after_type 1795 Parameters: 1796 stream_itr_type next 1797 stream_itr_type str_end 1798 ios_base 1799 facet_type</pre></td> 1800<td>A templated function that parses a date_generator from the stream.</td> 1801</tr> 1802<tr><td>Parses a first_day_of_the_week_after => "weekday after".</td></tr> 1803</tbody> 1804</table></div> 1805<p> 1806 </p> 1807<p>_____________________________________________________</p> 1808<a name="io_objects.special_values"></a><h4> 1809<a name="id-1.3.14.11.26.38"></a>Special Values</h4> 1810<p>The date_time library uses five special_values. They are: 1811 </p> 1812<table border="0" summary="Simple list" class="simplelist"><tr> 1813<td>not_a_date_time</td> 1814<td>neg_infin</td> 1815<td>pos_infin</td> 1816<td>min_date_time</td> 1817<td>max_date_time</td> 1818</tr></table> 1819<p> 1820 </p> 1821<p>The default set of strings used to represent these types are: "not-a-date-time", "-infinity", "+infinity", "minimum-date-time", "maximum-date-time". When output, the min_date-time and max_date_time appear as normal date/time representations: "1400-Jan-01" and "9999-Dec-31" repectively.</p> 1822<h5> 1823<a name="id-1.3.14.11.26.41"></a>Customization</h5> 1824<p>The special values parser/formatter allows the user to set custom strings for these special values. These strings can be set as construction parameters to a new facet, or can be set in an existing facet via an accessor function.</p> 1825<h5> 1826<a name="id-1.3.14.11.26.43"></a>Special Values Formatter/Parser Reference</h5> 1827 The complete class references can be found here: <code class="computeroutput"><a class="link" href="../boost/date_time/special_values_formatter.html" title="Class template special_values_formatter">Special Values Formatter Doxygen Reference</a></code> and here: <code class="computeroutput"><a class="link" href="../boost/date_time/special_values_parser.html" title="Class template special_values_parser">Special Values Parser Doxygen Reference</a></code><p> 1828 </p> 1829<h5> 1830<a name="id-1.3.14.11.26.46.1"></a>Special Values Formatter Constructor</h5> 1831<p> 1832 </p> 1833<div class="informaltable"><table class="table"> 1834<colgroup> 1835<col> 1836<col> 1837</colgroup> 1838<thead><tr> 1839<th valign="top">Syntax</th> 1840<th>Description</th> 1841</tr></thead> 1842<tbody> 1843<tr> 1844<td valign="top"><pre class="screen">special_values_formatter()</pre></td> 1845<td>Constructor uses defaults for special value strings.</td> 1846</tr> 1847<tr> 1848<td valign="top"><pre class="screen">special_values_formatter(...) 1849 Parameters: 1850 collection_type::iterator 1851 collection_type::iterator</pre></td> 1852<td>Constructs using values in collection. NOTE: Only the first three strings of the collection will be used. Strings for minimum_date_time and maximum_date_time are ignored as those special values are output as normal dates/times.</td> 1853</tr> 1854<tr> 1855<td valign="top"><pre class="screen">special_values_formatter(...) 1856 Parameters: 1857 char_type* 1858 char_type*</pre></td> 1859<td>Constructs special values formatter from an array of strings.</td> 1860</tr> 1861</tbody> 1862</table></div> 1863<p> 1864 </p> 1865<p> 1866 </p> 1867<h5> 1868<a name="id-1.3.14.11.26.47.1"></a>Special Values Formatter Accessors</h5> 1869<p> 1870 </p> 1871<div class="informaltable"><table class="table"> 1872<colgroup> 1873<col> 1874<col> 1875</colgroup> 1876<thead> 1877<tr> 1878<th rowspan="2" valign="top">Syntax</th> 1879<th>Description</th> 1880</tr> 1881<tr><th>Example</th></tr> 1882</thead> 1883<tbody> 1884<tr> 1885<td rowspan="2" valign="top"><pre class="screen">OutItrT put_special(...) 1886 Parameters: 1887 OutItrT next 1888 special_values value</pre></td> 1889<td>Puts the given special value into the stream.</td> 1890</tr> 1891<tr><td><pre class="screen">date d1(not_a_date_time); 1892date d2(minimum_date_time); 1893special_values_formatter formatter; 1894formatter.put_special(itr, d1); 1895// Puts: "not-a-date-time" 1896formatter.put_special(itr, d2); 1897// Puts: "1400-Jan-01"</pre></td></tr> 1898</tbody> 1899</table></div> 1900<p> 1901 </p> 1902<p> 1903 </p> 1904<h5> 1905<a name="id-1.3.14.11.26.48.1"></a>Special Values Parser Constructor</h5> 1906<p> 1907 </p> 1908<div class="informaltable"><table class="table"> 1909<colgroup> 1910<col> 1911<col> 1912</colgroup> 1913<thead><tr> 1914<th valign="top">Syntax</th> 1915<th>Description</th> 1916</tr></thead> 1917<tbody> 1918<tr> 1919<td valign="top"><pre class="screen">special_values_parser()</pre></td> 1920<td> </td> 1921</tr> 1922<tr> 1923<td valign="top"><pre class="screen">special_values_parser(...) 1924 Parameters: 1925 collection_type::iterator 1926 collection_type::iterator</pre></td> 1927<td>Constructs a special values parser using the strings in the collection.</td> 1928</tr> 1929<tr> 1930<td valign="top"><pre class="screen">special_values_parser(...) 1931 Parameter: 1932 scpecial_values_parser</pre></td> 1933<td>Copy constructor.</td> 1934</tr> 1935<tr> 1936<td valign="top"><pre class="screen">special_values_parser(...) 1937 Parameters: 1938 string_type nadt_str 1939 string_type neg_inf_str 1940 string_type pos_inf_str 1941 string_type min_dt_str 1942 string_type max_dt_str</pre></td> 1943<td>Constructs a special values parser using the supplied strings.</td> 1944</tr> 1945</tbody> 1946</table></div> 1947<p> 1948 </p> 1949<p> 1950 </p> 1951<h5> 1952<a name="id-1.3.14.11.26.49.1"></a>Special Values Parser Accessors</h5> 1953<p> 1954 </p> 1955<div class="informaltable"><table class="table"> 1956<colgroup> 1957<col> 1958<col> 1959</colgroup> 1960<thead> 1961<tr> 1962<th rowspan="2" valign="top">Syntax</th> 1963<th>Description</th> 1964</tr> 1965<tr><th>Example</th></tr> 1966</thead> 1967<tbody> 1968<tr> 1969<td rowspan="2" valign="top"><pre class="screen">void sv_strings(...) 1970 Parameters: 1971 string_type nadt_str 1972 string_type neg_inf_str 1973 string_type pos_inf_str 1974 string_type min_dt_str 1975 string_type max_dt_str</pre></td> 1976<td>Replace the set of special value strings with the given ones.</td> 1977</tr> 1978<tr><td><pre class="screen"></pre></td></tr> 1979<tr> 1980<td rowspan="2" valign="top"><pre class="screen">bool match(...) 1981 Parameters: 1982 stream_itr_type beg 1983 stream_itr_type end 1984 match_results</pre></td> 1985<td>Returns true if parse was successful. Upon a successful parse, <code class="computeroutput">mr.current_match</code> will be set an int values corresponding to the equivalent special_value.</td> 1986</tr> 1987<tr><td><pre class="screen">// stream holds "maximum_date_time" 1988typedef special_values_parser svp; 1989svp parser; 1990svp::match_results mr; 1991if(parser.match(itr, str_end, mr)) { 1992 d = date(static_cast<special_values>( 1993 mr.match_results)) 1994} else { 1995 // error, failed parse 1996} 1997// d == "9999-Dec-31"</pre></td></tr> 1998</tbody> 1999</table></div> 2000<p> 2001 </p> 2002<p>_____________________________________________________</p> 2003<a name="io_objects.format_date_parser"></a><h4> 2004<a name="id-1.3.14.11.26.52"></a>Format Date Parser</h4> 2005<p>The format date parser is the object that holds the strings for months and weekday names, as well as their abbreviations. Custom sets of strings can be set at construction time, or, the strings in an existing format_date_parser can be replaced through accessor functions. Both the constructor and the accessor functions take a vector of strings as their arguments.</p> 2006<h5> 2007<a name="id-1.3.14.11.26.54"></a>Format Date Parser Reference</h5> 2008 The complete class reference can be found here: <code class="computeroutput"><a class="link" href="../boost/date_time/format_date_parser.html" title="Class template format_date_parser">Doxygen Reference</a></code><p> 2009 </p> 2010<h5> 2011<a name="id-1.3.14.11.26.56.1"></a>Format Date Parser Constructor</h5> 2012<p> 2013 </p> 2014<div class="informaltable"><table class="table"> 2015<colgroup> 2016<col> 2017<col> 2018</colgroup> 2019<thead><tr> 2020<th valign="top">Syntax</th> 2021<th>Description</th> 2022</tr></thead> 2023<tbody> 2024<tr> 2025<td valign="top"><pre class="screen">format_date_parser(...) 2026 Parameters: 2027 string_type format 2028 std::locale</pre></td> 2029<td>Creates a parser that uses the given format for parsing dates (in those functions where there is no format parameter). The names and abbreviations used are extracted from the given locale.</td> 2030</tr> 2031<tr> 2032<td valign="top"><pre class="screen">format_date_parser(...) 2033 Parameters: 2034 string_type format 2035 input_collection_type 2036 input_collection_type 2037 input_collection_type 2038 input_collection_type</pre></td> 2039<td>Creates a parser from using the given components. The input_collection_type parameters are for: short month names, long month names, short weekday names, and long weekday names (in that order). These collections must contain values for every month and every weekday (begining with January and Sunday).</td> 2040</tr> 2041<tr> 2042<td valign="top"><pre class="screen">format_date_parser(...) 2043 Parameters: 2044 format_date_parser</pre></td> 2045<td>Copy Constructor</td> 2046</tr> 2047</tbody> 2048</table></div> 2049<p> 2050 </p> 2051<p> 2052 </p> 2053<h5> 2054<a name="id-1.3.14.11.26.57.1"></a>Format Date Parser Accessors</h5> 2055<p> 2056 </p> 2057<div class="informaltable"><table class="table"> 2058<colgroup> 2059<col> 2060<col> 2061</colgroup> 2062<thead> 2063<tr> 2064<th rowspan="2" valign="top">Syntax</th> 2065<th>Description</th> 2066</tr> 2067<tr><th>Example</th></tr> 2068</thead> 2069<tbody> 2070<tr> 2071<td rowspan="2" valign="top"><pre class="screen">string_type format()</pre></td> 2072<td>Returns the format that will be used when parsing dates in those functions where there is no format parameter.</td> 2073</tr> 2074<tr><td><pre class="screen"></pre></td></tr> 2075<tr> 2076<td rowspan="2" valign="top"><pre class="screen">void format(string_type)</pre></td> 2077<td>Sets the format that will be used when parsing dates in those functions where there is no format parameter.</td> 2078</tr> 2079<tr><td><pre class="screen"></pre></td></tr> 2080<tr> 2081<td rowspan="2" valign="top"><pre class="screen">void short_month_names(...) 2082 Parameter: 2083 input_collection_type names</pre></td> 2084<td>Replace the short month names used by the parser. The collection must contain values for each month, starting with January.</td> 2085</tr> 2086<tr><td><pre class="screen"></pre></td></tr> 2087<tr> 2088<td rowspan="2" valign="top"><pre class="screen">void long_month_names(...) 2089 Parameter: 2090 input_collection_type names</pre></td> 2091<td>Replace the long month names used by the parser. The collection must contain values for each month, starting with January.</td> 2092</tr> 2093<tr><td><pre class="screen"></pre></td></tr> 2094<tr> 2095<td rowspan="2" valign="top"><pre class="screen">void short_weekday_names(...) 2096 Parameter: 2097 input_collection_type names</pre></td> 2098<td>Replace the short weekday names used by the parser. The collection must contain values for each weekday, starting with Sunday.</td> 2099</tr> 2100<tr><td><pre class="screen"></pre></td></tr> 2101<tr> 2102<td rowspan="2" valign="top"><pre class="screen">void long_weekday_names(...) 2103 Parameter: 2104 input_collection_type names</pre></td> 2105<td>Replace the long weekday names used by the parser. The collection must contain values for each weekday, starting with Sunday.</td> 2106</tr> 2107<tr><td><pre class="screen"></pre></td></tr> 2108<tr> 2109<td rowspan="2" valign="top"><pre class="screen">date_type parse_date(...) 2110 Parameters: 2111 string_type input 2112 string_type format 2113 special_values_parser</pre></td> 2114<td>Parse a date from the given input using the given format.</td> 2115</tr> 2116<tr><td><pre class="screen">string inp("2005-Apr-15"); 2117string format("%Y-%b-%d"); 2118date d; 2119d = parser.parse_date(inp, 2120 format, 2121 svp); 2122// d == 2005-Apr-15</pre></td></tr> 2123<tr> 2124<td rowspan="2" valign="top"><pre class="screen">date_type parse_date(...) 2125 Parameters: 2126 istreambuf_iterator input 2127 istreambuf_iterator str_end 2128 special_values_parser</pre></td> 2129<td>Parse a date from stream using the parser's format.</td> 2130</tr> 2131<tr><td><pre class="screen"></pre></td></tr> 2132<tr> 2133<td rowspan="2" valign="top"><pre class="screen">date_type parse_date(...) 2134 Parameters: 2135 istreambuf_iterator input 2136 istreambuf_iterator str_end 2137 string_type format 2138 special_values_parser</pre></td> 2139<td>Parse a date from stream using the given format.</td> 2140</tr> 2141<tr><td><pre class="screen">// stream holds "2005-04-15" 2142string format("%Y-%m-%d"); 2143date d; 2144d = parser.parse_date(itr, 2145 str_end, 2146 format, 2147 svp); 2148// d == 2005-Apr-15</pre></td></tr> 2149<tr> 2150<td rowspan="2" valign="top"><pre class="screen">month_type parse_month(...) 2151 Parameters: 2152 istreambuf_iterator input 2153 istreambuf_iterator str_end 2154 string_type format</pre></td> 2155<td>Parses a month from stream using given format. Throws bad_month if unable to parse.</td> 2156</tr> 2157<tr><td><pre class="screen">// stream holds "March" 2158string format("%B"); 2159greg_month m; 2160m = parser.parse_month(itr, 2161 str_end, 2162 format); 2163// m == March</pre></td></tr> 2164<tr> 2165<td rowspan="2" valign="top"><pre class="screen">day_type parse_day_of_month(...) 2166 Parameters: 2167 istreambuf_iterator input 2168 istreambuf_iterator str_end</pre></td> 2169<td>Parses a day_of_month from stream. The day must appear as a two digit number (01-31), or a bad_day_of_month will be thrown.</td> 2170</tr> 2171<tr><td><pre class="screen">// stream holds "01" 2172greg_day d; 2173d = parser.parse_day_of_month(itr, 2174 str_end); 2175// d == 1st</pre></td></tr> 2176<tr> 2177<td rowspan="2" valign="top"><pre class="screen">day_type parse_var_day_of_month(...) 2178 Parameters: 2179 istreambuf_iterator input 2180 istreambuf_iterator str_end</pre></td> 2181<td>Parses a day_of_month from stream. The day must appear as a one or two digit number (1-31), or a bad_day_of_month will be thrown.</td> 2182</tr> 2183<tr><td><pre class="screen">// stream holds "1" 2184greg_day d; 2185d = parser.parse_var_day_of_month(itr, 2186 str_end); 2187// d == 1st</pre></td></tr> 2188<tr> 2189<td rowspan="2" valign="top"><pre class="screen">day_of_week_type parse_weekday(...) 2190 Parameters: 2191 istreambuf_iterator input 2192 istreambuf_iterator str_end 2193 string_type format</pre></td> 2194<td>Parse a weekday from stream according to the given format. Throws a bad_weekday if unable to parse.</td> 2195</tr> 2196<tr><td><pre class="screen">// stream holds "Tue" 2197string format("%a"); 2198greg_weekday wd; 2199wd = parser.parse_weekday(itr, 2200 str_end, 2201 format); 2202// wd == Tuesday</pre></td></tr> 2203<tr> 2204<td rowspan="2" valign="top"><pre class="screen">year_type parse_year(...) 2205 Parameters: 2206 istreambuf_iterator input 2207 istreambuf_iterator str_end 2208 string_type format</pre></td> 2209<td>Parse a year from stream according to given format. Throws bad year if unable to parse.</td> 2210</tr> 2211<tr><td><pre class="screen">// stream holds "98" 2212string format("%y"); 2213greg_year y; 2214y = parser.parse_year(itr, 2215 str_end, 2216 format); 2217// y == 1998</pre></td></tr> 2218</tbody> 2219</table></div> 2220<p> 2221 </p> 2222</div> 2223<div class="section"> 2224<div class="titlepage"><div><div><h3 class="title"> 2225<a name="date_time.io_tutorial"></a>Date Time IO Tutorial</h3></div></div></div> 2226<h3> 2227<a name="id-1.3.14.11.27.2"></a>Date Time IO Tutorial</h3> 2228<a class="link" href="date_time_io.html#basic_use">Basic Use</a> | 2229 <a class="link" href="date_time_io.html#format_strings">Format Strings</a> | 2230 <a class="link" href="date_time_io.html#content_strings">Content Strings</a> | 2231 <a class="link" href="date_time_io.html#tut_sv">Special Values</a> | 2232 <a class="link" href="date_time_io.html#tut_dper">Date/Time Periods</a> | 2233 <a class="link" href="date_time_io.html#tut_dgen">Date Generators</a><a name="basic_use"></a><h5> 2234<a name="id-1.3.14.11.27.10"></a>Basic Use</h5> 2235<p>Facets are automatically imbued when operators '>>' and '<<' are called. The list of date_time objects that can be streamed are:</p> 2236<h6> 2237<a name="id-1.3.14.11.27.12"></a>Gregorian</h6> 2238<p> 2239 <code class="computeroutput">date</code>, 2240 <code class="computeroutput">days</code>, 2241 <code class="computeroutput">date_period</code>, 2242 <code class="computeroutput">greg_month</code>, 2243 <code class="computeroutput">greg_weekday</code>, 2244 <code class="computeroutput">greg_year</code>, 2245 <code class="computeroutput">partial_date</code>, 2246 <code class="computeroutput">nth_day_of_the_week_in_month</code>, 2247 <code class="computeroutput">first_day_of_the_week_in_month</code>, 2248 <code class="computeroutput">last_day_of_the_week_in_month</code>, 2249 <code class="computeroutput">first_day_of_the_week_after</code>, 2250 <code class="computeroutput">first_day_of_the_week_before</code> 2251 </p> 2252<h6> 2253<a name="id-1.3.14.11.27.14"></a>Posix_time</h6> 2254<p> 2255 <code class="computeroutput">ptime</code>, 2256 <code class="computeroutput">time_period</code>, 2257 <code class="computeroutput">time_duration</code> 2258 </p> 2259<h6> 2260<a name="id-1.3.14.11.27.16"></a>Local_time</h6> 2261<p> 2262 <code class="computeroutput">local_date_time</code> 2263 </p> 2264<p> 2265 The following example is of the basic use of the new IO code, utilizing all the defaults. (this example can be found in the <code class="computeroutput">libs/date_time/example/tutorial</code> directory) 2266 </p> 2267<pre class="programlisting"> 2268 2269 date d(2004, Feb, 29); 2270 time_duration td(12,34,56,789); 2271 stringstream ss; 2272 ss << d << ' ' << td; 2273 ptime pt(not_a_date_time); 2274 cout << pt << endl; // "not-a-date-time" 2275 ss >> pt; 2276 cout << pt << endl; // "2004-Feb-29 12:34:56.000789" 2277 ss.str(""); 2278 ss << pt << " EDT-05EDT,M4.1.0,M10.5.0"; 2279 local_date_time ldt(not_a_date_time); 2280 ss >> ldt; 2281 cout << ldt << endl; // "2004-Feb-29 12:34:56.000789 EDT" 2282 2283 </pre> 2284<p>This example used the default settings for the input and output facets. The default formats are such that interoperability like that shown in the example is possible. NOTE: Input streaming of local_date_time can only be done with a <a class="link" href="local_time.html#date_time.local_time.posix_time_zone" title="Posix Time Zone">posix time zone string</a>. The default output format uses a time zone abbreviation. The format can be changed so out and in match (as we will see later in this tutorial).</p> 2285<a name="format_strings"></a><h5> 2286<a name="id-1.3.14.11.27.22"></a>Format Strings</h5> 2287<p>The format strings control the order, type, and style of the date/time elements used. The facets provide some predefined formats (iso_format_specifier, iso_format_extended_specifier, and default_date_format) but the user can easily create their own.</p> 2288 (continued from previous example) 2289 <pre class="programlisting"> 2290 2291 local_time_facet* output_facet = new local_time_facet(); 2292 local_time_input_facet* input_facet = new local_time_input_facet(); 2293 ss.imbue(locale(locale::classic(), output_facet)); 2294 ss.imbue(locale(ss.getloc(), input_facet)); 2295 2296 output_facet->format("%a %b %d, %H:%M %z"); 2297 ss.str(""); 2298 ss << ldt; 2299 cout << ss.str() << endl; // "Sun Feb 29, 12:34 EDT" 2300 2301 output_facet->format(local_time_facet::iso_time_format_specifier); 2302 ss.str(""); 2303 ss << ldt; 2304 cout << ss.str() << endl; // "20040229T123456.000789-0500" 2305 2306 output_facet->format(local_time_facet::iso_time_format_extended_specifier); 2307 ss.str(""); 2308 ss << ldt; 2309 cout << ss.str() << endl; // "2004-02-29 12:34:56.000789-05:00" 2310 2311 </pre> 2312<p>Format strings are not limited to date/time elements. Extra verbiage can be placed in a format string. NOTE: When extra verbiage is present in an input format, the data being input must also contain the exact verbiage.</p> 2313 (continued from previous example) 2314 <pre class="programlisting"> 2315 2316 // extra words in format 2317 string my_format("The extended ordinal time %Y-%jT%H:%M can also be \ 2318 represented as %A %B %d, %Y"); 2319 output_facet->format(my_format.c_str()); 2320 input_facet->format(my_format.c_str()); 2321 ss.str(""); 2322 ss << ldt; 2323 cout << ss.str() << endl; 2324 2325 // matching extra words in input 2326 ss.str("The extended ordinal time 2005-128T12:15 can also be \ 2327 represented as Sunday May 08, 2005"); 2328 ss >> ldt; 2329 cout << ldt << endl; 2330 2331 </pre> 2332<a name="content_strings"></a><h5> 2333<a name="id-1.3.14.11.27.28"></a>Content Strings</h5> 2334<p>So far we've shown how a user can achieve a great deal of customization with very little effort by using formats. Further customization can be achieved through user defined elements (ie strings). The elements that can be customized are: Special value names, month names, month abbreviations, weekday names, weekday abbreviations, delimiters of the date/time periods, and the phrase elements of the date_generators.</p> 2335<p>The default values for these are as follows:</p> 2336<h6> 2337<a name="id-1.3.14.11.27.31"></a>Special values</h6> 2338<p> 2339 <code class="computeroutput">not-a-date-time</code>, 2340 <code class="computeroutput">-infinity</code>, 2341 <code class="computeroutput">+infinity</code>, 2342 <code class="computeroutput">minimum-date-time</code>, 2343 <code class="computeroutput">maximum-date-time</code> 2344 </p> 2345<h6> 2346<a name="id-1.3.14.11.27.33"></a>Months</h6> 2347<p> 2348 <code class="computeroutput">English calendar and three letter abbreviations</code> 2349 </p> 2350<h6> 2351<a name="id-1.3.14.11.27.35"></a>Weekdays</h6> 2352<p> 2353 <code class="computeroutput">English calendar and three letter abbreviations</code> 2354 </p> 2355<h6> 2356<a name="id-1.3.14.11.27.37"></a>Date generator phrase elements</h6> 2357<p> 2358 <code class="computeroutput">first</code>, 2359 <code class="computeroutput">second</code>, 2360 <code class="computeroutput">third</code>, 2361 <code class="computeroutput">fourth</code>, 2362 <code class="computeroutput">fifth</code>, 2363 <code class="computeroutput">last</code>, 2364 <code class="computeroutput">before</code>, 2365 <code class="computeroutput">after</code>, 2366 <code class="computeroutput">of</code> 2367 </p> 2368<p>NOTE: We've shown earlier that the components of a date/time representation can be re-ordered via the format string. This is not the case with date_generators. The elements themselves can be customized but their order cannot be changed.</p> 2369<h5> 2370<a name="id-1.3.14.11.27.40"></a>Content Strings</h5> 2371<p>To illustrate the customization possibilities we will use custom strings for months and weekdays (we will only use long names, is all lowercase, for this example).</p> 2372 (continued from previous example) 2373 <pre class="programlisting"> 2374 2375 // set up the collections of custom strings. 2376 // only the full names are altered for the sake of brevity 2377 string month_names[12] = { "january", "february", "march", 2378 "april", "may", "june", 2379 "july", "august", "september", 2380 "october", "november", "december" }; 2381 vector<string> long_months(&month_names[0], &month_names[12]); 2382 string day_names[7] = { "sunday", "monday", "tuesday", "wednesday", 2383 "thursday", "friday", "saturday" }; 2384 vector<string> long_days(&day_names[0], &day_names[7]); 2385 2386 // create date_facet and date_input_facet using all defaults 2387 date_facet* date_output = new date_facet(); 2388 date_input_facet* date_input = new date_input_facet(); 2389 ss.imbue(locale(ss.getloc(), date_output)); 2390 ss.imbue(locale(ss.getloc(), date_input)); 2391 2392 // replace names in the output facet 2393 date_output->long_month_names(long_months); 2394 date_output->long_weekday_names(long_days); 2395 2396 // replace names in the input facet 2397 date_input->long_month_names(long_months); 2398 date_input->long_weekday_names(long_days); 2399 2400 // customize month, weekday and date formats 2401 date_output->format("%Y-%B-%d"); 2402 date_input->format("%Y-%B-%d"); 2403 date_output->month_format("%B"); // full name 2404 date_input->month_format("%B"); // full name 2405 date_output->weekday_format("%A"); // full name 2406 date_input->weekday_format("%A"); // full name 2407 2408 ss.str(""); 2409 ss << greg_month(3); 2410 cout << ss.str() << endl; // "march" 2411 ss.str(""); 2412 ss << greg_weekday(3); 2413 cout << ss.str() << endl; // "tuesday" 2414 ss.str(""); 2415 ss << date(2005,Jul,4); 2416 cout << ss.str() << endl; // "2005-july-04" 2417 2418 </pre> 2419<a name="tut_sv"></a><h5> 2420<a name="id-1.3.14.11.27.44"></a>Special Values</h5> 2421<p>Customizing the input and output of special values is best done by creating a new special_values_parser and special_values_formatter. The new strings can be set at construction time (as in the example below).</p> 2422 (continued from previous example) 2423 <pre class="programlisting"> 2424 2425 // reset the formats to defaults 2426 output_facet->format(local_time_facet::default_time_format); 2427 input_facet->format(local_time_input_facet::default_time_input_format); 2428 2429 // create custom special_values parser and formatter objects 2430 // and add them to the facets 2431 string sv[5] = {"nadt","neg_inf", "pos_inf", "min_dt", "max_dt" }; 2432 vector<string> sv_names(&sv[0], &sv[5]); 2433 special_values_parser sv_parser(sv_names.begin(), sv_names.end()); 2434 special_values_formatter sv_formatter(sv_names.begin(), sv_names.end()); 2435 output_facet->special_values_formatter(sv_formatter); 2436 input_facet->special_values_parser(sv_parser); 2437 2438 ss.str(""); 2439 ldt = local_date_time(not_a_date_time); 2440 ss << ldt; 2441 cout << ss.str() << endl; // "nadt" 2442 2443 ss.str("min_dt"); 2444 ss >> ldt; 2445 ss.str(""); 2446 ss << ldt; 2447 cout << ss.str() << endl; // "1400-Jan-01 00:00:00 UTC" 2448 2449 </pre> 2450<p>NOTE: even though we sent in strings for min and max to the formatter, they are ignored because those special values construct to actual dates (as shown above).</p> 2451<a name="tut_dper"></a><h5> 2452<a name="id-1.3.14.11.27.49"></a>Date/Time Periods</h5> 2453<p>Customizing the input and output of periods is best done by creating a new period_parser and period_formatter. The new strings can be set at construction time (as in the example below).</p> 2454 (continued from previous example) 2455 <pre class="programlisting"> 2456 2457 // all formats set back to defaults (not shown for brevity) 2458 2459 // create our date_period 2460 date_period dp(date(2005,Mar,1), days(31)); // month of march 2461 2462 // custom period formatter and parser 2463 period_formatter per_formatter(period_formatter::AS_OPEN_RANGE, 2464 " to ", "from ", " exclusive", " inclusive" ); 2465 period_parser per_parser(period_parser::AS_OPEN_RANGE, 2466 " to ", "from ", " exclusive" , "inclusive" ); 2467 2468 // default output 2469 ss.str(""); 2470 ss << dp; 2471 cout << ss.str() << endl; // "[2005-Mar-01/2005-Mar-31]" 2472 2473 // add out custom parser and formatter to the facets 2474 date_output->period_formatter(per_formatter); 2475 date_input->period_parser(per_parser); 2476 2477 // custom output 2478 ss.str(""); 2479 ss << dp; 2480 cout << ss.str() << endl; // "from 2005-Feb-01 to 2005-Apr-01 exclusive" 2481 2482 </pre> 2483<a name="tut_dgen"></a><h5> 2484<a name="id-1.3.14.11.27.53"></a>Date Generators</h5> 2485<p>Customizing the input and output of date_generators is done by replacing the existing strings (in the facet) with new strings.</p> 2486<p>NOTE: We've shown earlier that the components of a date/time representation can be re-ordered via the format string. This is not the case with date_generators. The elements themselves can be customized but their order cannot be changed.</p> 2487 (continued from previous example) 2488 <pre class="programlisting"> 2489 2490 // custom date_generator phrases 2491 string dg_phrases[9] = { "1st", "2nd", "3rd", "4th", "5th", 2492 "final", "prior to", "following", "in" }; 2493 vector<string> phrases(&dg_phrases[0], &dg_phrases[9]); 2494 2495 // create our date_generator 2496 first_day_of_the_week_before d_gen(Monday); 2497 2498 // default output 2499 ss.str(""); 2500 ss << d_gen; 2501 cout << ss.str() << endl; // "Mon before" 2502 2503 // add our custom strings to the date facets 2504 date_output->date_gen_phrase_strings(phrases); 2505 date_input->date_gen_element_strings(phrases); 2506 2507 // custom output 2508 ss.str(""); 2509 ss << d_gen; 2510 cout << ss.str() << endl; // "Mon prior to" 2511 2512 </pre> 2513</div> 2514</div> 2515<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 2516<td align="left"></td> 2517<td align="right"><div class="copyright-footer">Copyright © 2001-2005 CrystalClear Software, Inc<p>Subject to the Boost Software License, Version 1.0. (See accompanying file 2518 <code class="filename">LICENSE_1_0.txt</code> or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)</p> 2519</div></td> 2520</tr></table> 2521<hr> 2522<div class="spirit-nav"> 2523<a accesskey="p" href="local_time.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../date_time.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="serialization.html"><img src="../../../doc/src/images/next.png" alt="Next"></a> 2524</div> 2525</body> 2526</html> 2527