3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>Date Time Input/Output</title>
5 <link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
6 <meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
7 <link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
8 <link rel="up" href="../date_time.html" title="Chapter 9. Boost.Date_Time">
9 <link rel="prev" href="local_time.html" title="Local Time">
10 <link rel="next" href="serialization.html" title="Serialization">
12 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13 <table cellpadding="2" width="100%"><tr>
14 <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
15 <td align="center"><a href="../../../index.html">Home</a></td>
16 <td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
17 <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18 <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19 <td align="center"><a href="../../../more/index.htm">More</a></td>
22 <div class="spirit-nav">
23 <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>
26 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
27 <a name="date_time.date_time_io"></a>Date Time Input/Output</h2></div></div></div>
28 <div class="toc"><dl class="toc">
29 <dt><span class="section"><a href="date_time_io.html#date_time.format_flags">Format Flags</a></span></dt>
30 <dt><span class="section"><a href="date_time_io.html#date_time.date_facet">Date Facet</a></span></dt>
31 <dt><span class="section"><a href="date_time_io.html#date_time.date_input_facet">Date Input Facet</a></span></dt>
32 <dt><span class="section"><a href="date_time_io.html#date_time.time_facet">Time Facet</a></span></dt>
33 <dt><span class="section"><a href="date_time_io.html#date_time.time_input_facet">Time Input Facet</a></span></dt>
34 <dt><span class="section"><a href="date_time_io.html#date_time.io_objects">Date Time Formatter/Parser Objects</a></span></dt>
35 <dt><span class="section"><a href="date_time_io.html#date_time.io_tutorial">Date Time IO Tutorial</a></span></dt>
38 <a name="idp179854336"></a>Date Time IO System</h3>
40 <a class="link" href="date_time_io.html#streaming_exceptions">Exception Handling on Streams</a>
42 <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>
43 <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>
44 <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>
45 <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>
46 <a name="streaming_exceptions"></a><h6>
47 <a name="idp179863344"></a>Exception Handling on Streams</h6>
48 <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>
49 <pre class="screen">// "Turning on" exceptions
50 date d(not_a_date_time);
52 ss.exceptions(std::ios_base::failbit);
54 ss >> d; // throws bad_year exception AND sets failbit on stream</pre>
56 <a name="idp179867712"></a>A simple example of this new system:</h6>
57 <pre class="screen">//example to customize output to be "LongWeekday LongMonthname day, year"
60 date_facet* facet(new date_facet("%A %B %d, %Y"));
61 std::cout.imbue(std::locale(std::cout.getloc(), facet));
62 std::cout << d << std::endl;
63 // "Saturday June 25, 2005"</pre>
65 <div class="titlepage"><div><div><h3 class="title">
66 <a name="date_time.format_flags"></a>Format Flags</h3></div></div></div>
67 <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>
68 <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.
71 <a name="date_time_io.date_format_flags"></a>
72 Date Facet Format Flags
74 <div class="informaltable"><table class="table">
81 <th rowspan="2" valign="top">Format Specifier</th>
84 <tr><th>Example</th></tr>
88 <td rowspan="2" valign="top"><pre class="screen">%a</pre></td>
89 <td>Abbreviated weekday name</td>
91 <tr><td><pre class="screen">"Mon" => Monday</pre></td></tr>
93 <td rowspan="2" valign="top"><pre class="screen">%A</pre></td>
94 <td>Long weekday name</td>
96 <tr><td><pre class="screen">"Monday"</pre></td></tr>
98 <td rowspan="2" valign="top"><pre class="screen">%b</pre></td>
99 <td>Abbreviated month name</td>
101 <tr><td><pre class="screen">"Feb" => February</pre></td></tr>
103 <td rowspan="2" valign="top"><pre class="screen">%B</pre></td>
104 <td>Full month name</td>
106 <tr><td><pre class="screen">"February"</pre></td></tr>
108 <td rowspan="2" valign="top"><pre class="screen">%c !</pre></td>
109 <td>The preferred date and time representation for the current locale.</td>
111 <tr><td><pre class="screen"></pre></td></tr>
113 <td rowspan="2" valign="top"><pre class="screen">%C !#</pre></td>
114 <td>The century number (year/100) as a 2-digit integer.</td>
116 <tr><td><pre class="screen"></pre></td></tr>
118 <td rowspan="2" valign="top"><pre class="screen">%d</pre></td>
119 <td>Day of the month as decimal 01 to 31</td>
121 <tr><td><pre class="screen"></pre></td></tr>
123 <td rowspan="2" valign="top"><pre class="screen">%D !#</pre></td>
124 <td>Equivalent to %m/%d/%y</td>
126 <tr><td><pre class="screen"></pre></td></tr>
128 <td rowspan="2" valign="top"><pre class="screen">%e #</pre></td>
129 <td>Like %d, the day of the month as a decimal number, but a leading zero is replaced by a space</td>
131 <tr><td><pre class="screen"></pre></td></tr>
133 <td rowspan="2" valign="top"><pre class="screen">%G !</pre></td>
134 <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>
136 <tr><td><pre class="screen"></pre></td></tr>
138 <td rowspan="2" valign="top"><pre class="screen">%g !</pre></td>
139 <td>Like %G, but without century.</td>
141 <tr><td><pre class="screen"></pre></td></tr>
143 <td rowspan="2" valign="top"><pre class="screen">%h !#</pre></td>
144 <td> Equivalent to %b</td>
146 <tr><td><pre class="screen"></pre></td></tr>
148 <td rowspan="2" valign="top"><pre class="screen">%j</pre></td>
149 <td>Day of year as decimal from 001 to 366 for leap years, 001 - 365 for non-leap years.</td>
151 <tr><td><pre class="screen">"060" => Feb-29</pre></td></tr>
153 <td rowspan="2" valign="top"><pre class="screen">%m</pre></td>
154 <td>Month name as a decimal 01 to 12</td>
156 <tr><td><pre class="screen">"01" => January</pre></td></tr>
158 <td rowspan="2" valign="top"><pre class="screen">%u !</pre></td>
159 <td>The day of the week as a decimal, range 1 to 7, Monday being 1.</td>
161 <tr><td><pre class="screen"></pre></td></tr>
163 <td rowspan="2" valign="top"><pre class="screen">%U</pre></td>
164 <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>
166 <tr><td><pre class="screen">date d(2005, Jan, 1); // Saturday
168 ss << d; // "00"
169 d += day(1); // Sunday
170 ss << d; // "01" beginning of week 1</pre></td></tr>
172 <td rowspan="2" valign="top"><pre class="screen">%V !#</pre></td>
173 <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>
175 <tr><td><pre class="screen"></pre></td></tr>
177 <td rowspan="2" valign="top"><pre class="screen">%w</pre></td>
178 <td>Weekday as decimal number 0 to 6</td>
180 <tr><td><pre class="screen">"0" => Sunday</pre></td></tr>
182 <td rowspan="2" valign="top"><pre class="screen">%W</pre></td>
183 <td>Week number 00 to 53 where Monday is first day of week 1</td>
185 <tr><td><pre class="screen">date d(2005, Jan, 2); // Sunday
187 ss << d; // "00"
188 d += day(1); // Monday
189 ss << d; // "01" beginning of week 1</pre></td></tr>
191 <td rowspan="2" valign="top"><pre class="screen">%x</pre></td>
192 <td>Implementation defined date format from the locale.</td>
194 <tr><td><pre class="screen">date d(2005,Oct,31);
195 date_facet* f = new date_facet("%x");
197 locale loc = locale(locale("en_US"), f);
199 cout << d; // "10/31/2005"
201 loc = locale(locale("de_DE"), f);
203 cout << d; // "31.10.2005"</pre></td></tr>
205 <td rowspan="2" valign="top"><pre class="screen">%y</pre></td>
206 <td>Two digit year</td>
208 <tr><td><pre class="screen">"05" => 2005</pre></td></tr>
210 <td rowspan="2" valign="top"><pre class="screen">%Y</pre></td>
211 <td>Four digit year</td>
213 <tr><td><pre class="screen">"2005"</pre></td></tr>
215 <td rowspan="2" valign="top"><pre class="screen">%Y-%b-%d</pre></td>
216 <td>Default date format</td>
218 <tr><td><pre class="screen">"2005-Apr-01"</pre></td></tr>
220 <td rowspan="2" valign="top"><pre class="screen">%Y%m%d</pre></td>
223 <tr><td><pre class="screen">"20050401"</pre></td></tr>
225 <td rowspan="2" valign="top"><pre class="screen">%Y-%m-%d</pre></td>
226 <td>ISO extended format</td>
228 <tr><td><pre class="screen">"2005-04-01"</pre></td></tr>
234 <a name="date_time_io.time_format_flags"></a>
235 Time Facet Format Flags
237 <div class="informaltable"><table class="table">
244 <th rowspan="2" valign="top">Format Specifier</th>
247 <tr><th>Example</th></tr>
251 <td rowspan="2" valign="top"><pre class="screen">%- *!</pre></td>
252 <td>Placeholder for the sign of a duration. Only displays when the duration is negative.</td>
254 <tr><td><pre class="screen">"-13:15:16"</pre></td></tr>
256 <td rowspan="2" valign="top"><pre class="screen">%+ *!</pre></td>
257 <td>Placeholder for the sign of a duration. Always displays for both positive and negative.</td>
259 <tr><td><pre class="screen">"+13:15:16"</pre></td></tr>
261 <td rowspan="2" valign="top"><pre class="screen">%f</pre></td>
262 <td>Fractional seconds are always used, even when their value is zero</td>
264 <tr><td><pre class="screen">"13:15:16.000000"</pre></td></tr>
266 <td rowspan="2" valign="top"><pre class="screen">%F *</pre></td>
267 <td>Fractional seconds are used only when their value is not zero.</td>
269 <tr><td><pre class="screen">"13:15:16"
270 "05:04:03.001234"</pre></td></tr>
272 <td rowspan="2" valign="top"><pre class="screen">%H</pre></td>
273 <td>The hour as a decimal number using a 24-hour clock (range 00 to 23).</td>
275 <tr><td> </td></tr>
277 <td rowspan="2" valign="top"><pre class="screen">%I !</pre></td>
278 <td>The hour as a decimal number using a 12-hour clock (range 01 to 12).</td>
280 <tr><td> </td></tr>
282 <td rowspan="2" valign="top"><pre class="screen">%k !</pre></td>
283 <td>The hour (24-hour clock) as a decimal number (range 0 to 23); single digits are preceded by a blank.</td>
285 <tr><td> </td></tr>
287 <td rowspan="2" valign="top"><pre class="screen">%l !</pre></td>
288 <td>The hour (12-hour clock) as a decimal number (range 1 to 12); single digits are preceded by a blank.</td>
290 <tr><td> </td></tr>
292 <td rowspan="2" valign="top"><pre class="screen">%M</pre></td>
293 <td>The minute as a decimal number (range 00 to 59).</td>
295 <tr><td> </td></tr>
297 <td rowspan="2" valign="top"><pre class="screen">%O</pre></td>
298 <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>
300 <tr><td> </td></tr>
302 <td rowspan="2" valign="top"><pre class="screen">%p !</pre></td>
303 <td>Either `AM' or `PM' according to the given time value, or the corresponding strings for the current locale.</td>
305 <tr><td> </td></tr>
307 <td rowspan="2" valign="top"><pre class="screen">%P !#</pre></td>
308 <td>Like %p but in lowercase: `am' or `pm' or a corresponding string for the current locale.</td>
310 <tr><td> </td></tr>
312 <td rowspan="2" valign="top"><pre class="screen">%r !#</pre></td>
313 <td>The time in a.m. or p.m. notation. In the POSIX locale this is equivalent to `%I:%M:%S %p'</td>
315 <tr><td> </td></tr>
317 <td rowspan="2" valign="top"><pre class="screen">%R !</pre></td>
318 <td>The time in 24-hour notation (%H:%M)</td>
320 <tr><td> </td></tr>
322 <td rowspan="2" valign="top"><pre class="screen">%s *</pre></td>
323 <td>Seconds with fractional seconds.</td>
325 <tr><td><pre class="screen">"59.000000"</pre></td></tr>
327 <td rowspan="2" valign="top"><pre class="screen">%S</pre></td>
328 <td>Seconds only</td>
330 <tr><td><pre class="screen">"59"</pre></td></tr>
332 <td rowspan="2" valign="top"><pre class="screen">%T !</pre></td>
333 <td>The time in 24-hour notation (%H:%M:%S)</td>
335 <tr><td> </td></tr>
337 <td rowspan="2" valign="top"><pre class="screen">%q</pre></td>
338 <td>ISO time zone (output only). This flag is ignored when using the time_facet with a ptime.</td>
340 <tr><td><pre class="screen">"-0700" // Mountain Standard Time</pre></td></tr>
342 <td rowspan="2" valign="top"><pre class="screen">%Q</pre></td>
343 <td>ISO extended time zone (output only). This flag is ignored when using the time_facet with a ptime.</td>
345 <tr><td><pre class="screen">"-05:00" // Eastern Standard Time</pre></td></tr>
347 <td rowspan="2" valign="top"><pre class="screen">%z *!</pre></td>
348 <td>Abbreviated time zone (output only). This flag is ignored when using the time_facet with a ptime.</td>
350 <tr><td><pre class="screen">"MST" // Mountain Standard Time</pre></td></tr>
352 <td rowspan="2" valign="top"><pre class="screen">%Z *!</pre></td>
353 <td>Full time zone name (output only). This flag is ignored when using the time_facet with a ptime.</td>
355 <tr><td><pre class="screen">"EDT" // Eastern Daylight Time</pre></td></tr>
357 <td rowspan="2" valign="top"><pre class="screen">%ZP *</pre></td>
358 <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>
360 <tr><td><pre class="screen">"EST-05EDT+01,M4.1.0/02:00,M10.5.0/02:00"</pre></td></tr>
362 <td rowspan="2" valign="top"><pre class="screen">%x %X</pre></td>
363 <td>Implementation defined date/time format from the locale.</td>
365 <tr><td><pre class="screen">date d(2005,Oct,31);
366 ptime pt(d, hours(20));
367 time_facet* f = new time_facet("%x %X");
369 locale loc = locale(locale("en_US"), f);
371 cout << pt; // "10/31/2005 08:00:00 PM"
373 loc = locale(locale("de_DE"), f);
375 cout << pt; // "31.10.2005 20:00:00"</pre></td></tr>
377 <td rowspan="2" valign="top"><pre class="screen">%Y%m%dT%H%M%S%F%q</pre></td>
380 <tr><td><pre class="screen">"20051015T131211-0700" // Oct 15, 2005 13:12:11 MST</pre></td></tr>
382 <td rowspan="2" valign="top"><pre class="screen">%Y-%m-%d %H:%M:%S%F%Q</pre></td>
383 <td>Extended ISO format</td>
385 <tr><td><pre class="screen">"2005-10-15 13:12:11-07:00"</pre></td></tr>
387 <td rowspan="2" valign="top"><pre class="screen">%Y-%b-%d %H:%M:%S%F %z</pre></td>
388 <td>Default format used when outputting ptime and local_date_time.</td>
390 <tr><td><pre class="screen">"2005-Oct-15 13:12:11 MST"</pre></td></tr>
392 <td rowspan="2" valign="top"><pre class="screen">%Y-%b-%d %H:%M:%S%F %ZP</pre></td>
393 <td>Default format used when inputting ptime and local_date_time.</td>
395 <tr><td><pre class="screen">"2005-Oct-15 13:12:11 MST-07"</pre></td></tr>
397 <td rowspan="2" valign="top"><pre class="screen">%-%H:%M:%S%F !</pre></td>
398 <td>Default time_duration format for output. Sign will only be displayed for negative durations.</td>
400 <tr><td><pre class="screen">"-13:14:15.003400"</pre></td></tr>
402 <td rowspan="2" valign="top"><pre class="screen">%H:%M:%S%F</pre></td>
403 <td>Default time_duration format for input.</td>
405 <tr><td><pre class="screen">"13:14:15.003400"</pre></td></tr>
410 <p>* Signifies flags that have a behavior unique to <code class="computeroutput">date_time</code>.</p>
411 <p># Signifies flags that have a platform-dependent behavior. These may not be supported everywhere.</p>
412 <p>! Signifies flags that currently do not work for input.</p>
414 <p>The following table lists the available facets.</p>
415 <a name="io_objects_table"></a><h4>
416 <a name="idp180062528"></a>IO Objects</h4>
419 <div class="informaltable"><table class="table">
430 <td><code class="computeroutput"><a class="link" href="../boost/date_time/date_facet.html" title="Class template date_facet">date_facet</a></code></td>
431 <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>
434 <td><code class="computeroutput"><a class="link" href="../boost/date_time/date_facet.html" title="Class template date_facet">wdate_facet</a></code></td>
435 <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>
438 <td><code class="computeroutput"><a class="link" href="../boost/date_time/time_facet.html" title="Class template time_facet">time_facet</a></code></td>
439 <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>
442 <td><code class="computeroutput"><a class="link" href="../boost/date_time/time_facet.html" title="Class template time_facet">wtime_facet</a></code></td>
443 <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>
447 <code class="computeroutput"><a class="link" href="../boost/date_time/time_facet.html" title="Class template time_facet">local_time_facet</a></code>*</td>
449 <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>
453 <code class="computeroutput"><a class="link" href="../boost/date_time/time_facet.html" title="Class template time_facet">wlocal_time_facet</a></code>*</td>
455 <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>
460 * 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.
463 <a name="idp180088080"></a>Formatter/Parser Objects</h4>
464 <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>
467 <div class="informaltable"><table class="table">
478 <td><code class="computeroutput"><a class="link" href="../boost/date_time/period_formatter.html" title="Class template period_formatter">period_formatter</a></code></td>
479 <td><code class="computeroutput"><a class="link" href="../boost/date_time/period_parser.html" title="Class template period_parser">period_parser</a></code></td>
482 <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>
483 <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>
486 <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>
487 <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>
491 <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>
497 <div class="section">
498 <div class="titlepage"><div><div><h3 class="title">
499 <a name="date_time.date_facet"></a>Date Facet</h3></div></div></div>
500 <a class="link" href="date_time_io.html#date_facet_intro">Introduction</a> -
501 <a class="link" href="date_time_io.html#date_facet_constr">Construction</a> -
502 <a class="link" href="date_time_io.html#date_facet_accessors">Accessors</a><a name="date_facet_intro"></a><h4>
503 <a name="idp180110384"></a>Introduction</h4>
504 <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>.
506 <a name="date_facet_constr"></a><h4>
507 <a name="idp180115200"></a>Construction</h4>
510 <div class="informaltable"><table class="table">
521 <td valign="top"><pre class="screen">date_facet()</pre></td>
522 <td>Default constructor</td>
525 <td valign="top"><pre class="screen">date_facet(...)
528 input_collection_type</pre></td>
529 <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>
532 <td valign="top"><pre class="screen">date_facet(...)
535 period_formatter_type
536 special_values_formatter_type
537 date_gen_formatter_type</pre></td>
538 <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>
544 <a name="date_facet_accessors"></a><h4>
545 <a name="idp180128064"></a>Accessors</h4>
548 <div class="informaltable"><table class="table">
555 <th rowspan="2" valign="top">Syntax</th>
558 <tr><th>Example</th></tr>
562 <td rowspan="2" valign="top"><pre class="screen">void format(char_type*)</pre></td>
563 <td>Set the format for dates.</td>
565 <tr><td><pre class="screen">date_facet* f = new date_facet();
566 f->format("%m %d %Y");</pre></td></tr>
568 <td rowspan="2" valign="top"><pre class="screen">void set_iso_format()</pre></td>
569 <td>Sets the date format to ISO</td>
571 <tr><td><pre class="screen">f->set_iso_format();
572 // "%Y%m%d"</pre></td></tr>
574 <td rowspan="2" valign="top"><pre class="screen">void set_iso_extended_format()</pre></td>
575 <td>Sets the date format to ISO Extended</td>
577 <tr><td><pre class="screen">f->set_iso_extended_format();
578 // "%Y-%m-%d"</pre></td></tr>
580 <td rowspan="2" valign="top"><pre class="screen">void month_format(char_type*)</pre></td>
581 <td>Set the format for months when they are 'put' individually.</td>
583 <tr><td><pre class="screen">f->month_format("%B");
584 ss << greg_month(12); // "December"</pre></td></tr>
586 <td rowspan="2" valign="top"><pre class="screen">void weekday_format(char_type*)</pre></td>
587 <td>Set the format for weekdays when they are 'put' individually.</td>
589 <tr><td><pre class="screen">f->weekday_format("%a");
590 ss << greg_weekday(2); // "Tue"</pre></td></tr>
592 <td rowspan="2" valign="top"><pre class="screen">void period_formatter(...)
594 period_formatter_type</pre></td>
595 <td>Replaces the period formatter object with a user created one.</td>
597 <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>
599 <td rowspan="2" valign="top"><pre class="screen">void special_values_formatter(...)
601 special_values_formatter_type</pre></td>
602 <td>Replaces the special_values formatter object with a user created one.</td>
604 <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>
606 <td rowspan="2" valign="top"><pre class="screen">void date_gen_phrase_strings(...)
608 input_collection_type
609 date_gen_formatter_type::
610 phrase_elements</pre></td>
611 <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>
613 <tr><td><pre class="screen"></pre></td></tr>
615 <td rowspan="2" valign="top"><pre class="screen">void short_weekday_names(...)
617 input_collection_type</pre></td>
618 <td>Replace strings used when 'putting' short weekdays.</td>
620 <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>
622 <td rowspan="2" valign="top"><pre class="screen">void long_weekday_names(...)
624 input_collection_type</pre></td>
625 <td>Replace strings used when 'putting' long weekdays.</td>
627 <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>
629 <td rowspan="2" valign="top"><pre class="screen">void short_month_names(...)
631 input_collection_type</pre></td>
632 <td>Replace strings used when 'putting' short months.</td>
634 <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>
636 <td rowspan="2" valign="top"><pre class="screen">void long_month_names(...)
638 input_collection_type</pre></td>
639 <td>Replace strings used when 'putting' long months.</td>
641 <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>
643 <td rowspan="2" valign="top"><pre class="screen">OutItrT put(...)
644 Common parameters for all
649 Unique parameter for 'put' funcs:
650 gregorian object</pre></td>
651 <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>
653 <tr><td><pre class="screen"></pre></td></tr>
655 <td rowspan="2" valign="top"><pre class="screen">OutItrT put(..., date)</pre></td>
656 <td>Puts a date object into the stream using the format set by <code class="computeroutput">format(...)</code> or the default.</td>
658 <tr><td><pre class="screen"></pre></td></tr>
660 <td rowspan="2" valign="top"><pre class="screen">OutItrT put(..., days)</pre></td>
661 <td>Puts a days object into the stream as a number.</td>
663 <tr><td><pre class="screen"></pre></td></tr>
665 <td rowspan="2" valign="top"><pre class="screen">OutItrT put(..., month)</pre></td>
666 <td>Puts a month object into the stream using the format set by <code class="computeroutput">month_format(...)</code> or the default.</td>
668 <tr><td><pre class="screen"></pre></td></tr>
670 <td rowspan="2" valign="top"><pre class="screen">OutItrT put(..., day)</pre></td>
671 <td>Puts a day of month object into the stream as a two digit number.</td>
673 <tr><td><pre class="screen">"01" // January 1st</pre></td></tr>
675 <td rowspan="2" valign="top"><pre class="screen">OutItrT put(..., day_of_week)</pre></td>
676 <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>
678 <tr><td><pre class="screen"></pre></td></tr>
680 <td rowspan="2" valign="top"><pre class="screen">OutItrT put(..., date_period)</pre></td>
681 <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>
683 <tr><td><pre class="screen"></pre></td></tr>
685 <td rowspan="2" valign="top"><pre class="screen">OutItrT put(..., partial_date)</pre></td>
686 <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>
688 <tr><td><pre class="screen">"01 Jan" // default formats
689 "01 January" // long month format</pre></td></tr>
691 <td rowspan="2" valign="top"><pre class="screen">OutItrT put(..., date_generator)
693 nth_day_of_the_week_in_month</pre></td>
694 <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>
696 <tr><td><pre class="screen">"third Fri in May" // defaults</pre></td></tr>
698 <td rowspan="2" valign="top"><pre class="screen">OutItrT put(..., date_generator)
700 first_day_of_the_week_in_month</pre></td>
701 <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>
703 <tr><td><pre class="screen">"first Wed of Jun" // defaults</pre></td></tr>
705 <td rowspan="2" valign="top"><pre class="screen">OutItrT put(..., date_generator)
707 last_day_of_the_week_in_month</pre></td>
708 <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>
710 <tr><td><pre class="screen">"last Tue of Mar" // defaults</pre></td></tr>
712 <td rowspan="2" valign="top"><pre class="screen">OutItrT put(..., date_generator)
714 first_day_of_the_week_after</pre></td>
715 <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>
717 <tr><td><pre class="screen">"first Sat after" // defaults</pre></td></tr>
719 <td rowspan="2" valign="top"><pre class="screen">OutItrT put(..., date_generator)
721 first_day_of_the_week_before</pre></td>
722 <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>
724 <tr><td><pre class="screen">"first Mon before" // defaults</pre></td></tr>
730 <div class="section">
731 <div class="titlepage"><div><div><h3 class="title">
732 <a name="date_time.date_input_facet"></a>Date Input Facet</h3></div></div></div>
733 <a class="link" href="date_time_io.html#date_input_facet_intro">Introduction</a> -
734 <a class="link" href="date_time_io.html#date_input_facet_constr">Construction</a> -
735 <a class="link" href="date_time_io.html#date_input_facet_accessors">Accessors</a><a name="date_input_facet_intro"></a><h4>
736 <a name="idp180241216"></a>Introduction</h4>
737 <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>.
739 <a name="date_input_facet_constr"></a><h4>
740 <a name="idp180245984"></a>Construction</h4>
743 <div class="informaltable"><table class="table">
754 <td valign="top"><pre class="screen">date_input_facet()</pre></td>
755 <td>Default constructor</td>
758 <td valign="top"><pre class="screen">date_input_facet(string_type format)</pre></td>
759 <td>Format given will be used for date input. All other formats will use their defaults.</td>
762 <td valign="top"><pre class="screen">date_input_facet(...)
765 format_date_parser_type
766 special_values_parser_type
768 date_gen_parser_type</pre></td>
769 <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>
775 <a name="date_input_facet_accessors"></a><h4>
776 <a name="idp180257728"></a>Accessors</h4>
779 <div class="informaltable"><table class="table">
786 <th rowspan="2" valign="top">Syntax</th>
789 <tr><th>Example</th></tr>
793 <td rowspan="2" valign="top"><pre class="screen">void format(char_type*)</pre></td>
794 <td>Set the format for dates.</td>
796 <tr><td><pre class="screen">date_input_facet* f =
797 new date_input_facet();
798 f->format("%m %d %Y");</pre></td></tr>
800 <td rowspan="2" valign="top"><pre class="screen">void set_iso_format()</pre></td>
801 <td>Sets the date format to ISO</td>
803 <tr><td><pre class="screen">f->set_iso_format();
804 // "%Y%m%d"</pre></td></tr>
806 <td rowspan="2" valign="top"><pre class="screen">void set_iso_extended_format()</pre></td>
807 <td>Sets the date format to ISO Extended</td>
809 <tr><td><pre class="screen">f->set_iso_extended_format();
810 // "%Y-%m-%d"</pre></td></tr>
812 <td rowspan="2" valign="top"><pre class="screen">void month_format(char_type*)</pre></td>
813 <td>Set the format when 'get'ing months individually.</td>
815 <tr><td><pre class="screen">f->month_format("%B");
817 ss >> m; // March</pre></td></tr>
819 <td rowspan="2" valign="top"><pre class="screen">void weekday_format(char_type*)</pre></td>
820 <td>Set the format when 'get'ing weekdays individually.</td>
822 <tr><td><pre class="screen">f->weekday_format("%a");
824 ss >> wd; // Sunday</pre></td></tr>
826 <td rowspan="2" valign="top"><pre class="screen">void year_format(char_type*)</pre></td>
827 <td>Set the format when 'get'ing years individually.</td>
829 <tr><td><pre class="screen">f->weekday_format("%y");
831 ss >> year; // 2004</pre></td></tr>
833 <td rowspan="2" valign="top"><pre class="screen">void period_parser(...)
835 period_parser_type</pre></td>
836 <td>Replaces the period parser object with a user created one.</td>
838 <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>
840 <td rowspan="2" valign="top"><pre class="screen">void special_values_parser(...)
842 special_values_parser_type</pre></td>
843 <td>Replaces the special_values parser object with a user created one.</td>
845 <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>
847 <td rowspan="2" valign="top"><pre class="screen">void date_gen_phrase_strings(...)
849 input_collection_type</pre></td>
850 <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>
852 <tr><td><pre class="screen"></pre></td></tr>
854 <td rowspan="2" valign="top"><pre class="screen">void short_weekday_names(...)
856 input_collection_type</pre></td>
857 <td>Replace strings used when 'getting' short weekdays.</td>
859 <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>
861 <td rowspan="2" valign="top"><pre class="screen">void long_weekday_names(...)
863 input_collection_type</pre></td>
864 <td>Replace strings used when 'getting' long weekdays.</td>
866 <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>
868 <td rowspan="2" valign="top"><pre class="screen">void short_month_names(...)
870 input_collection_type</pre></td>
871 <td>Replace strings used when 'getting' short months.</td>
873 <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>
875 <td rowspan="2" valign="top"><pre class="screen">void long_month_names(...)
877 input_collection_type</pre></td>
878 <td>Replace strings used when 'getting' long months.</td>
880 <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>
882 <td rowspan="2" valign="top"><pre class="screen">InItrT get(...)
883 Common parameters for all
888 Unique parameter for 'get' funcs:
889 gregorian object</pre></td>
890 <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>
892 <tr><td><pre class="screen"></pre></td></tr>
894 <td rowspan="2" valign="top"><pre class="screen">InItrT get(..., date)</pre></td>
895 <td>Gets a date object from the stream using the format set by <code class="computeroutput">format(...)</code> or the default.</td>
897 <tr><td><pre class="screen">ss.str("2005-Jan-01");
898 ss >> d; // default format</pre></td></tr>
900 <td rowspan="2" valign="top"><pre class="screen">InItrT get(..., month)</pre></td>
901 <td>Gets a month object from the stream using the format set by <code class="computeroutput">month_format(...)</code> or the default.</td>
903 <tr><td><pre class="screen">ss.str("Feb");
904 ss >> m; // default format</pre></td></tr>
906 <td rowspan="2" valign="top"><pre class="screen">InItrT get(..., day_of_week)</pre></td>
907 <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>
909 <tr><td><pre class="screen">ss.str("Sun");
910 ss >> dow; // default format</pre></td></tr>
912 <td rowspan="2" valign="top"><pre class="screen">InItrT get(..., day)</pre></td>
913 <td>Gets a day of month object from the stream as a two digit number.</td>
915 <tr><td><pre class="screen">"01" // January 1st</pre></td></tr>
917 <td rowspan="2" valign="top"><pre class="screen">InItrT get(..., year)</pre></td>
918 <td>Gets a year object from the stream as a number. The number of expected digits depends on the year format.</td>
920 <tr><td><pre class="screen">ss/str("2005");
921 ss >> y; // default format</pre></td></tr>
923 <td rowspan="2" valign="top"><pre class="screen">InItrT get(..., days)</pre></td>
924 <td>Gets a days object from the stream as a number.</td>
926 <tr><td><pre class="screen">ss.str("356");
927 ss >> dys; // a full year</pre></td></tr>
929 <td rowspan="2" valign="top"><pre class="screen">InItrT get(..., date_period)</pre></td>
930 <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>
932 <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>
934 <td rowspan="2" valign="top"><pre class="screen">InItrT get(..., partial_date)</pre></td>
935 <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>
937 <tr><td><pre class="screen">"01 Jan" // default formats
938 "01 January" // long month format</pre></td></tr>
940 <td rowspan="2" valign="top"><pre class="screen">InItrT get(..., date_generator)
942 nth_day_of_the_week_in_month</pre></td>
943 <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>
945 <tr><td><pre class="screen">"third Fri in May" // defaults</pre></td></tr>
947 <td rowspan="2" valign="top"><pre class="screen">InItrT get(..., date_generator)
949 first_day_of_the_week_in_month</pre></td>
950 <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>
952 <tr><td><pre class="screen">"first Wed of Jun" // defaults</pre></td></tr>
954 <td rowspan="2" valign="top"><pre class="screen">InItrT get(..., date_generator)
956 last_day_of_the_week_in_month</pre></td>
957 <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>
959 <tr><td><pre class="screen">"last Tue of Mar" // defaults</pre></td></tr>
961 <td rowspan="2" valign="top"><pre class="screen">InItrT get(..., date_generator)
963 first_day_of_the_week_after</pre></td>
964 <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>
966 <tr><td><pre class="screen">"first Sat after" // defaults</pre></td></tr>
968 <td rowspan="2" valign="top"><pre class="screen">InItrT get(..., date_generator)
970 first_day_of_the_week_before</pre></td>
971 <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>
973 <tr><td><pre class="screen">"first Mon before" // defaults</pre></td></tr>
979 <div class="section">
980 <div class="titlepage"><div><div><h3 class="title">
981 <a name="date_time.time_facet"></a>Time Facet</h3></div></div></div>
982 <a class="link" href="date_time_io.html#time_facet_intro">Introduction</a> -
983 <a class="link" href="date_time_io.html#time_facet_constr">Construction</a> -
984 <a class="link" href="date_time_io.html#time_facet_accessors">Accessors</a><a name="time_facet_intro"></a><h4>
985 <a name="idp180378512"></a>Introduction</h4>
986 <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>.
988 <a name="time_facet_constr"></a><h4>
989 <a name="idp180386144"></a>Construction</h4>
992 <div class="informaltable"><table class="table">
1003 <td valign="top"><pre class="screen">time_facet()</pre></td>
1004 <td>Default constructor</td>
1007 <td valign="top"><pre class="screen">time_facet(...)
1010 period_formatter_type
1011 special_values_formatter_type
1012 date_gen_formatter_type</pre></td>
1013 <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>
1019 <a name="time_facet_accessors"></a><h4>
1020 <a name="idp180396752"></a>Accessors</h4>
1022 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.
1024 <div class="informaltable"><table class="table">
1031 <th rowspan="2" valign="top">Syntax</th>
1032 <th>Description</th>
1034 <tr><th>Example</th></tr>
1038 <td rowspan="2" valign="top"><pre class="screen">void time_duration_format(...)
1040 char_type*</pre></td>
1041 <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>
1043 <tr><td><pre class="screen">f->time_duration_format("%+%H:%M");
1044 // hours and minutes only w/ sign always displayed
1045 time_duration td1(3, 15, 56);
1046 time_duration td2(-12, 25, 32);
1047 ss << td1; // "+03:15:56"
1048 ss << td2; // "-12:25:56"
1051 <td rowspan="2" valign="top"><pre class="screen">void set_iso_format()</pre></td>
1052 <td>Sets the date and time format to ISO.</td>
1054 <tr><td><pre class="screen">f->set_iso_format();
1055 // "%Y%m%dT%H%M%S%F%q"</pre></td></tr>
1057 <td rowspan="2" valign="top"><pre class="screen">void set_iso_extended_format()</pre></td>
1058 <td>Sets the date and time format to ISO Extended</td>
1060 <tr><td><pre class="screen">f->set_iso_extended_format();
1061 // "%Y-%m-%d %H:%M:%S%F%Q"</pre></td></tr>
1063 <td rowspan="2" valign="top"><pre class="screen">OutItrT put(...)
1064 Common parameters for all
1069 Unique parameter for 'put' funcs:
1070 posix_time object</pre></td>
1071 <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>
1073 <tr><td><pre class="screen"></pre></td></tr>
1075 <td rowspan="2" valign="top"><pre class="screen">OutItrT put(..., ptime)</pre></td>
1076 <td>Puts a ptime object into the stream using the format set by <code class="computeroutput">format(...)</code> or the default.</td>
1078 <tr><td><pre class="screen"></pre></td></tr>
1080 <td rowspan="2" valign="top"><pre class="screen">OutItrT put(..., time_duration)</pre></td>
1081 <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>
1083 <tr><td><pre class="screen"></pre></td></tr>
1085 <td rowspan="2" valign="top"><pre class="screen">OutItrT put(..., time_period)</pre></td>
1086 <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>
1088 <tr><td><pre class="screen"></pre></td></tr>
1094 <div class="section">
1095 <div class="titlepage"><div><div><h3 class="title">
1096 <a name="date_time.time_input_facet"></a>Time Input Facet</h3></div></div></div>
1097 <a class="link" href="date_time_io.html#time_input_facet_intro">Introduction</a> -
1098 <a class="link" href="date_time_io.html#time_input_facet_constr">Construction</a> -
1099 <a class="link" href="date_time_io.html#time_input_facet_accessors">Accessors</a><a name="time_input_facet_intro"></a><h4>
1100 <a name="idp180436096"></a>Introduction</h4>
1101 <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>.
1103 <a name="time_input_facet_constr"></a><h4>
1104 <a name="idp180443664"></a>Construction</h4>
1107 <div class="informaltable"><table class="table">
1114 <th>Description</th>
1118 <td valign="top"><pre class="screen">time_input_facet()</pre></td>
1119 <td>Default constructor</td>
1122 <td valign="top"><pre class="screen">time_input_facet(string_type)</pre></td>
1123 <td>Format given will be used for date/time input. All other formats will use their defaults.</td>
1126 <td valign="top"><pre class="screen">time_input_facet(...)
1129 format_date_parser_type
1130 special_values_parser_type
1132 date_gen_parser_type</pre></td>
1133 <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>
1139 <a name="time_input_facet_accessors"></a><h4>
1140 <a name="idp180455440"></a>Accessors</h4>
1142 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.
1144 <div class="informaltable"><table class="table">
1151 <th rowspan="2" valign="top">Syntax</th>
1152 <th>Description</th>
1154 <tr><th>Example</th></tr>
1158 <td rowspan="2" valign="top"><pre class="screen">void set_iso_format()</pre></td>
1159 <td>Sets the time format to ISO</td>
1161 <tr><td><pre class="screen">f->set_iso_format();
1162 // "%Y%m%dT%H%M%S%F%q"
1163 "20051225T132536.789-0700"</pre></td></tr>
1165 <td rowspan="2" valign="top"><pre class="screen">void set_iso_extended_format()</pre></td>
1166 <td>Sets the date format to ISO Extended</td>
1168 <tr><td><pre class="screen">f->set_iso_extended_format();
1169 // "%Y-%m-%d %H:%M:%S%F %Q"
1170 "2005-12-25 13:25:36.789 -07:00"</pre></td></tr>
1172 <td rowspan="2" valign="top"><pre class="screen">void time_duration_format(...)
1174 char_type*</pre></td>
1175 <td>Sets the time_duration format.</td>
1177 <tr><td><pre class="screen">f->time_duration_format("%H:%M");
1178 // hours and minutes only</pre></td></tr>
1180 <td rowspan="2" valign="top"><pre class="screen">InItrT get(...)
1181 Common parameters for all
1186 Unique parameter for 'get' funcs:
1187 gregorian object</pre></td>
1188 <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>
1190 <tr><td><pre class="screen"></pre></td></tr>
1192 <td rowspan="2" valign="top"><pre class="screen">InItrT get(..., ptime)</pre></td>
1193 <td>Gets a ptime object from the stream using the format set by <code class="computeroutput">format(...)</code> or the default.</td>
1195 <tr><td><pre class="screen">ss.str("2005-Jan-01 13:12:01");
1196 ss >> pt; // default format</pre></td></tr>
1198 <td rowspan="2" valign="top"><pre class="screen">InItrT get(..., time_duration)</pre></td>
1199 <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>
1201 <tr><td><pre class="screen">ss.str("01:25:15.000123000");
1202 ss >> td; // default format</pre></td></tr>
1204 <td rowspan="2" valign="top"><pre class="screen">InItrT get(..., time_period)</pre></td>
1205 <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>
1207 <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>
1213 <div class="section">
1214 <div class="titlepage"><div><div><h3 class="title">
1215 <a name="date_time.io_objects"></a>Date Time Formatter/Parser Objects</h3></div></div></div>
1217 <a name="idp180490496"></a>Date Time Formatter/Parser Objects</h3>
1218 <a class="link" href="date_time_io.html#io_objects.periods">Periods</a> |
1219 <a class="link" href="date_time_io.html#io_objects.date_generators">Date Generators</a> |
1220 <a class="link" href="date_time_io.html#io_objects.special_values">Special Values</a> |
1221 <a class="link" href="date_time_io.html#io_objects.format_date_parser">Format Date Parser</a><a name="io_objects.periods"></a><h4>
1222 <a name="idp180495856"></a>Periods</h4>
1223 <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>
1225 <a name="idp180497296"></a>Period Form</h5>
1226 <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>
1227 <pre class="screen">[2003-Jan-01/2003-Dec-31] <-- period holding 365 days
1228 [2003-Jan-01/2004-Jan-01) <-- period holding 365 days</pre>
1230 <a name="idp180499568"></a>Delimiters</h5>
1231 <p>There are four delimiters. The default values are</p>
1232 <table border="0" summary="Simple list" class="simplelist">
1233 <tr><td>"\" - separator</td></tr>
1234 <tr><td>"[" - start delimiter</td></tr>
1235 <tr><td>")" - open range end delimiter</td></tr>
1236 <tr><td>"]" - closed range end delimiter</td></tr>
1238 <p>A user can provide a custom set of delimiters. Custom delimiters may contain spaces.</p>
1240 <a name="idp180503344"></a>Customization</h5>
1241 <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>
1243 <a name="idp180504688"></a>Period Formatter/Parser Reference</h5>
1244 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>
1247 <a name="idp180508240"></a>Period Formatter Construction</h5>
1250 <div class="informaltable"><table class="table">
1256 <th valign="top">Syntax</th>
1257 <th>Description</th>
1260 <td valign="top"><pre class="screen">period_formatter(...)
1262 range_display_options
1266 char_type*</pre></td>
1267 <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>
1273 <a name="idp180516368"></a>Period Formatter Accessors</h5>
1276 <div class="informaltable"><table class="table">
1283 <th rowspan="2" valign="top">Syntax</th>
1284 <th>Description</th>
1286 <tr><th>Example</th></tr>
1290 <td rowspan="2" valign="top"><pre class="screen">range_display_options range_option()</pre></td>
1291 <td>Returns the current setting for the range display (either AS_OPEN_RANGE or AS_CLOSED_RANGE).</td>
1293 <tr><td><pre class="screen"></pre></td></tr>
1295 <td rowspan="2" valign="top"><pre class="screen">void range_option(...)
1297 range_display_options</pre></td>
1298 <td>Sets the option for range display (either AS_OPEN_RANGE or AS_CLOSED_RANGE).</td>
1300 <tr><td><pre class="screen"></pre></td></tr>
1302 <td rowspan="2" valign="top"><pre class="screen">void delimiter_strings(...)
1307 string_type</pre></td>
1308 <td>Set new delimiter strings in the formatter.</td>
1310 <tr><td><pre class="screen">string beg("->| ");
1312 string opn(" ->|");
1313 string clo(" |<-");
1314 pf.delimiter_strings(beg, sep,
1315 opn, clo);</pre></td></tr>
1317 <td rowspan="2" valign="top"><pre class="screen">put_period_start_delimeter(...)
1322 <td>Puts the start delimiter into the stream at position pointed to by OutItrT parameter.</td>
1324 <tr><td><pre class="screen"></pre></td></tr>
1326 <td rowspan="2" valign="top"><pre class="screen">put_period_sepatator(...)
1331 <td>Puts the separator into the stream at position pointed to by OutItrT parameter.</td>
1333 <tr><td><pre class="screen"></pre></td></tr>
1335 <td rowspan="2" valign="top"><pre class="screen">put_period_end_delimeter(...)
1340 <td>Puts the end delimiter into the stream at position pointed to by OutItrT parameter.</td>
1342 <tr><td><pre class="screen"></pre></td></tr>
1344 <td rowspan="2" valign="top"><pre class="screen">OutItrT put_period(...)
1350 facet_type</pre></td>
1351 <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>
1353 <tr><td><pre class="screen"></pre></td></tr>
1361 <a name="idp180545456"></a>Period Parser Construction</h5>
1364 <div class="informaltable"><table class="table">
1370 <th valign="top">Syntax</th>
1371 <th>Description</th>
1375 <td valign="top"><pre class="screen">period_parser(...)
1381 char_type*</pre></td>
1382 <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>
1385 <td valign="top"><pre class="screen">period_parser(period_parser)</pre></td>
1386 <td>Copy constructor</td>
1393 <a name="idp180555440"></a>Period Parser Accessors</h5>
1396 <div class="informaltable"><table class="table">
1403 <th rowspan="2" valign="top">Syntax</th>
1404 <th>Description</th>
1406 <tr><th>Example</th></tr>
1410 <td rowspan="2" valign="top"><pre class="screen">period_range_option range_option()</pre></td>
1411 <td>Returns the current setting for the period range (either AS_OPEN_RANGE or AS_CLOSED_RANGE).</td>
1413 <tr><td><pre class="screen"></pre></td></tr>
1415 <td rowspan="2" valign="top"><pre class="screen">void range_option(...)
1417 period_range_option </pre></td>
1418 <td>Sets the option for period range (either AS_OPEN_RANGE or AS_CLOSED_RANGE).</td>
1420 <tr><td><pre class="screen"></pre></td></tr>
1422 <td rowspan="2" valign="top"><pre class="screen">void delimiter_strings(...)
1427 string_type</pre></td>
1428 <td>Set new delimiter strings in the parser.</td>
1430 <tr><td><pre class="screen">string beg("->| ");
1432 string opn(" ->|");
1433 string clo(" |<-");
1434 pp.delimiter_strings(beg, sep,
1435 opn, clo);</pre></td></tr>
1437 <td rowspan="2" valign="top"><pre class="screen">collection_type delimiter_strings()</pre></td>
1438 <td>Returns the set of delimiter strings currently held in the parser.</td>
1440 <tr><td><pre class="screen"></pre></td></tr>
1442 <td rowspan="2" valign="top"><pre class="screen">period_type get_period(...)
1449 facet_type</pre></td>
1450 <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>
1452 <tr><td><pre class="screen"></pre></td></tr>
1457 <p>_____________________________________________________</p>
1458 <a name="io_objects.date_generators"></a><h4>
1459 <a name="idp180580432"></a>Date Generators</h4>
1460 <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>
1462 <a name="idp180582112"></a>Customization</h5>
1463 <p>The default "phrase_strings" are:
1465 <table border="0" summary="Simple list" class="simplelist"><tr>
1477 A custom set of phrase_strings must maintain this order of occurance (Ex: "1st", "2nd", "3rd", "4th", "5th", "last", "prior", "past", "in").</p>
1478 <p> Examples using default phrase_strings and default facet formats for weekday & month: </p>
1479 <pre class="screen">"first Tue of Mar"</pre>
1480 <p>And using custom phrase_strings: </p>
1481 <pre class="screen">"1st Tue in Mar"</pre>
1484 <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>
1485 <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>
1487 <a name="idp180591248"></a>Date Generator Reference</h5>
1488 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>
1491 <a name="idp180594848"></a>Date Generator Formatter Construction</h5>
1494 <div class="informaltable"><table class="table">
1500 <th valign="top">Syntax</th>
1501 <th>Description</th>
1505 <td valign="top"><pre class="screen">date_generator_formatter()</pre></td>
1506 <td>Uses the default date generator elements.</td>
1509 <td valign="top"><pre class="screen">date_generator_formatter(...)
1511 string_type first_element
1512 string_type second_element
1513 string_type third_element
1514 string_type fourth_element
1515 string_type fifth_element
1516 string_type last_element
1517 string_type before_element
1518 string_type after_element
1519 string_type of_element</pre></td>
1520 <td>Constructs a date_generator_formatter using the given element strings.</td>
1527 <a name="idp180603136"></a>Date Generator Formatter Accessors</h5>
1530 <div class="informaltable"><table class="table">
1537 <th rowspan="2" valign="top">Syntax</th>
1538 <th>Description</th>
1540 <tr><th>Example</th></tr>
1544 <td rowspan="2" valign="top"><pre class="screen">void elements(...)
1547 phrase_elements</pre></td>
1548 <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>
1550 <tr><td><pre class="screen">// col is a collection holding
1551 // "final", "prior", "following",
1553 typedef date_generator_formatter dgf;
1555 formatter.elements(col, dgf::last);
1556 // complete elements in dgf are now:
1557 "first", "second", "third",
1558 "fourth", "fifth", "final",
1559 "prior", "following", and "in"</pre></td></tr>
1561 <td rowspan="2" valign="top"><pre class="screen">put_partial_date(...)
1569 facet_type</pre></td>
1570 <td>A put function for partial_date. This is a templated function that takes a facet_type as a parameter.</td>
1572 <tr><td>Put a partial_date => "dd Month".</td></tr>
1574 <td rowspan="2" valign="top"><pre class="screen">put_nth_kday(...)
1582 facet_type</pre></td>
1583 <td>A put function for nth_kday_type. This is a templated function that takes a facet_type as a parameter.</td>
1585 <tr><td>Put an nth_day_of_the_week_in_month => "nth weekday of month".</td></tr>
1587 <td rowspan="2" valign="top"><pre class="screen">put_first_kday(...)
1595 facet_type</pre></td>
1596 <td>A put function for first_kday_type. This is a templated function that takes a facet_type as a parameter.</td>
1598 <tr><td>Put a first_day_of_the_week_in_month => "first weekday of month".</td></tr>
1600 <td rowspan="2" valign="top"><pre class="screen">put_last_kday(...)
1608 facet_type</pre></td>
1609 <td>A put function for last_kday_type. This is a templated function that takes a facet_type as a parameter.</td>
1611 <tr><td>Put a last_day_of_the_week_in_month => "last weekday of month".</td></tr>
1613 <td rowspan="2" valign="top"><pre class="screen">put_kday_before(...)
1621 facet_type</pre></td>
1622 <td>A put function for kday_before_type. This is a templated function that takes a facet_type as a parameter.</td>
1624 <tr><td>Put a first_day_of_the_week_before => "weekday before"</td></tr>
1626 <td rowspan="2" valign="top"><pre class="screen">put_kday_after(...)
1634 facet_type</pre></td>
1635 <td>A put function for kday_after_type. This is a templated function that takes a facet_type as a parameter.</td>
1637 <tr><td>Put a first_day_of_the_week_after => "weekday after".</td></tr>
1645 <a name="idp180632400"></a>Date Generator Parser Construction</h5>
1648 <div class="informaltable"><table class="table">
1654 <th valign="top">Syntax</th>
1655 <th>Description</th>
1659 <td valign="top"><pre class="screen">date_generator_parser()</pre></td>
1660 <td>Uses the default date generator elements.</td>
1663 <td valign="top"><pre class="screen">date_generator_parser(...)
1665 date_generator_parser</pre></td>
1666 <td>Copy Constructor</td>
1669 <td valign="top"><pre class="screen">date_generator_parser(...)
1671 string_type first_element
1672 string_type second_element
1673 string_type third_element
1674 string_type fourth_element
1675 string_type fifth_element
1676 string_type last_element
1677 string_type before_element
1678 string_type after_element
1679 string_type of_element</pre></td>
1680 <td>Constructs a date_generator_parser using the given element strings.</td>
1687 <a name="idp180642560"></a>Date Generator Parser Accessors</h5>
1690 <div class="informaltable"><table class="table">
1697 <th rowspan="2" valign="top">Syntax</th>
1698 <th>Description</th>
1700 <tr><th>Example</th></tr>
1704 <td rowspan="2" valign="top"><pre class="screen">void element_strings(...)
1706 collection_type</pre></td>
1707 <td>Replace the set of date generator element string with a new set.</td>
1709 <tr><td><pre class="screen"></pre></td></tr>
1711 <td rowspan="2" valign="top"><pre class="screen">void element_strings(...)
1721 string_type of</pre></td>
1722 <td>Replace the set of date generator elements with new values.</td>
1724 <tr><td><pre class="screen"></pre></td></tr>
1726 <td rowspan="2" valign="top"><pre class="screen">get_partial_date_type(...)
1728 facet_type::partial_date_type
1730 stream_itr_type next
1731 stream_itr_type str_end
1733 facet_type</pre></td>
1734 <td>A templated function that parses a date_generator from the stream.</td>
1736 <tr><td>Parses a partial_date => "dd Month".</td></tr>
1738 <td rowspan="2" valign="top"><pre class="screen">get_nth_kday_type(...)
1740 facet_type::nth_kday_type
1742 stream_itr_type next
1743 stream_itr_type str_end
1745 facet_type</pre></td>
1746 <td>A templated function that parses a date_generator from the stream.</td>
1748 <tr><td>Parses an nth_day_of_the_week_in_month => "nth weekday of month".</td></tr>
1750 <td rowspan="2" valign="top"><pre class="screen">get_first_kday_type(...)
1752 facet_type::firat_kday_type
1754 stream_itr_type next
1755 stream_itr_type str_end
1757 facet_type</pre></td>
1758 <td>A templated function that parses a date_generator from the stream.</td>
1760 <tr><td>Parses a first_day_of_the_week_in_month => "first weekday of month".</td></tr>
1762 <td rowspan="2" valign="top"><pre class="screen">get_last_kday_type(...)
1764 facet_type::last_kday_type
1766 stream_itr_type next
1767 stream_itr_type str_end
1769 facet_type</pre></td>
1770 <td>A templated function that parses a date_generator from the stream.</td>
1772 <tr><td>Parses a last_day_of_the_week_in_month => "last weekday of month".</td></tr>
1774 <td rowspan="2" valign="top"><pre class="screen">get_kday_before_type(...)
1776 facet_type::kday_before_type
1778 stream_itr_type next
1779 stream_itr_type str_end
1781 facet_type</pre></td>
1782 <td>A templated function that parses a date_generator from the stream.</td>
1784 <tr><td>Parses a first_day_of_the_week_before => "weekday before"</td></tr>
1786 <td rowspan="2" valign="top"><pre class="screen">get_kday_after_type(...)
1788 facet_type::kday_after_type
1790 stream_itr_type next
1791 stream_itr_type str_end
1793 facet_type</pre></td>
1794 <td>A templated function that parses a date_generator from the stream.</td>
1796 <tr><td>Parses a first_day_of_the_week_after => "weekday after".</td></tr>
1801 <p>_____________________________________________________</p>
1802 <a name="io_objects.special_values"></a><h4>
1803 <a name="idp180674672"></a>Special Values</h4>
1804 <p>The date_time library uses five special_values. They are:
1806 <table border="0" summary="Simple list" class="simplelist"><tr>
1807 <td>not_a_date_time</td>
1810 <td>min_date_time</td>
1811 <td>max_date_time</td>
1815 <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>
1817 <a name="idp180679488"></a>Customization</h5>
1818 <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>
1820 <a name="idp180680800"></a>Special Values Formatter/Parser Reference</h5>
1821 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>
1824 <a name="idp180684368"></a>Special Values Formatter Constructor</h5>
1827 <div class="informaltable"><table class="table">
1833 <th valign="top">Syntax</th>
1834 <th>Description</th>
1838 <td valign="top"><pre class="screen">special_values_formatter()</pre></td>
1839 <td>Constructor uses defaults for special value strings.</td>
1842 <td valign="top"><pre class="screen">special_values_formatter(...)
1844 collection_type::iterator
1845 collection_type::iterator</pre></td>
1846 <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>
1849 <td valign="top"><pre class="screen">special_values_formatter(...)
1852 char_type*</pre></td>
1853 <td>Constructs special values formatter from an array of strings.</td>
1862 <a name="idp180694944"></a>Special Values Formatter Accessors</h5>
1865 <div class="informaltable"><table class="table">
1872 <th rowspan="2" valign="top">Syntax</th>
1873 <th>Description</th>
1875 <tr><th>Example</th></tr>
1879 <td rowspan="2" valign="top"><pre class="screen">OutItrT put_special(...)
1882 special_values value</pre></td>
1883 <td>Puts the given special value into the stream.</td>
1885 <tr><td><pre class="screen">date d1(not_a_date_time);
1886 date d2(minimum_date_time);
1887 special_values_formatter formatter;
1888 formatter.put_special(itr, d1);
1889 // Puts: "not-a-date-time"
1890 formatter.put_special(itr, d2);
1891 // Puts: "1400-Jan-01"</pre></td></tr>
1899 <a name="idp180704128"></a>Special Values Parser Constructor</h5>
1902 <div class="informaltable"><table class="table">
1908 <th valign="top">Syntax</th>
1909 <th>Description</th>
1913 <td valign="top"><pre class="screen">special_values_parser()</pre></td>
1917 <td valign="top"><pre class="screen">special_values_parser(...)
1919 collection_type::iterator
1920 collection_type::iterator</pre></td>
1921 <td>Constructs a special values parser using the strings in the collection.</td>
1924 <td valign="top"><pre class="screen">special_values_parser(...)
1926 scpecial_values_parser</pre></td>
1927 <td>Copy constructor.</td>
1930 <td valign="top"><pre class="screen">special_values_parser(...)
1932 string_type nadt_str
1933 string_type neg_inf_str
1934 string_type pos_inf_str
1935 string_type min_dt_str
1936 string_type max_dt_str</pre></td>
1937 <td>Constructs a special values parser using the supplied strings.</td>
1946 <a name="idp180716336"></a>Special Values Parser Accessors</h5>
1949 <div class="informaltable"><table class="table">
1956 <th rowspan="2" valign="top">Syntax</th>
1957 <th>Description</th>
1959 <tr><th>Example</th></tr>
1963 <td rowspan="2" valign="top"><pre class="screen">void sv_strings(...)
1965 string_type nadt_str
1966 string_type neg_inf_str
1967 string_type pos_inf_str
1968 string_type min_dt_str
1969 string_type max_dt_str</pre></td>
1970 <td>Replace the set of special value strings with the given ones.</td>
1972 <tr><td><pre class="screen"></pre></td></tr>
1974 <td rowspan="2" valign="top"><pre class="screen">bool match(...)
1978 match_results</pre></td>
1979 <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>
1981 <tr><td><pre class="screen">// stream holds "maximum_date_time"
1982 typedef special_values_parser svp;
1984 svp::match_results mr;
1985 if(parser.match(itr, str_end, mr)) {
1986 d = date(static_cast<special_values>(
1989 // error, failed parse
1991 // d == "9999-Dec-31"</pre></td></tr>
1996 <p>_____________________________________________________</p>
1997 <a name="io_objects.format_date_parser"></a><h4>
1998 <a name="idp180730704"></a>Format Date Parser</h4>
1999 <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>
2001 <a name="idp180732160"></a>Format Date Parser Reference</h5>
2002 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>
2005 <a name="idp180734416"></a>Format Date Parser Constructor</h5>
2008 <div class="informaltable"><table class="table">
2014 <th valign="top">Syntax</th>
2015 <th>Description</th>
2019 <td valign="top"><pre class="screen">format_date_parser(...)
2022 std::locale</pre></td>
2023 <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>
2026 <td valign="top"><pre class="screen">format_date_parser(...)
2029 input_collection_type
2030 input_collection_type
2031 input_collection_type
2032 input_collection_type</pre></td>
2033 <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>
2036 <td valign="top"><pre class="screen">format_date_parser(...)
2038 format_date_parser</pre></td>
2039 <td>Copy Constructor</td>
2048 <a name="idp180745248"></a>Format Date Parser Accessors</h5>
2051 <div class="informaltable"><table class="table">
2058 <th rowspan="2" valign="top">Syntax</th>
2059 <th>Description</th>
2061 <tr><th>Example</th></tr>
2065 <td rowspan="2" valign="top"><pre class="screen">string_type format()</pre></td>
2066 <td>Returns the format that will be used when parsing dates in those functions where there is no format parameter.</td>
2068 <tr><td><pre class="screen"></pre></td></tr>
2070 <td rowspan="2" valign="top"><pre class="screen">void format(string_type)</pre></td>
2071 <td>Sets the format that will be used when parsing dates in those functions where there is no format parameter.</td>
2073 <tr><td><pre class="screen"></pre></td></tr>
2075 <td rowspan="2" valign="top"><pre class="screen">void short_month_names(...)
2077 input_collection_type names</pre></td>
2078 <td>Replace the short month names used by the parser. The collection must contain values for each month, starting with January.</td>
2080 <tr><td><pre class="screen"></pre></td></tr>
2082 <td rowspan="2" valign="top"><pre class="screen">void long_month_names(...)
2084 input_collection_type names</pre></td>
2085 <td>Replace the long month names used by the parser. The collection must contain values for each month, starting with January.</td>
2087 <tr><td><pre class="screen"></pre></td></tr>
2089 <td rowspan="2" valign="top"><pre class="screen">void short_weekday_names(...)
2091 input_collection_type names</pre></td>
2092 <td>Replace the short weekday names used by the parser. The collection must contain values for each weekday, starting with Sunday.</td>
2094 <tr><td><pre class="screen"></pre></td></tr>
2096 <td rowspan="2" valign="top"><pre class="screen">void long_weekday_names(...)
2098 input_collection_type names</pre></td>
2099 <td>Replace the long weekday names used by the parser. The collection must contain values for each weekday, starting with Sunday.</td>
2101 <tr><td><pre class="screen"></pre></td></tr>
2103 <td rowspan="2" valign="top"><pre class="screen">date_type parse_date(...)
2107 special_values_parser</pre></td>
2108 <td>Parse a date from the given input using the given format.</td>
2110 <tr><td><pre class="screen">string inp("2005-Apr-15");
2111 string format("%Y-%b-%d");
2113 d = parser.parse_date(inp,
2116 // d == 2005-Apr-15</pre></td></tr>
2118 <td rowspan="2" valign="top"><pre class="screen">date_type parse_date(...)
2120 istreambuf_iterator input
2121 istreambuf_iterator str_end
2122 special_values_parser</pre></td>
2123 <td>Parse a date from stream using the parser's format.</td>
2125 <tr><td><pre class="screen"></pre></td></tr>
2127 <td rowspan="2" valign="top"><pre class="screen">date_type parse_date(...)
2129 istreambuf_iterator input
2130 istreambuf_iterator str_end
2132 special_values_parser</pre></td>
2133 <td>Parse a date from stream using the given format.</td>
2135 <tr><td><pre class="screen">// stream holds "2005-04-15"
2136 string format("%Y-%m-%d");
2138 d = parser.parse_date(itr,
2142 // d == 2005-Apr-15</pre></td></tr>
2144 <td rowspan="2" valign="top"><pre class="screen">month_type parse_month(...)
2146 istreambuf_iterator input
2147 istreambuf_iterator str_end
2148 string_type format</pre></td>
2149 <td>Parses a month from stream using given format. Throws bad_month if unable to parse.</td>
2151 <tr><td><pre class="screen">// stream holds "March"
2152 string format("%B");
2154 m = parser.parse_month(itr,
2157 // m == March</pre></td></tr>
2159 <td rowspan="2" valign="top"><pre class="screen">day_type parse_day_of_month(...)
2161 istreambuf_iterator input
2162 istreambuf_iterator str_end</pre></td>
2163 <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>
2165 <tr><td><pre class="screen">// stream holds "01"
2167 d = parser.parse_day_of_month(itr,
2169 // d == 1st</pre></td></tr>
2171 <td rowspan="2" valign="top"><pre class="screen">day_type parse_var_day_of_month(...)
2173 istreambuf_iterator input
2174 istreambuf_iterator str_end</pre></td>
2175 <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>
2177 <tr><td><pre class="screen">// stream holds "1"
2179 d = parser.parse_var_day_of_month(itr,
2181 // d == 1st</pre></td></tr>
2183 <td rowspan="2" valign="top"><pre class="screen">day_of_week_type parse_weekday(...)
2185 istreambuf_iterator input
2186 istreambuf_iterator str_end
2187 string_type format</pre></td>
2188 <td>Parse a weekday from stream according to the given format. Throws a bad_weekday if unable to parse.</td>
2190 <tr><td><pre class="screen">// stream holds "Tue"
2191 string format("%a");
2193 wd = parser.parse_weekday(itr,
2196 // wd == Tuesday</pre></td></tr>
2198 <td rowspan="2" valign="top"><pre class="screen">year_type parse_year(...)
2200 istreambuf_iterator input
2201 istreambuf_iterator str_end
2202 string_type format</pre></td>
2203 <td>Parse a year from stream according to given format. Throws bad year if unable to parse.</td>
2205 <tr><td><pre class="screen">// stream holds "98"
2206 string format("%y");
2208 y = parser.parse_year(itr,
2211 // y == 1998</pre></td></tr>
2217 <div class="section">
2218 <div class="titlepage"><div><div><h3 class="title">
2219 <a name="date_time.io_tutorial"></a>Date Time IO Tutorial</h3></div></div></div>
2221 <a name="idp180800128"></a>Date Time IO Tutorial</h3>
2222 <a class="link" href="date_time_io.html#basic_use">Basic Use</a> |
2223 <a class="link" href="date_time_io.html#format_strings">Format Strings</a> |
2224 <a class="link" href="date_time_io.html#content_strings">Content Strings</a> |
2225 <a class="link" href="date_time_io.html#tut_sv">Special Values</a> |
2226 <a class="link" href="date_time_io.html#tut_dper">Date/Time Periods</a> |
2227 <a class="link" href="date_time_io.html#tut_dgen">Date Generators</a><a name="basic_use"></a><h5>
2228 <a name="idp180807328"></a>Basic Use</h5>
2229 <p>Facets are automatically imbued when operators '>>' and '<<' are called. The list of date_time objects that can be streamed are:</p>
2231 <a name="idp180808720"></a>Gregorian</h6>
2233 <code class="computeroutput">date</code>,
2234 <code class="computeroutput">days</code>,
2235 <code class="computeroutput">date_period</code>,
2236 <code class="computeroutput">greg_month</code>,
2237 <code class="computeroutput">greg_weekday</code>,
2238 <code class="computeroutput">greg_year</code>,
2239 <code class="computeroutput">partial_date</code>,
2240 <code class="computeroutput">nth_day_of_the_week_in_month</code>,
2241 <code class="computeroutput">first_day_of_the_week_in_month</code>,
2242 <code class="computeroutput">last_day_of_the_week_in_month</code>,
2243 <code class="computeroutput">first_day_of_the_week_after</code>,
2244 <code class="computeroutput">first_day_of_the_week_before</code>
2247 <a name="idp180818480"></a>Posix_time</h6>
2249 <code class="computeroutput">ptime</code>,
2250 <code class="computeroutput">time_period</code>,
2251 <code class="computeroutput">time_duration</code>
2254 <a name="idp180821680"></a>Local_time</h6>
2256 <code class="computeroutput">local_date_time</code>
2259 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/examples/tutorial</code> directory)
2261 <pre class="programlisting">
2263 date d(2004, Feb, 29);
2264 time_duration td(12,34,56,789);
2266 ss << d << ' ' << td;
2267 ptime pt(not_a_date_time);
2268 cout << pt << endl; // "not-a-date-time"
2270 cout << pt << endl; // "2004-Feb-29 12:34:56.000789"
2272 ss << pt << " EDT-05EDT,M4.1.0,M10.5.0";
2273 local_date_time ldt(not_a_date_time);
2275 cout << ldt << endl; // "2004-Feb-29 12:34:56.000789 EDT"
2278 <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>
2279 <a name="format_strings"></a><h5>
2280 <a name="idp180828208"></a>Format Strings</h5>
2281 <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>
2282 (continued from previous example)
2283 <pre class="programlisting">
2285 local_time_facet* output_facet = new local_time_facet();
2286 local_time_input_facet* input_facet = new local_time_input_facet();
2287 ss.imbue(locale(locale::classic(), output_facet));
2288 ss.imbue(locale(ss.getloc(), input_facet));
2290 output_facet->format("%a %b %d, %H:%M %z");
2293 cout << ss.str() << endl; // "Sun Feb 29, 12:34 EDT"
2295 output_facet->format(local_time_facet::iso_time_format_specifier);
2298 cout << ss.str() << endl; // "20040229T123456.000789-0500"
2300 output_facet->format(local_time_facet::iso_time_format_extended_specifier);
2303 cout << ss.str() << endl; // "2004-02-29 12:34:56.000789-05:00"
2306 <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>
2307 (continued from previous example)
2308 <pre class="programlisting">
2310 // extra words in format
2311 string my_format("The extended ordinal time %Y-%jT%H:%M can also be \
2312 represented as %A %B %d, %Y");
2313 output_facet->format(my_format.c_str());
2314 input_facet->format(my_format.c_str());
2317 cout << ss.str() << endl;
2319 // matching extra words in input
2320 ss.str("The extended ordinal time 2005-128T12:15 can also be \
2321 represented as Sunday May 08, 2005");
2323 cout << ldt << endl;
2326 <a name="content_strings"></a><h5>
2327 <a name="idp180834256"></a>Content Strings</h5>
2328 <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>
2329 <p>The default values for these are as follows:</p>
2331 <a name="idp180836176"></a>Special values</h6>
2333 <code class="computeroutput">not-a-date-time</code>,
2334 <code class="computeroutput">-infinity</code>,
2335 <code class="computeroutput">+infinity</code>,
2336 <code class="computeroutput">minimum-date-time</code>,
2337 <code class="computeroutput">maximum-date-time</code>
2340 <a name="idp180840816"></a>Months</h6>
2342 <code class="computeroutput">English calendar and three letter abbreviations</code>
2345 <a name="idp180842608"></a>Weekdays</h6>
2347 <code class="computeroutput">English calendar and three letter abbreviations</code>
2350 <a name="idp180844400"></a>Date generator phrase elements</h6>
2352 <code class="computeroutput">first</code>,
2353 <code class="computeroutput">second</code>,
2354 <code class="computeroutput">third</code>,
2355 <code class="computeroutput">fourth</code>,
2356 <code class="computeroutput">fifth</code>,
2357 <code class="computeroutput">last</code>,
2358 <code class="computeroutput">before</code>,
2359 <code class="computeroutput">after</code>,
2360 <code class="computeroutput">of</code>
2362 <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>
2364 <a name="idp180852544"></a>Content Strings</h5>
2365 <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>
2366 (continued from previous example)
2367 <pre class="programlisting">
2369 // set up the collections of custom strings.
2370 // only the full names are altered for the sake of brevity
2371 string month_names[12] = { "january", "february", "march",
2372 "april", "may", "june",
2373 "july", "august", "september",
2374 "october", "november", "december" };
2375 vector<string> long_months(&month_names[0], &month_names[12]);
2376 string day_names[7] = { "sunday", "monday", "tuesday", "wednesday",
2377 "thursday", "friday", "saturday" };
2378 vector<string> long_days(&day_names[0], &day_names[7]);
2380 // create date_facet and date_input_facet using all defaults
2381 date_facet* date_output = new date_facet();
2382 date_input_facet* date_input = new date_input_facet();
2383 ss.imbue(locale(ss.getloc(), date_output));
2384 ss.imbue(locale(ss.getloc(), date_input));
2386 // replace names in the output facet
2387 date_output->long_month_names(long_months);
2388 date_output->long_weekday_names(long_days);
2390 // replace names in the input facet
2391 date_input->long_month_names(long_months);
2392 date_input->long_weekday_names(long_days);
2394 // customize month, weekday and date formats
2395 date_output->format("%Y-%B-%d");
2396 date_input->format("%Y-%B-%d");
2397 date_output->month_format("%B"); // full name
2398 date_input->month_format("%B"); // full name
2399 date_output->weekday_format("%A"); // full name
2400 date_input->weekday_format("%A"); // full name
2403 ss << greg_month(3);
2404 cout << ss.str() << endl; // "march"
2406 ss << greg_weekday(3);
2407 cout << ss.str() << endl; // "tuesday"
2409 ss << date(2005,Jul,4);
2410 cout << ss.str() << endl; // "2005-july-04"
2413 <a name="tut_sv"></a><h5>
2414 <a name="idp180857360"></a>Special Values</h5>
2415 <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>
2416 (continued from previous example)
2417 <pre class="programlisting">
2419 // reset the formats to defaults
2420 output_facet->format(local_time_facet::default_time_format);
2421 input_facet->format(local_time_input_facet::default_time_input_format);
2423 // create custom special_values parser and formatter objects
2424 // and add them to the facets
2425 string sv[5] = {"nadt","neg_inf", "pos_inf", "min_dt", "max_dt" };
2426 vector<string> sv_names(&sv[0], &sv[5]);
2427 special_values_parser sv_parser(sv_names.begin(), sv_names.end());
2428 special_values_formatter sv_formatter(sv_names.begin(), sv_names.end());
2429 output_facet->special_values_formatter(sv_formatter);
2430 input_facet->special_values_parser(sv_parser);
2433 ldt = local_date_time(not_a_date_time);
2435 cout << ss.str() << endl; // "nadt"
2441 cout << ss.str() << endl; // "1400-Jan-01 00:00:00 UTC"
2444 <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>
2445 <a name="tut_dper"></a><h5>
2446 <a name="idp180862080"></a>Date/Time Periods</h5>
2447 <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>
2448 (continued from previous example)
2449 <pre class="programlisting">
2451 // all formats set back to defaults (not shown for brevity)
2453 // create our date_period
2454 date_period dp(date(2005,Mar,1), days(31)); // month of march
2456 // custom period formatter and parser
2457 period_formatter per_formatter(period_formatter::AS_OPEN_RANGE,
2458 " to ", "from ", " exclusive", " inclusive" );
2459 period_parser per_parser(period_parser::AS_OPEN_RANGE,
2460 " to ", "from ", " exclusive" , "inclusive" );
2465 cout << ss.str() << endl; // "[2005-Mar-01/2005-Mar-31]"
2467 // add out custom parser and formatter to the facets
2468 date_output->period_formatter(per_formatter);
2469 date_input->period_parser(per_parser);
2474 cout << ss.str() << endl; // "from 2005-Feb-01 to 2005-Apr-01 exclusive"
2477 <a name="tut_dgen"></a><h5>
2478 <a name="idp180865760"></a>Date Generators</h5>
2479 <p>Customizing the input and output of date_generators is done by replacing the existing strings (in the facet) with new strings.</p>
2480 <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>
2481 (continued from previous example)
2482 <pre class="programlisting">
2484 // custom date_generator phrases
2485 string dg_phrases[9] = { "1st", "2nd", "3rd", "4th", "5th",
2486 "final", "prior to", "following", "in" };
2487 vector<string> phrases(&dg_phrases[0], &dg_phrases[9]);
2489 // create our date_generator
2490 first_day_of_the_week_before d_gen(Monday);
2495 cout << ss.str() << endl; // "Mon before"
2497 // add our custom strings to the date facets
2498 date_output->date_gen_phrase_strings(phrases);
2499 date_input->date_gen_element_strings(phrases);
2504 cout << ss.str() << endl; // "Mon prior to"
2509 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
2510 <td align="left"></td>
2511 <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
2512 <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>
2516 <div class="spirit-nav">
2517 <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>