Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/doc/html/date_time/local_time.html @ 46

Last change on this file since 46 was 29, checked in by landauf, 17 years ago

updated boost from 1_33_1 to 1_34_1

File size: 67.1 KB
Line 
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
4<title>Local Time</title>
5<link rel="stylesheet" href="../boostbook.css" type="text/css">
6<meta name="generator" content="DocBook XSL Stylesheets V1.68.1">
7<link rel="start" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
8<link rel="up" href="../date_time.html" title="Chapter 4. Boost.Date_Time">
9<link rel="prev" href="posix_time.html" title="Posix Time">
10<link rel="next" href="date_time_io.html" title="Date Time Input/Output">
11</head>
12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13<table cellpadding="2" width="100%">
14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
15<td align="center"><a href="../../../index.htm">Home</a></td>
16<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
17<td align="center"><a href="../../../people/people.htm">People</a></td>
18<td align="center"><a href="../../../more/faq.htm">FAQ</a></td>
19<td align="center"><a href="../../../more/index.htm">More</a></td>
20</table>
21<hr>
22<div class="spirit-nav">
23<a accesskey="p" href="posix_time.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../date_time.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="date_time_io.html"><img src="../images/next.png" alt="Next"></a>
24</div>
25<div class="section" lang="en">
26<div class="titlepage"><div><div><h2 class="title" style="clear: both">
27<a name="date_time.local_time"></a>Local Time</h2></div></div></div>
28<div class="toc"><dl>
29<dt><span class="section"><a href="local_time.html#date_time.local_time.time_zone_base">Time Zone (abstract)</a></span></dt>
30<dt><span class="section"><a href="local_time.html#date_time.local_time.posix_time_zone">Posix Time Zone</a></span></dt>
31<dt><span class="section"><a href="local_time.html#date_time.local_time.tz_database">Time Zone Database</a></span></dt>
32<dt><span class="section"><a href="local_time.html#date_time.local_time.custom_time_zone">Custom Time Zone</a></span></dt>
33<dt><span class="section"><a href="local_time.html#date_time.local_time.local_date_time">Local Date Time</a></span></dt>
34<dt><span class="section"><a href="local_time.html#date_time.local_time.local_time_period">Local Time Period</a></span></dt>
35</dl></div>
36<h2>
37<a name="id974837"></a>Local Time System</h2>
38<p>
39    <a href="local_time.html#local_intro">Introduction</a> --
40    <a href="local_time.html#local_ex">Usage Examples</a>
41  </p>
42<a name="local_intro"></a><h3>
43<a name="id974867"></a>Introduction</h3>
44<p>
45    The library supports 4 main extensions for the management of local times. This includes
46    </p>
47<table class="simplelist" border="0" summary="Simple list">
48<tr><td>local_date_time -- locally adjusted time point</td></tr>
49<tr><td>posix_time_zone -- time zone defined by posix string (eg: "EST10EDT,M10.5.0,M3.5.0/03")</td></tr>
50<tr><td>time_zone_database -- get time zones by region from .csv file (eg: America/New York)</td></tr>
51<tr><td>time_zone -- abstract time zone interface</td></tr>
52</table>
53<p>
54  </p>
55<p>
56    Together, these extensions define a time system adjusted for recording times related to a specific earth location. This time system utilizes all the features and benefits of the posix_time system (see <a href="posix_time.html" title="Posix Time">posix_time</a> for full details). It uses a time_zone object which contains all the necessary data/rules to enable adjustments to and from various time zones. The time_zone objects used in date_time are handled via a boost::shared_ptr&lt;boost::local_time::time_zone&gt;.
57  </p>
58<p>
59    The phrase "wall-clock" refers to the time that would be shown on a wall clock in a particular time zone at any point in time. Local_time uses a time zone object to account for differences in time zones and daylight savings adjustments. For example: While 5:00 pm, October 10, 2004 in Sydney Australia occurs at exactly the same instant as 3:00 am, October 10, 2004 in New York USA, it is a 14 hour difference in wall-clock times. However, a point in time just one day later will result in a 16 hour difference in wall-clock time due to daylight savings adjustments in both time zones. The local_time system tracks these by means of a time point, stored as UTC, and time_zone objects that contain all the necessary data to correctly calculate wall-clock times.
60  </p>
61<a name="local_ex"></a><h3>
62<a name="id974915"></a>Usage Examples</h3>
63<p>
64    </p>
65<div class="informaltable"><table class="table">
66<colgroup>
67<col>
68<col>
69</colgroup>
70<thead><tr>
71<th>Example</th>
72<th>Description</th>
73</tr></thead>
74<tbody>
75<tr>
76<td><a href="examples.html#date_time.examples.simple_time_zone" title="Simple Time Zones">Simple Time Zone</a></td>
77<td>Side by side examples of Time Zone usage. Both <span class="type">custom_time_zone</span> and <span class="type">posix_time_zone</span> are shown.</td>
78</tr>
79<tr>
80<td><a href="examples.html#date_time.examples.calc_rules" title="Daylight Savings Calc Rules">Daylight Savings Calc Rules</a></td>
81<td>Simple example showing the creation of all five <span class="type">dst_calc_rule</span> types.</td>
82</tr>
83<tr>
84<td><a href="examples.html#date_time.examples.seconds_since_epoch" title="Seconds Since Epoch">Seconds Since Epoch</a></td>
85<td>Example that calculates the total seconds elapsed since the epoch (1970-Jan-01) utilizing local_date_time.</td>
86</tr>
87</tbody>
88</table></div>
89<p>
90  </p>
91<div class="section" lang="en">
92<div class="titlepage"><div><div><h3 class="title">
93<a name="date_time.local_time.time_zone_base"></a>Time Zone (abstract)</h3></div></div></div>
94<a href="local_time.html#time_zone_base_intro">Introduction</a> --
95  <a href="local_time.html#time_zone_base_header">Header</a> --
96  <a href="local_time.html#time_zone_base_constr">Construction</a> --
97  <a href="local_time.html#time_zone_base_accessors">Accessors</a><a name="time_zone_base_intro"></a><h3>
98<a name="id975083"></a>Introduction</h3>
99<p>
100    The time_zone_base class is an abstract base class template for representing time zones. Time zones are a set of data and rules that provide information about a time zone. The date_time library handles time_zones by means of a boost::shared_ptr&lt;time_zone_base&gt;. A user's custom time zone class will work in the date_time library by means of this shared_ptr.
101  </p>
102<p>
103    For convienience, the time_zone_base class is typedef'd as time_zone. All references in the documentation to time_zone, are referring to this typedef.
104  </p>
105<a name="time_zone_base_header"></a><h3>
106<a name="id975104"></a>Header</h3>
107<p>
108    The time_zone_base class is defined in the header:
109    </p>
110<pre class="programlisting">#include "boost/date_time/time_zone_base.hpp"
111    </pre>
112<p>
113  </p>
114<a name="time_zone_base_constr"></a><h3>
115<a name="id975126"></a>Construction</h3>
116<p>
117    A default constructor is provided in the time_zone_base class. There are no private data members in this base class to initialize.
118  </p>
119<p>
120    Template parameters are time_type (typically posix_time::ptime) and CharT (defaults to char).
121  </p>
122<a name="time_zone_base_accessors"></a><h3>
123<a name="id975149"></a>Accessors</h3>
124<p>
125    All of the accessors listed here are pure virtual functions.
126  </p>
127<p>
128    </p>
129<div class="informaltable"><table class="table">
130<colgroup>
131<col>
132<col>
133</colgroup>
134<thead><tr>
135<th>Syntax</th>
136<th>Description</th>
137</tr></thead>
138<tbody>
139<tr>
140<td valign="top"><pre class="screen">
141string_type dst_zone_abbrev();</pre></td>
142<td>Returns the daylight savings abbreviation for the represented time zone.</td>
143</tr>
144<tr>
145<td valign="top"><pre class="screen">
146string_type std_zone_abbrev();</pre></td>
147<td>Returns the standard abbreviation for the represented time zone.</td>
148</tr>
149<tr>
150<td valign="top"><pre class="screen">
151string_type dst_zone_name();</pre></td>
152<td>Returns the daylight savings name for the represented time zone.</td>
153</tr>
154<tr>
155<td valign="top"><pre class="screen">
156string_type std_zone_name();</pre></td>
157<td>Returns the standard name for the represented time zone.</td>
158</tr>
159<tr>
160<td valign="top"><pre class="screen">bool has_dst();</pre></td>
161<td>Returns true if this time zone does not make a daylight savings shift.</td>
162</tr>
163<tr>
164<td valign="top"><pre class="screen">
165time_type dst_local_start_time(year_type);</pre></td>
166<td>The date and time daylight savings time begins in given year.</td>
167</tr>
168<tr>
169<td valign="top"><pre class="screen">
170time_type dst_local_end_time(year_type);</pre></td>
171<td valign="top">The date and time daylight savings time ends in given year.</td>
172</tr>
173<tr>
174<td valign="top"><pre class="screen">
175time_duration_type base_utc_offset();</pre></td>
176<td>The amount of time offset from UTC (typically in hours).</td>
177</tr>
178<tr>
179<td valign="top"><pre class="screen">
180time_duration_type dst_offset();</pre></td>
181<td>The amount of time shifted during daylight savings.</td>
182</tr>
183<tr>
184<td valign="top"><pre class="screen">
185std::string to_posix_string();</pre></td>
186<td>Returns a posix time zone string representation of this time_zone_base object. For a detailed description of a posix time zone string see <a href="local_time.html#date_time.local_time.posix_time_zone" title="Posix Time Zone">posix_time_zone</a>.</td>
187</tr>
188</tbody>
189</table></div>
190<p>
191  </p>
192</div>
193<div class="section" lang="en">
194<div class="titlepage"><div><div><h3 class="title">
195<a name="date_time.local_time.posix_time_zone"></a>Posix Time Zone</h3></div></div></div>
196<a href="local_time.html#posix_time_zone_intro">Introduction</a> --
197  <a href="local_time.html#posix_time_zone_notes">Important Notes</a> --
198  <a href="local_time.html#posix_time_zone_header">Header</a> --
199  <a href="local_time.html#posix_time_zone_constr">Construction</a> --
200  <a href="local_time.html#posix_time_zone_accessors">Accessors</a><a name="posix_time_zone_intro"></a><h3>
201<a name="id975424"></a>Introduction</h3>
202<p>
203    A posix_time_zone object is a set of data and rules that provide information about a time zone. Information such as the offset from UTC, it's name and abbreviation, as well as daylight savings rules, called <a href="local_time.html#date_time.local_time.dst_calc_rules">dst_calc_rules</a>. These rules are stored as a boost::shared_ptr&lt;dst_calc_rules&gt;.
204  </p>
205<p>
206    As a convenience, a typedef for shared_ptr&lt;dst_calc_rules&gt; is provided.
207    </p>
208<pre class="programlisting">typedef boost::shared_ptr&lt;dst_calc_rules&gt; local_time::dst_calc_rule_ptr;</pre>
209<p>
210  </p>
211<p>
212    A posix_time_zone is unique in that the object is created from a Posix time zone string (IEEE Std 1003.1). A POSIX time zone string takes the form of:
213    </p>
214<div class="literallayout"><p><br>
215      "std offset dst [offset],start[/time],end[/time]" (w/no spaces).</p></div>
216<p>'std' specifies the abbrev of the time zone. 'offset' is the offset from UTC. 'dst' specifies the abbrev of the time zone during daylight savings time. The second offset is how many hours changed during DST. 'start' and 'end' are the dates when DST goes into (and out of) effect. 'offset' takes the form of:
217    </p>
218<div class="literallayout"><p><br>
219      [+|-]hh[:mm[:ss]] {h=0-23, m/s=0-59}</p></div>
220<p>'time' and 'offset' take the same form. 'start' and 'end' can be one of three forms:
221    </p>
222<div class="literallayout"><p><br>
223      Mm.w.d {month=1-12, week=1-5 (5 is always last), day=0-6} <br>
224      Jn {n=1-365 Feb29 is never counted} <br>
225      n {n=0-365 Feb29 is counted in leap years}</p></div>
226<p>
227  </p>
228<p>
229    Exceptions will be thrown under the following conditions:
230    </p>
231<div class="itemizedlist"><ul type="disc">
232<li>An exception will be thrown for an invalid date spec (see <a href="gregorian.html#date_time.gregorian.date_class" title="Date">date class</a>).</li>
233<li>A boost::local_time::bad_offset exception will be thrown for:</li>
234<li>A DST start or end offset that is negative or more than 24 hours.</li>
235<li>A UTC zone that is greater than +12 or less than -12 hours.</li>
236<li>A boost::local_time::bad_adjustment exception will be thrown for a DST adjustment that is 24 hours or more (positive or negative)</li>
237</ul></div>
238<p>
239  </p>
240<p>As stated above, the 'offset' and '/time' portions of the string are not required. If they are not given they default to 01:00 for 'offset', and 02:00 for both occurrences of '/time'.
241  </p>
242<p>
243    Some examples are:
244    </p>
245<div class="literallayout"><p><br>
246      "PST-8PDT01:00:00,M4.1.0/02:00:00,M10.1.0/02:00:00"<br>
247      "PST-8PDT,M4.1.0,M10.1.0"</p></div>
248<p>These two are actually the same specification (defaults were used in the second string). This zone lies eight hours west of GMT and makes a one hour shift forward during daylight savings time. Daylight savings for this zone starts on the first Sunday of April at 2am, and ends on the first Sunday of October at 2am.
249    </p>
250<div class="literallayout"><p><br>
251      "MST-7"</p></div>
252<p>This zone is as simple as it gets. This zone lies seven hours west of GMT and has no daylight savings.
253    </p>
254<div class="literallayout"><p><br>
255      "EST10EDT,M10.5.0,M3.5.0/03"</p></div>
256<p>This string describes the time zone for Sydney Australia. It lies ten hours east of GMT and makes a one hour shift forward during daylight savings. Being located in the southern hemisphere, daylight savings begins on the last Sunday in October at 2am and ends on the last Sunday in March at 3am.
257    </p>
258<div class="literallayout"><p><br>
259      "FST+3FDT02:00,J60/00,J304/02"</p></div>
260<p>This specification describes a fictitious zone that lies three hours east of GMT. It makes a two hour shift forward for daylight savings which begins on March 1st at midnight, and ends on October 31st at 2am. The 'J' designation in the start/end specs signifies that counting starts at one and February 29th is never counted.
261    </p>
262<div class="literallayout"><p><br>
263      "FST+3FDT,59,304"</p></div>
264<p>This specification is significant because of the '59'. The lack of 'J' for the start and end dates, indicates that the Julian day-count begins at zero and ends at 365. If you do the math, you'll see that allows for a total of 366 days. This is fine in leap years, but in non-leap years '59' (Feb-29) does not exist. This will construct a valid posix_time_zone object but an exception will be thrown if the date of '59' is accessed in a non-leap year. Ex:
265    </p>
266<pre class="programlisting">posix_time_zone leap_day(std::string("FST+3FDT,59,304"));
267leap_day.dst_local_start_time(2004); // ok
268leap_day.dst_local_start_time(2003); // Exception thrown</pre>
269<p>
270  </p>
271<p>
272    The posix_time_zone objects are used via a boost::shared_ptr&lt;local_time::time_zone_base&gt;. As a convenience, a typedef for boost::shared_ptr&lt;local_time::time_zone_base&gt; is provided:
273    </p>
274<pre class="programlisting">typedef boost::shared_ptr&lt;time_zone_base&gt; local_time::time_zone_ptr;</pre>
275<p>
276  </p>
277<p>
278    See <a href="examples.html#date_time.examples.simple_time_zone" title="Simple Time Zones">Simple time zone</a> for a side by side example of time_zone and posix_time_zone usage.
279  </p>
280<a name="posix_time_zone_notes"></a><h3>
281<a name="id975661"></a>Important Notes</h3>
282<div class="itemizedlist"><ul type="disc">
283<li>posix_time_zone objects use the standard and daylight savings abbreviations in place of the full names (see <a href="local_time.html#posix_time_zone_accessors">Accessors</a> below).</li>
284<li>'Jn' and 'n' date specifications can not be mixed in a specification string. Ex: "FST+3FDT,59,J304" </li>
285<li>'n' date specification of 59 represents Feb-29. Do not attempt to access in a non-leap year or an exception will be thrown.</li>
286</ul></div>
287<a name="posix_time_zone_header"></a><h3>
288<a name="id975698"></a>Header</h3>
289<p>
290    The inclusion of a single header will bring in all boost::local_time types, functions, and IO operators.
291    </p>
292<pre class="programlisting">#include "boost/date_time/local_time/local_time.hpp"</pre>
293<p>
294  </p>
295<a name="posix_time_zone_constr"></a><h3>
296<a name="id975721"></a>Construction</h3>
297<p>
298    </p>
299<div class="informaltable"><table class="table">
300<colgroup>
301<col>
302<col>
303</colgroup>
304<thead><tr>
305<th>Syntax</th>
306<th>Example</th>
307</tr></thead>
308<tbody><tr>
309<td valign="top"><pre class="screen">posix_time_zone(std::string)</pre></td>
310<td>
311<pre class="screen">std::string nyc("EST-5EDT,M4.1.0,M10.5.0");
312time_zone_ptr zone(new posix_time_zone(nyc));</pre>
313            </td>
314</tr></tbody>
315</table></div>
316<p>
317  </p>
318<a name="posix_time_zone_accessors"></a><h3>
319<a name="id975784"></a>Accessors</h3>
320<p>
321    </p>
322<div class="informaltable"><table class="table">
323<colgroup>
324<col>
325<col>
326</colgroup>
327<thead>
328<tr>
329<th rowspan="2" valign="top">Syntax</th>
330<th>Description</th>
331</tr>
332<tr><th>Example</th></tr>
333</thead>
334<tbody>
335<tr>
336<td rowspan="2" valign="top"><pre class="screen">std::string dst_zone_abbrev()</pre></td>
337<td>Returns the daylight savings abbreviation for the represented time zone.</td>
338</tr>
339<tr><td><pre class="screen">nyc_zone_sh_ptr-&gt;dst_zone_abbrev(); // "EDT"</pre></td></tr>
340<tr>
341<td rowspan="2" valign="top"><pre class="screen">std::string std_zone_abbrev()</pre></td>
342<td>Returns the standard abbreviation for the represented time zone.</td>
343</tr>
344<tr><td><pre class="screen">nyc_zone_sh_ptr-&gt;std_zone_abbrev(); // "EST"</pre></td></tr>
345<tr>
346<td rowspan="2" valign="top"><pre class="screen">std::string dst_zone_name()</pre></td>
347<td>Returns the daylight savings ABBREVIATION for the represented time zone.</td>
348</tr>
349<tr><td><pre class="screen">nyc_zone_sh_ptr-&gt;dst_zone_name(); // "EDT"</pre></td></tr>
350<tr>
351<td rowspan="2" valign="top"><pre class="screen">std::string std_zone_name()</pre></td>
352<td>Returns the standard ABBREVIATION for the represented time zone.</td>
353</tr>
354<tr><td><pre class="screen">nyc_zone_sh_ptr-&gt;std_zone_name(); // "EST"</pre></td></tr>
355<tr>
356<td rowspan="2" valign="top"><pre class="screen">bool has_dst()</pre></td>
357<td>Returns true when time_zone's shared_ptr to dst_calc_rules is not NULL.</td>
358</tr>
359<tr><td>
360<pre class="screen">nyc_zone_sh_ptr-&gt;has_dst(); // true
361phx_zone_sh_ptr-&gt;has_dst(); // false</pre>
362            </td></tr>
363<tr>
364<td rowspan="2" valign="top"><pre class="screen">
365ptime dst_local_start_time(greg_year)</pre></td>
366<td>The date and time daylight savings time begins in given year. Returns not_a_date_time if this zone has no daylight savings.</td>
367</tr>
368<tr><td><pre class="screen">nyc_zone_sh_ptr-&gt;dst_local_start_time(2004);
369// 2004-Apr-04 02:00</pre></td></tr>
370<tr>
371<td rowspan="2" valign="top"><pre class="screen">
372ptime dst_local_end_time(greg_year)</pre></td>
373<td>The date and time daylight savings time ends in given year. Returns not_a_date_time if this zone has no daylight savings.</td>
374</tr>
375<tr><td><pre class="screen">nyc_zone_sh_ptr-&gt;dst_local_end_time(2004);
376// 2004-Oct-31 02:00</pre></td></tr>
377<tr>
378<td rowspan="2" valign="top"><pre class="screen">
379time_duration base_utc_offset()</pre></td>
380<td>The amount of time offset from UTC (typically in hours).</td>
381</tr>
382<tr><td><pre class="screen">nyc_zone_sh_ptr-&gt;base_utc_offset(); // -05:00</pre></td></tr>
383<tr>
384<td rowspan="2" valign="top"><pre class="screen">posix_time::time_duration dst_offset()</pre></td>
385<td>The amount of time shifted during daylight savings.</td>
386</tr>
387<tr><td><pre class="screen">nyc_zone_sh_ptr-&gt;dst_offset(); // 01:00</pre></td></tr>
388<tr>
389<td rowspan="2" valign="top"><pre class="screen">std::string to_posix_string()</pre></td>
390<td>Returns a posix time zone string representation of this time_zone_base object. Depending on how the time_zone object was created, the date-spec format of the string will be in either 'M' notation or 'n' notation. Every possible date-spec that can be represented in 'J' notation can also be represented in 'n' notation. The reverse is not true so only 'n' notation is used for these types of date-specs. For a detailed description of a posix time zone string see <a href="local_time.html#date_time.local_time.posix_time_zone" title="Posix Time Zone">posix_time_zone</a>.</td>
391</tr>
392<tr><td><pre class="screen">nyc_zone_sh_ptr-&gt;to_posix_string();
393// "EST-05EDT+01,M4.1.0/02:00,M10.5.0/02:00"
394phx_zone_sh_ptr-&gt;to_posix_string();
395// "MST-07"
396            </pre></td></tr>
397</tbody>
398</table></div>
399<p>
400  </p>
401</div>
402<div class="section" lang="en">
403<div class="titlepage"><div><div><h3 class="title">
404<a name="date_time.local_time.tz_database"></a>Time Zone Database</h3></div></div></div>
405<a href="local_time.html#tz_database_intro">Introduction</a> --
406  <a href="local_time.html#tz_database_header">Header</a> --
407  <a href="local_time.html#tz_database_constr">Construction</a> --
408  <a href="local_time.html#tz_database_accessors">Accessors</a> --
409  <a href="local_time.html#tz_database_datafile">Data File Details</a><a name="tz_database_intro"></a><h3>
410<a name="id976209"></a>Introduction</h3>
411<p>
412    The local_time system depends on the ability to store time zone information. Our Time Zone Database (tz_database) is a means of permanently storing that data. The specifications for many time zones (377 at this time) are provided. These specifications are based on data found in the <a href="http://www.twinsun.com/tz/tz-link.htm" target="_top">zoneinfo datebase</a>. The specifications are stored in the file:</p>
413<pre class="screen">libs/date_time/data/date_time_zonespec.csv</pre>
414<p>. While this file already contains specifications for many time zones, it's real intent is for the user to modify it by adding (or removing) time zones to fit their application. See <a href="local_time.html#tz_database_datafile">Data File Details</a> to learn how this is accomplished.
415  </p>
416<a name="tz_database_header"></a><h3>
417<a name="id976254"></a>Header</h3>
418<p>
419    The inclusion of a single header will bring in all boost::local_time types, functions, and IO operators.
420    </p>
421<pre class="programlisting">#include "boost/date_time/local_time/local_time.hpp"
422    </pre>
423<p>
424  </p>
425<a name="tz_database_constr"></a><h3>
426<a name="id976277"></a>Construction</h3>
427<p>
428    The only constructor takes no arguments and creates an empty database. It is up to the user to populate the database. This is typically achieved by loading the desired datafile, but can also be accomplished by means of the <code class="computeroutput">add_record(...)</code> function (see the <a href="local_time.html#tz_database_accessors">Accessors table</a>). A <code class="computeroutput">local_time::data_not_accessible</code> exception will be thrown if given zonespec file cannot be found. <code class="computeroutput">local_time::bad_field_count</code> exception will be thrown if the number of fields in given zonespec file is incorrect.
429  </p>
430<p>
431    </p>
432<div class="informaltable"><table class="table">
433<colgroup>
434<col>
435<col>
436</colgroup>
437<thead><tr>
438<th rowspan="2" valign="top">Syntax</th>
439<th>Description</th>
440</tr></thead>
441<tbody>
442<tr>
443<td rowspan="2" valign="top"><pre class="screen">tz_database()</pre></td>
444<td>Constructor creates an empty database.</td>
445</tr>
446<tr><td><pre class="screen">tz_database tz_db;</pre></td></tr>
447<tr>
448<td rowspan="2" valign="top"><pre class="screen">bool load_from_file(std::string)</pre></td>
449<td>Parameter is path to a time zone spec csv file (see <a href="local_time.html#tz_database_datafile">Data File Details</a> for details on the contents of this file). This function populates the database with time zone records found in the zone spec file. A <code class="computeroutput">local_time::data_not_accessible</code> exception will be thrown if given zonespec file cannot be found. <code class="computeroutput">local_time::bad_field_count</code> exception will be thrown if the number of fields in given zonespec file is incorrect.</td>
450</tr>
451<tr><td>
452<pre class="screen">tz_database tz_db;
453tz_db.load_from_file("./date_time_zonespec.csv");</pre>
454            </td></tr>
455</tbody>
456</table></div>
457<p>
458  </p>
459<a name="tz_database_accessors"></a><h3>
460<a name="id976440"></a>Accessors</h3>
461<p>
462    </p>
463<div class="informaltable"><table class="table">
464<colgroup>
465<col>
466<col>
467</colgroup>
468<thead>
469<tr>
470<th rowspan="2" valign="top">Syntax</th>
471<th>Description</th>
472</tr>
473<tr><th>Example</th></tr>
474</thead>
475<tbody>
476<tr>
477<td rowspan="2" valign="top"><pre class="screen">bool tz_db.add_record(std::string id,
478                      <a href="local_time.html#date_time.local_time.custom_time_zone_ptr">time_zone_ptr</a> tz);</pre></td>
479<td>Adds a time_zone, or a posix_time_zone, to the database. ID is the region name for this zone (Ex: "America/Phoenix").</td>
480</tr>
481<tr><td>
482<pre class="screen">time_zone_ptr zone(
483  new posix_time_zone("PST-8PDT,M4.1.0,M10.1.0")
484);
485std::string id("America/West_Coast");
486tz_db.add_record(id, zone);</pre>
487            </td></tr>
488<tr>
489<td rowspan="2" valign="top"><pre class="screen">time_zone_ptr
490  tz_db.time_zone_from_region(string id);</pre></td>
491<td>Returns a time_zone, via a time_zone_ptr, that matches the region listed in the data file. A null pointer is returned if no match is found.
492            </td>
493</tr>
494<tr><td>
495<pre class="screen">time_zone_ptr nyc =
496  tz_db.time_zone_from_region("America/New_York");</pre>
497            </td></tr>
498<tr>
499<td rowspan="2" valign="top"><pre class="screen">vector&lt;string&gt; tz_db.region_list();</pre></td>
500<td>Returns a vector of strings that holds all the region ID strings from the database.</td>
501</tr>
502<tr><td>
503<pre class="screen">std::vector&lt;std::string&gt; regions;
504regions = tz_db.region_list();</pre>
505            </td></tr>
506</tbody>
507</table></div>
508<p>
509  </p>
510<a name="tz_database_datafile"></a><h3>
511<a name="id976598"></a>Data File Details</h3>
512<a href="local_time.html#tz_database_fields">Field Description/Details</a><p>
513    The csv file containing the zone_specs used by the boost::local_time::tz_database is intended to be customized by the library user. When customizing this file (or creating your own) the file must follow a specific format.
514  </p>
515<p>
516    This first line is expected to contain column headings and is therefore
517not processed by the tz_database.
518  </p>
519<p>
520    Each record (line) must have eleven fields. Some of those fields can be empty. Every field (even empty ones) must be enclosed in double-quotes.
521    </p>
522<div class="literallayout"><p><br>
523      Ex:<br>
524      "America/Phoenix" &lt;- string enclosed in quotes<br>
525      ""                &lt;- empty field<br>
526    </p></div>
527<p>
528  </p>
529<p>
530    Some fields represent a length of time. The format of these fields must be:
531    </p>
532<div class="literallayout"><p><br>
533      "{+|-}hh:mm[:ss]" &lt;- length-of-time format<br>
534    </p></div>
535<p>
536    Where the plus or minus is mandatory and the seconds are optional.
537  </p>
538<p>
539    Since some time zones do not use daylight savings it is not always necessary for every field in a zone_spec to contain a value. All zone_specs must have at least ID and GMT offset. Zones that use daylight savings must have all fields filled except: STD ABBR, STD NAME, DST NAME. You should take note that DST ABBR is mandatory for zones that use daylight savings (see field descriptions for further details).
540  </p>
541<a name="tz_database_fields"></a><h3>
542<a name="id976674"></a>Field Description/Details</h3>
543<p>
544    </p>
545<div class="itemizedlist"><ul type="disc">
546<li>
547        ID
548        <p>
549          Contains the identifying string for the zone_spec. Any string will do as long as it's unique. No two ID's can be the same.
550        </p>
551</li>
552<li>
553        STD ABBR
554      </li>
555<li>
556        STD NAME
557      </li>
558<li>
559        DST ABBR
560      </li>
561<li>
562        DST NAME
563        <p>
564          These four are all the names and abbreviations used by the time zone being described. While any string will do in these fields, care should be taken. These fields hold the strings that will be used in the output of many of the local_time classes.
565        </p>
566</li>
567<li>
568        GMT offset
569        <p>
570          This is the number of hours added to utc to get the local time before any daylight savings adjustments are made. Some examples are: America/New_York offset -5 hours, and Africa/Cairo offset +2 hours. The format must follow the length-of-time format described above.
571        </p>
572</li>
573<li>
574        DST adjustment
575        <p>
576          The amount of time added to gmt_offset when daylight savings is in effect. The format must follow the length-of-time format described above.
577        </p>
578<p>
579          NOTE: more rule capabilities are needed - this portion of the tz_database is incomplete
580        </p>
581</li>
582<li>
583        DST Start Date rule
584        <p>
585          This is a specially formatted string that describes the day of year in which the transition take place. It holds three fields of it's own, separated by semicolons.
586          </p>
587<div class="orderedlist"><ol type="1">
588<li>
589              The first field indicates the "nth" weekday of the month. The possible values are: 1 (first), 2 (second), 3 (third), 4 (fourth), 5 (fifth), and -1 (last).
590            </li>
591<li>
592              The second field indicates the day-of-week from 0-6 (Sun=0).
593            </li>
594<li>
595              The third field indicates the month from 1-12 (Jan=1).
596            </li>
597</ol></div>
598<p>
599          Examples are: "-1;5;9"="Last Friday of September", "2;1;3"="Second Monday of March"
600        </p>
601</li>
602<li>
603        Start time
604        <p>
605          Start time is the number of hours past midnight, on the day of the start transition, the transition takes place. More simply put, the time of day the transition is made (in 24 hours format). The format must follow the length-of-time format described above with the exception that it must always be positive.
606        </p>
607</li>
608<li>
609        DST End date rule
610        <p>
611          See DST Start date rule. The difference here is this is the day daylight savings ends (transition to STD).
612        </p>
613</li>
614<li>
615        End time
616        <p>
617          Same as Start time.
618        </p>
619</li>
620</ul></div>
621<p>
622  </p>
623</div>
624<div class="section" lang="en">
625<div class="titlepage"><div><div><h3 class="title">
626<a name="date_time.local_time.custom_time_zone"></a>Custom Time Zone</h3></div></div></div>
627<a href="local_time.html#custom_time_zone_intro">Introduction</a> --
628  <a href="local_time.html#custom_time_zone_header">Header</a> --
629  <a href="local_time.html#custom_time_zone_constr">Construction</a> --
630  <a href="local_time.html#custom_time_zone_accessors">Accessors</a> --
631  <a href="local_time.html#custom_time_zone_dependents">Dependent Types</a><a name="custom_time_zone_intro"></a><h3>
632<a name="id976870"></a>Introduction</h3>
633<p>
634    A custom_time_zone object is a set of data and rules that provide information about a time zone. Information such as the offset from UTC, it's name and abbreviation, as well as daylight savings rules, called <a href="local_time.html#date_time.local_time.dst_calc_rules">dst_calc_rules</a>. These rules are handled via a boost::shared_ptr&lt;dst_calc_rules&gt;. Not all time zones utilize daylight savings, therefore, time_zone objects can be used with a NULL-assigned shared_ptr.
635  </p>
636<p>
637    As a convenience, a typedef for shared_ptr&lt;dst_calc_rules&gt; is provided.
638    </p>
639<pre class="programlisting">typedef boost::shared_ptr&lt;dst_calc_rules&gt; local_time::dst_calc_rule_ptr;</pre>
640<p>
641  </p>
642<a name="date_time.local_time.custom_time_zone_ptr"></a><p>
643    The time_zone objects are used via a boost::shared_ptr&lt;local_time::time_zone&gt;. As a convenience, a typedef for boost::shared_ptr&lt;local_time::time_zone&gt; is provided:
644    </p>
645<pre class="programlisting">typedef boost::shared_ptr&lt;time_zone&gt; local_time::time_zone_ptr;</pre>
646<p>
647  </p>
648<a name="custom_time_zone_header"></a><h3>
649<a name="id976941"></a>Header</h3>
650<p>
651    The inclusion of a single header will bring in all boost::local_time types, functions, and IO operators.
652    </p>
653<pre class="programlisting">#include "boost/date_time/local_time/local_time.hpp"</pre>
654<p>
655  </p>
656<a name="custom_time_zone_constr"></a><h3>
657<a name="id976964"></a>Construction</h3>
658<p>
659    Construction of a custom_time_zone is dependent on four objects: a
660    <a href="posix_time.html#date_time.posix_time.time_duration" title="Time Duration">time_duration</a>, a <a href="local_time.html#time_zone_names">time_zone_names</a>, a <a href="local_time.html#dst_adjustment_offsets">dst_adjustment_offsets</a>, and a shared_ptr to a <a href="local_time.html#date_time.local_time.dst_calc_rules">dst_calc_rule</a>.
661  </p>
662<p>
663    </p>
664<div class="informaltable"><table class="table">
665<colgroup>
666<col>
667<col>
668</colgroup>
669<thead><tr>
670<th>Syntax</th>
671<th>Example</th>
672</tr></thead>
673<tbody><tr>
674<td valign="top"><pre class="screen">custom_time_zone(...)
675  Parameters:
676    <a href="local_time.html#time_zone_names">names</a>,
677    <a href="posix_time.html#date_time.posix_time.time_duration" title="Time Duration">gmt_offset</a>,
678    <a href="local_time.html#dst_adjustment_offsets">dst_offsets</a>,
679    <a href="local_time.html#date_time.local_time.dst_calc_rules">dst_rules</a> </pre></td>
680<td>See <a href="examples.html#date_time.examples.simple_time_zone" title="Simple Time Zones">simple_time_zone</a> example for time_zone usage</td>
681</tr></tbody>
682</table></div>
683<p>
684  </p>
685<a name="custom_time_zone_accessors"></a><h3>
686<a name="id977098"></a>Accessors</h3>
687<p>
688    </p>
689<div class="informaltable"><table class="table">
690<colgroup>
691<col>
692<col>
693</colgroup>
694<thead>
695<tr>
696<th rowspan="2" valign="top">Syntax</th>
697<th>Description</th>
698</tr>
699<tr><th>Example</th></tr>
700</thead>
701<tbody>
702<tr>
703<td rowspan="2" valign="top"><pre class="screen">std::string dst_zone_abbrev()</pre></td>
704<td>Returns the daylight savings abbreviation for the represented time zone.</td>
705</tr>
706<tr><td><pre class="screen">nyc_zone_sh_ptr-&gt;dst_zone_abbrev();
707// "EDT"</pre></td></tr>
708<tr>
709<td rowspan="2" valign="top"><pre class="screen">std::string std_zone_abbrev()</pre></td>
710<td>Returns the standard abbreviation for the represented time zone.</td>
711</tr>
712<tr><td><pre class="screen">nyc_zone_sh_ptr-&gt;std_zone_abbrev();
713// "EST"</pre></td></tr>
714<tr>
715<td rowspan="2" valign="top"><pre class="screen">std::string dst_zone_name()</pre></td>
716<td>Returns the daylight savings name for the represented time zone.</td>
717</tr>
718<tr><td><pre class="screen">nyc_zone_sh_ptr-&gt;dst_zone_name();
719// "Eastern Daylight Time"</pre></td></tr>
720<tr>
721<td rowspan="2" valign="top"><pre class="screen">std::string std_zone_name()</pre></td>
722<td>Returns the standard name for the represented time zone.</td>
723</tr>
724<tr><td><pre class="screen">nyc_zone_sh_ptr-&gt;std_zone_name();
725// "Eastern Standard Time"</pre></td></tr>
726<tr>
727<td rowspan="2" valign="top"><pre class="screen">bool has_dst()</pre></td>
728<td>Returns true when custom_time_zone's shared_ptr to dst_calc_rules is not NULL.</td>
729</tr>
730<tr><td>
731<pre class="screen">nyc_zone_sh_ptr-&gt;has_dst();
732// true
733phx_zone_sh_ptr-&gt;has_dst();
734// false</pre>
735            </td></tr>
736<tr>
737<td rowspan="2" valign="top"><pre class="screen">dst_local_start_time(...)
738  Return Type:
739    ptime
740  Parameter:
741    greg_year</pre></td>
742<td>The date and time daylight savings time begins in given year. Returns not_a_date_time if this zone has no daylight savings.</td>
743</tr>
744<tr><td><pre class="screen">nyc_ptr-&gt;dst_local_start_time(2004);
745// 2004-Apr-04 02:00</pre></td></tr>
746<tr>
747<td rowspan="2" valign="top"><pre class="screen">dst_local_end_time(...)
748  Return Type:
749    ptime
750  Parameter:
751    greg_year</pre></td>
752<td>The date and time daylight savings time ends in given year. Returns not_a_date_time if this zone has no daylight savings.</td>
753</tr>
754<tr><td><pre class="screen">nyc_ptr-&gt;dst_local_end_time(2004);
755// 2004-Oct-31 02:00</pre></td></tr>
756<tr>
757<td rowspan="2" valign="top"><pre class="screen">time_duration base_utc_offset()</pre></td>
758<td>The amount of time offset from UTC (typically in hours).</td>
759</tr>
760<tr><td><pre class="screen">nyc_ptr-&gt;base_utc_offset();
761// -05:00</pre></td></tr>
762<tr>
763<td rowspan="2" valign="top"><pre class="screen">time_duration dst_offset()</pre></td>
764<td>The amount of time shifted during daylight savings.</td>
765</tr>
766<tr><td><pre class="screen">nyc_zone_sh_ptr-&gt;dst_offset();
767// 01:00</pre></td></tr>
768<tr>
769<td rowspan="2" valign="top"><pre class="screen">std::string to_posix_string()</pre></td>
770<td>Returns a posix time zone string representation of this time_zone object. Depending on how the time_zone object was created, the date-spec format of the string will be in either 'M' notation or 'n' notation. Every possible date-spec that can be represented in 'J' notation can also be represented in 'n' notation. The reverse is not true so only 'n' notation is used for these types of date-specs. For a detailed description of a posix time zone string see <a href="local_time.html#date_time.local_time.posix_time_zone" title="Posix Time Zone">posix_time_zone</a>.</td>
771</tr>
772<tr><td><pre class="screen">nyc_ptr-&gt;to_posix_string();
773// "EST-05EDT+01,M4.1.0/02:00,M10.5.0/02:00"
774phx_ptr-&gt;to_posix_string();
775// "MST-07"
776            </pre></td></tr>
777</tbody>
778</table></div>
779<p>
780  </p>
781<a name="custom_time_zone_dependents"></a><h3>
782<a name="id977471"></a>Dependent Types</h3>
783<a href="local_time.html#time_zone_names">Time Zone Names</a> --
784  <a href="local_time.html#dst_adjustment_offsets">Dst Adjustment Offsets</a> --
785  <a href="local_time.html#date_time.local_time.dst_calc_rules">Daylight Savings Calc Rules</a><a name="time_zone_names"></a><h3>
786<a name="id977504"></a>Time Zone Names</h3>
787<p>
788    The time_zone_names_base type is an immutable template class of four strings. One each for the name and abbreviation in standard time and daylight savings time. The time_zone_names type is a typedef of time_zone_names_base&lt;char&gt;.
789  </p>
790<p>
791    </p>
792<div class="informaltable"><table class="table">
793<colgroup>
794<col>
795<col>
796</colgroup>
797<thead>
798<tr>
799<th rowspan="2" valign="top">Syntax</th>
800<th>Description</th>
801</tr>
802<tr><th>Example</th></tr>
803</thead>
804<tbody>
805<tr>
806<td rowspan="2" valign="top"><pre class="screen">time_zone_names(...)
807  Parameters:
808    string std_name
809    string std_abbrev
810    string dst_name
811    string dst_abbrev</pre></td>
812<td>The only constructor, all four strings must be provided.</td>
813</tr>
814<tr><td>
815<pre class="screen">string sn("Eastern Standard Time");
816string sa("EST");
817string dn("Eastern Daylight Time");
818string da("EDT");
819time_zone_names nyc_names(sn, sa,
820                          dn, da);</pre>
821            </td></tr>
822<tr>
823<td rowspan="2" valign="top"><pre class="screen">std::string std_zone_name()</pre></td>
824<td>Returns the standard zone name</td>
825</tr>
826<tr><td><pre class="screen">nyc_names.std_zone_name();
827// "Eastern Standard Time"</pre></td></tr>
828<tr>
829<td rowspan="2" valign="top"><pre class="screen">std::string std_zone_abbrev()</pre></td>
830<td>Returns the standard zone abbreviation</td>
831</tr>
832<tr><td><pre class="screen">nyc_names.std_zone_abbrev();
833// "EST"</pre></td></tr>
834<tr>
835<td rowspan="2" valign="top"><pre class="screen">std::string dst_zone_name()</pre></td>
836<td>Returns the daylight savings zone name</td>
837</tr>
838<tr><td><pre class="screen">nyc_names.std_zone_name();
839// "Eastern Daylight Time"</pre></td></tr>
840<tr>
841<td rowspan="2" valign="top"><pre class="screen">std::string dst_zone_abbrev()</pre></td>
842<td>Returns the daylight savings zone abbreviation</td>
843</tr>
844<tr><td><pre class="screen">nyc_names.std_zone_abbrev();
845// "EDT"</pre></td></tr>
846</tbody>
847</table></div>
848<p>
849  </p>
850<a name="dst_adjustment_offsets"></a><h3>
851<a name="id977513"></a>Dst Adjustment Offsets</h3>
852<p>
853    The dst_adjustment_offsets type is a collection of three <a href="posix_time.html#date_time.posix_time.time_duration" title="Time Duration">time_duration</a> objects.
854  </p>
855<p>
856    </p>
857<div class="informaltable"><table class="table">
858<colgroup>
859<col>
860<col>
861</colgroup>
862<thead>
863<tr>
864<th rowspan="2" valign="top">Syntax</th>
865<th>Description</th>
866</tr>
867<tr><th>Example</th></tr>
868</thead>
869<tbody>
870<tr>
871<td rowspan="2" valign="top"><pre class="screen">dst_adjustment_offsets(...)
872  Parameters:
873    time_duration dst_adjust
874    time_duration start_offset
875    time_duration end_offset</pre></td>
876<td>The first time_duration is the daylight savings adjustment. The second is the time which daylight savings starts on the start day. The third is the time daylight savings ends on the ending day.</td>
877</tr>
878<tr><td><pre class="screen">
879dst_adjustment_offsets(hours(1),
880                       hours(2),
881                       hours(2));</pre></td></tr>
882</tbody>
883</table></div>
884<p>
885  </p>
886<a name="date_time.local_time.dst_calc_rules"></a><h3>
887<a name="id977813"></a>Daylight Savings Calc Rules</h3>
888<p>
889    Daylight savings calc rules, named dst_calc_rules, are a series of objects that group appropriate <a href="gregorian.html#date_time.gregorian.date_algorithms" title="Date Generators/Algorithms">date_generators</a> together to form rule sets. The individual rules objects are used via dst_calc_rule_ptr.
890  </p>
891<p>
892    For a complete example of all five dst_calc_rule types, see: <a href="examples.html#date_time.examples.calc_rules" title="Daylight Savings Calc Rules">calc_rules example</a>.
893  </p>
894<p>
895    </p>
896<div class="informaltable"><table class="table">
897<colgroup>
898<col>
899<col>
900</colgroup>
901<thead><tr>
902<th>Syntax</th>
903<th>Description</th>
904</tr></thead>
905<tbody>
906<tr>
907<td valign="top"><pre class="screen">partial_date_dst_rule(...)
908  Parameters:
909    start_rule
910    end_rule</pre></td>
911<td>Both the start and end rules are of type gregorian::partial_date.</td>
912</tr>
913<tr>
914<td valign="top"><pre class="screen">first_last_dst_rule(...)
915  Parameters:
916    start_rule
917    end_rule</pre></td>
918<td>The DST start rule is of type gregorian::first_day_of_the_week_in_month and the end rule is of type gregorian::last_day_of_the_week_in_month.</td>
919</tr>
920<tr>
921<td valign="top"><pre class="screen">last_last_dst_rule(...)
922  Parameters:
923    start_rule
924    end_rule</pre></td>
925<td>Both the start and end rules are of type gregorian::last_day_of_the_week_in_month.</td>
926</tr>
927<tr>
928<td valign="top"><pre class="screen">nth_last_dst_rule(...)
929  Parameters:
930    start_rule
931    end_rule</pre></td>
932<td>The DST start rule is of type gregorian::nth_day_of_the_week_in_month and the end rule is of type gregorian::last_day_of_the_week_in_month.</td>
933</tr>
934<tr>
935<td valign="top">
936<pre class="screen">nth_kday_dst_rule(...)
937  Parameters:
938    start_rule
939    end_rule)
940(see note* below)</pre>
941            </td>
942<td>Both rules are of type gregorian::nth_day_of_the_week_in_month.</td>
943</tr>
944</tbody>
945</table></div>
946<p>
947    </p>
948<p>
949      * Note: The name "nth_kday_dst_rule" is a bit cryptic. Therefore, a more descriptive name, "nth_day_of_the_week_in_month_dst_rule", is also provided.
950    </p>
951<p>
952  </p>
953</div>
954<div class="section" lang="en">
955<div class="titlepage"><div><div><h3 class="title">
956<a name="date_time.local_time.local_date_time"></a>Local Date Time</h3></div></div></div>
957<a href="local_time.html#local_date_time_intro">Introduction</a> --
958  <a href="local_time.html#local_date_time_header">Header</a> --
959  <a href="local_time.html#local_date_time_clock_constr">Construct From Clock</a> --
960  <a href="local_time.html#local_date_time_constr">Construction</a> --
961  <a href="local_time.html#local_date_time_accessors">Accessors</a> --
962  <a href="local_time.html#local_date_time_operators">Operators</a> --
963  <a href="local_time.html#local_date_time_tm_func">Struct tm Functions</a><a name="local_date_time_intro"></a><h3>
964<a name="id978048"></a>Introduction</h3>
965<p>
966    A local_date_time object is a point in time and an associated time zone. The time is represented internally as UTC.
967  </p>
968<a name="local_date_time_header"></a><h3>
969<a name="id978065"></a>Header</h3>
970<p>
971    The inclusion of a single header will bring in all boost::local_time types,
972functions, and IO operators.
973    </p>
974<pre class="programlisting">
975      #include "boost/date_time/local_time/local_time.hpp"
976    </pre>
977<p>
978  </p>
979<a name="local_date_time_clock_constr"></a><h3>
980<a name="id978089"></a>Construct From Clock</h3>
981<p>
982    Creation of a local_date_time object from clock is possible with either second, or sub second resolution.
983  </p>
984<p>
985    </p>
986<div class="informaltable"><table class="table">
987<colgroup>
988<col>
989<col>
990</colgroup>
991<thead><tr>
992<th>Syntax</th>
993<th>Example</th>
994</tr></thead>
995<tbody>
996<tr>
997<td valign="top"><pre class="screen">local_microsec_clock(...)
998  Return Type:
999    local_date_time
1000  Parameter:
1001    time_zone_ptr</pre></td>
1002<td>
1003<pre class="screen">time_zone_ptr zone(
1004  new posix_time_zone("MST-07")
1005);
1006local_date_time ldt =
1007  local_microsec_clock::local_time(
1008    zone);</pre>
1009            </td>
1010</tr>
1011<tr>
1012<td valign="top"><pre class="screen">local_sec_clock(...)
1013  Return Type:
1014    local_date_time
1015  Parameter:
1016    time_zone_ptr</pre></td>
1017<td>
1018<pre class="screen">time_zone_ptr zone(
1019  new posix_time_zone("MST-07")
1020);
1021local_date_time ldt =
1022  local_sec_clock::local_time(zone);</pre>
1023            </td>
1024</tr>
1025</tbody>
1026</table></div>
1027<p>
1028  </p>
1029<a name="local_date_time_constr"></a><h3>
1030<a name="id978181"></a>Construction</h3>
1031<p>
1032    Construction of a local_date_time object can be done with a ptime and a time_zone_ptr where the ptime represents UTC time. Construction with a wall-clock representation takes the form of a date, a time_duration, a time_zone_ptr, and a fourth parameter that addresses the following complication.
1033  </p>
1034<p>
1035    Construction from a wall-clock rep may result in differing shifts for a particular time zone, depending on daylight savings rules for that zone. This means it is also possible to create a local_date_time with a non-existent, or duplicated, UTC representation. These cases occur during the forward shift in time that is the transition into daylight savings and during the backward shift that is the transition out of daylight savings. The user has two options for handling these cases: a bool flag that states if the time is daylight savings, or an enum that states what to do when either of these cases are encountered.
1036  </p>
1037<p>
1038    The bool flag is ignored when the given time_zone has no daylight savings specification. When the daylight savings status of a given time label is calculated and it does not match the flag, a <code class="computeroutput">local_time::dst_not_valid</code> exception is thrown. If a time label is invalid (does not exist), a <code class="computeroutput">local_time::time_label_invalid</code> exception is thrown.
1039  </p>
1040<p>
1041    There are two elements in the <code class="computeroutput">local_date_time::DST_CALC_OPTIONS</code> enum: <code class="computeroutput">EXCEPTION_ON_ERROR</code> and <code class="computeroutput">NOT_DATE_TIME_ON_ERROR</code>. The possible exceptions thrown are a <code class="computeroutput">local_time::ambiguous_result</code> or a <code class="computeroutput">local_time::time_label_invalid</code>. The <code class="computeroutput">NOT_DATE_TIME_ON_ERROR</code> sets the time value to the special value <code class="computeroutput">local_time::not_a_date_time</code> in the event of either a invalid or an ambiguous time label.
1042  </p>
1043<p>
1044    </p>
1045<div class="informaltable"><table class="table">
1046<colgroup>
1047<col>
1048<col>
1049</colgroup>
1050<thead>
1051<tr>
1052<th rowspan="2">Syntax</th>
1053<th>Description</th>
1054</tr>
1055<tr><th>Example</th></tr>
1056</thead>
1057<tbody>
1058<tr>
1059<td rowspan="2" valign="top"><pre class="screen">local_date_time(...)
1060  Parameters:
1061    posix_time::ptime
1062    time_zone_ptr</pre></td>
1063<td>The given time is expected to be UTC. Therefore, the given time will be adjusted according to the offset described in the time zone.</td>
1064</tr>
1065<tr><td>
1066<pre class="screen">
1067// 3am, 2004-Nov-05 local time
1068ptime pt(date(2004,Nov,5),
1069         hours(10));
1070time_zone_ptr zone(
1071  new posix_time_zone("MST-07"));
1072local_date_time az(pt, zone);</pre>
1073            </td></tr>
1074<tr>
1075<td rowspan="2" valign="top"><pre class="screen">local_date_time(...)
1076  Parameters:
1077    date
1078    time_duration
1079    time_zone_ptr
1080    bool</pre></td>
1081<td>The passed time information understood to be in the passed tz. The DST flag must be passed to indicate whether the time is in daylight savings or not. May throw a <code class="computeroutput">dst_not_valid</code> or <code class="computeroutput">time_label_invalid</code> exception.</td>
1082</tr>
1083<tr><td>
1084<pre class="screen">date d(2004,Nov,5);
1085time_duration td(5,0,0,0);
1086string z("PST-8PDT,M4.1.0,M10.1.0")
1087time_zone_ptr zone(
1088  new posix_time_zone(z));
1089local_date_time nyc(d, td,
1090                    zone, false);</pre>
1091            </td></tr>
1092<tr>
1093<td rowspan="2" valign="top"><pre class="screen">local_date_time(...)
1094  Parameters:
1095    date
1096    time_duration
1097    time_zone_ptr
1098    DST_CALC_OPTIONS</pre></td>
1099<td>The passed time information understood to be in the passed tz. The DST flag is calculated according to the specified rule. May throw a <code class="computeroutput">ambiguous_result</code> or <code class="computeroutput">time_label_invalid</code> exception.</td>
1100</tr>
1101<tr><td>
1102<pre class="screen">date d(2004,Nov,5);
1103time_duration td(5,0,0,0);
1104string z("PST-8PDT,M4.1.0,M10.1.0")
1105time_zone_ptr zone(
1106  new posix_time_zone(z));
1107local_date_time nyc(d, td, zone,
1108  NOT_DATE_TIME_ON_ERROR);</pre>
1109            </td></tr>
1110<tr>
1111<td rowspan="2" valign="top"><pre class="screen">local_date_time(local_date_time);</pre></td>
1112<td>Copy Constructor.</td>
1113</tr>
1114<tr><td><pre class="screen">local_date_time az_2(az);</pre></td></tr>
1115<tr>
1116<td rowspan="2" valign="top"><pre class="screen">local_date_time(...)
1117  Parameters:
1118    special_values
1119    time_zone_ptr</pre></td>
1120<td>Special Values constructor.</td>
1121</tr>
1122<tr><td>
1123<pre class="screen">time_zone_ptr zone(
1124  new posix_time_zone("MST-07")
1125);
1126local_date_time nadt(not_a_date_time,
1127                     zone);
1128// default NULL time_zone_ptr
1129local_date_time nadt(pos_infin);</pre>
1130            </td></tr>
1131</tbody>
1132</table></div>
1133<p>
1134  </p>
1135<a name="local_date_time_accessors"></a><h3>
1136<a name="id978500"></a>Accessors</h3>
1137<p>
1138    </p>
1139<div class="informaltable"><table class="table">
1140<colgroup>
1141<col>
1142<col>
1143</colgroup>
1144<thead>
1145<tr>
1146<th rowspan="2" valign="top">Syntax</th>
1147<th>Description</th>
1148</tr>
1149<tr><th>Example</th></tr>
1150</thead>
1151<tbody>
1152<tr>
1153<td rowspan="2" valign="top"><pre class="screen">time_zone_ptr zone()</pre></td>
1154<td>Returns associated time_zone object via a time_zone_ptr</td>
1155</tr>
1156<tr><td><pre class="screen"></pre></td></tr>
1157<tr>
1158<td rowspan="2" valign="top"><pre class="screen">bool is_dst()</pre></td>
1159<td>Determines if time value is in DST for associated zone.</td>
1160</tr>
1161<tr><td> </td></tr>
1162<tr>
1163<td rowspan="2" valign="top"><pre class="screen">ptime utc_time()</pre></td>
1164<td>Converts the local time value to a UTC value.</td>
1165</tr>
1166<tr><td>
1167<pre class="screen">ptime pt(date(2004,Nov,5),
1168         hours(10));
1169time_zone_ptr zone(
1170  new posix_time_zone("MST-07"));
1171local_date_time az(pt, zone);
1172az.utc_time(); // 10am 2004-Nov-5</pre>
1173            </td></tr>
1174<tr>
1175<td rowspan="2" valign="top"><pre class="screen">ptime local_time()</pre></td>
1176<td>Returns the local time for this object (Wall-clock).</td>
1177</tr>
1178<tr><td><pre class="screen">ptime pt(date(2004,Nov,5),
1179         hours(10));
1180time_zone_ptr zone(
1181  new posix_time_zone("MST-07"));
1182local_date_time az(pt, zone);
1183az.utc_time(); // 10am 2004-Nov-5
1184az.local_time(); // 3am 2004-Nov-5</pre></td></tr>
1185<tr>
1186<td rowspan="2" valign="top"><pre class="screen">local_time_in(...)
1187  Return Type:
1188    local_date_time
1189  Parameters:
1190    time_zone_ptr
1191    time_duration</pre></td>
1192<td>Returns a local_date_time representing the same UTC time as calling object, plus optional time_duration, with given time zone.</td>
1193</tr>
1194<tr><td>
1195<pre class="screen">local_date_time nyc = az.local_time_in(nyc_zone);
1196// nyc == 7am 2004-Nov-5</pre>
1197            </td></tr>
1198<tr>
1199<td rowspan="2" valign="top"><pre class="screen">bool is_infinity() const</pre></td>
1200<td>Returns true if local_date_time is either positive or negative infinity</td>
1201</tr>
1202<tr><td><pre class="screen">local_date_time ldt(pos_infin);
1203ldt.is_infinity(); // --&gt; true</pre></td></tr>
1204<tr>
1205<td rowspan="2" valign="top"><pre class="screen">bool is_neg_infinity() const</pre></td>
1206<td>Returns true if local_date_time is negative infinity</td>
1207</tr>
1208<tr><td><pre class="screen">local_date_time ldt(neg_infin);
1209ldt.is_neg_infinity(); // --&gt; true</pre></td></tr>
1210<tr>
1211<td rowspan="2" valign="top"><pre class="screen">bool is_pos_infinity() const</pre></td>
1212<td>Returns true if local_date_time is positive infinity</td>
1213</tr>
1214<tr><td><pre class="screen">local_date_time ldt(neg_infin);
1215ldt.is_pos_infinity(); // --&gt; true</pre></td></tr>
1216<tr>
1217<td rowspan="2" valign="top"><pre class="screen">bool is_not_a_date_time() const</pre></td>
1218<td>Returns true if value is not a date</td>
1219</tr>
1220<tr><td><pre class="screen">local_date_time ldt(not_a_date_time);
1221ldt.is_not_a_date_time(); // --&gt; true</pre></td></tr>
1222<tr>
1223<td rowspan="2" valign="top"><pre class="screen">bool is_special() const</pre></td>
1224<td>Returns true if local_date_time is any <code class="computeroutput">special_value</code>
1225</td>
1226</tr>
1227<tr><td><pre class="screen">local_date_time ldt(pos_infin);
1228local_date_time ldt2(not_a_date_time);
1229time_zone_ptr
1230  mst(new posix_time_zone("MST-07"));
1231local_date_time
1232  ldt3(local_sec_clock::local_time(mst));
1233ldt.is_special(); // --&gt; true
1234ldt2.is_special(); // --&gt; true
1235ldt3.is_special(); // --&gt; false</pre></td></tr>
1236</tbody>
1237</table></div>
1238<p>
1239  </p>
1240<a name="local_date_time_operators"></a><h3>
1241<a name="id996315"></a>Operators</h3>
1242<div class="informaltable"><table class="table">
1243<colgroup>
1244<col>
1245<col>
1246</colgroup>
1247<thead>
1248<tr>
1249<th rowspan="2" valign="top">Syntax</th>
1250<th>Description</th>
1251</tr>
1252<tr><th>Example</th></tr>
1253</thead>
1254<tbody>
1255<tr>
1256<td rowspan="2" valign="top"><pre class="screen">operator&lt;&lt;</pre></td>
1257<td>Output streaming operator. This operator is part of the v1.33 IO addition to date_time. For complete details on this feature see <a href="date_time_io.html" title="Date Time Input/Output">Date Time IO</a>. The default output is shown in this example.</td>
1258</tr>
1259<tr><td><pre class="screen">
1260time_zone_ptr zone(new posix_time_zone("MST-07");
1261local_date_time ldt(date(2005,Jul,4),
1262                    hours(20),
1263                    false);
1264std::cout &lt;&lt; ldt &lt;&lt; std::endl;
1265// "2005-Jul-04 20:00:00 MST"
1266          </pre></td></tr>
1267<tr>
1268<td rowspan="2" valign="top"><pre class="screen">operator&gt;&gt;</pre></td>
1269<td>Input streaming operator. This operator is part of the v1.33 IO addition to date_time. For complete details on this feature see <a href="date_time_io.html" title="Date Time Input/Output">Date Time IO</a>. At this time, <code class="computeroutput">local_date_time</code> objects can only be streamed in with a Posix Time Zone string. A complete description of a Posix Time Zone string can be found in the documentation for the <a href="local_time.html#posix_time_zone_intro">posix_time_zone</a> class.</td>
1270</tr>
1271<tr><td><pre class="screen">stringstream ss;
1272ss.str("2005-Jul-04 20:00:00 MST-07");
1273ss &gt;&gt; ldt;
1274          </pre></td></tr>
1275<tr>
1276<td rowspan="2" valign="top"><pre class="screen">operator==, operator!=,
1277operator&gt;, operator&lt;,
1278operator&gt;=, operator&lt;=</pre></td>
1279<td>A full complement of comparison operators</td>
1280</tr>
1281<tr><td><pre class="screen">ldt1 == ldt2, etc</pre></td></tr>
1282<tr>
1283<td rowspan="2" valign="top"><pre class="screen">operator+, operator+=,
1284operator-, operator-=</pre></td>
1285<td>Addition, subtraction, and shortcut operators for <code class="computeroutput">local_date_time</code> and date duration types. These include: <code class="computeroutput">days</code>, <code class="computeroutput">months</code>, and <code class="computeroutput">years</code>.</td>
1286</tr>
1287<tr><td><pre class="screen">ldt + days(5), etc</pre></td></tr>
1288<tr>
1289<td rowspan="2" valign="top"><pre class="screen">operator+, operator+=,
1290operator-, operator-=</pre></td>
1291<td>Addition, subtraction, and shortcut operators for <code class="computeroutput">local_date_time</code> and <code class="computeroutput">time_duration</code>.</td>
1292</tr>
1293<tr><td><pre class="screen">ldt + hours(5), etc</pre></td></tr>
1294</tbody>
1295</table></div>
1296<a name="local_date_time_tm_func"></a><h3>
1297<a name="id996601"></a>Struct tm Functions</h3>
1298<p>Function for converting a <code class="computeroutput">local_date_time</code> object to a <code class="computeroutput">tm</code> struct is provided.</p>
1299<div class="informaltable"><table class="table">
1300<colgroup>
1301<col>
1302<col>
1303</colgroup>
1304<thead>
1305<tr>
1306<th rowspan="2" valign="top">Syntax</th>
1307<th>Description</th>
1308</tr>
1309<tr><th>Example</th></tr>
1310</thead>
1311<tbody>
1312<tr>
1313<td rowspan="2" valign="top"><pre class="screen">tm to_tm(local_date_time)</pre></td>
1314<td>A function for converting a <code class="computeroutput">local_date_time</code> object to a <code class="computeroutput">tm</code> struct.</td>
1315</tr>
1316<tr><td>
1317<pre class="screen">
1318// 6am, 2005-Jul-05 local time
1319std::string z("EST-05EDT,M4.1.0,M10.1.0");
1320ptime pt(date(2005,Jul,5),
1321         hours(10));
1322time_zone_ptr zone( new posix_time_zone(z));
1323local_date_time ldt(pt, zone);
1324tm ldt_tm = to_tm(ldt);
1325/* tm_year =&gt; 105
1326   tm_mon  =&gt; 6
1327   tm_mday =&gt; 5
1328   tm_wday =&gt; 2 (Tuesday)
1329   tm_yday =&gt; 185
1330   tm_hour =&gt; 6
1331   tm_min  =&gt; 0
1332   tm_sec  =&gt; 0
1333   tm_isddst =&gt; 1 */</pre>
1334          </td></tr>
1335</tbody>
1336</table></div>
1337</div>
1338<div class="section" lang="en">
1339<div class="titlepage"><div><div><h3 class="title">
1340<a name="date_time.local_time.local_time_period"></a>Local Time Period</h3></div></div></div>
1341<a href="local_time.html#local_time_period_intro">Introduction</a> --
1342  <a href="local_time.html#local_time_period_header">Header</a> --
1343  <a href="local_time.html#local_time_period_constr">Construction</a> --
1344  <a href="local_time.html#local_time_period_accessors">Accessors</a> --
1345  <a href="local_time.html#local_time_period_operators">Operators</a><a name="local_time_period_intro"></a><h3>
1346<a name="id996767"></a>Introduction</h3>
1347<p>
1348    The class <code class="computeroutput">boost::local_time::local_time_period</code> provides direct representation for ranges between two local times. Periods provide the ability to simplify some types of calculations by simplifying the conditional logic of the program.
1349  </p>
1350<p>
1351    A period that is created with beginning and end points being equal, or with a duration of zero, is known as a zero length period. Zero length periods are considered invalid (it is perfectly legal to construct an invalid period). For these periods, the <code class="computeroutput">last</code> point will always be one unit less that the <code class="computeroutput">begin</code> point.
1352  </p>
1353<a name="local_time_period_header"></a><h3>
1354<a name="id996812"></a>Header</h3>
1355<p>
1356    </p>
1357<pre class="programlisting">#include "boost/date_time/local_time/local_time.hpp" //include all types plus i/o
1358or
1359#include "boost/date_time/local_time/local_time_types.hpp" //no i/o just types</pre>
1360<p>
1361  </p>
1362<a name="local_time_period_constr"></a><h3>
1363<a name="id996834"></a>Construction</h3>
1364<p>
1365    </p>
1366<div class="informaltable"><table class="table">
1367<colgroup>
1368<col>
1369<col>
1370</colgroup>
1371<thead>
1372<tr>
1373<th rowspan="2" valign="top">Syntax</th>
1374<th>Description</th>
1375</tr>
1376<tr><th>Example</th></tr>
1377</thead>
1378<tbody>
1379<tr>
1380<td rowspan="2" valign="top"><pre class="screen">local_time_period(...)
1381  Parameters:
1382    local_date_time beginning
1383    local_date_time end</pre></td>
1384<td> Create a period as [begin, end). If end is &lt;= begin then the period will be defined as invalid.</td>
1385</tr>
1386<tr><td>
1387<pre class="screen">time_zone_ptr
1388  zone(new posix_time_zone("MST-07"));
1389local_date_time
1390  beg(ptime(date(2005,Jan,1),hours(0)), zone);
1391local_date_time
1392  end(ptime(date(2005,Feb,1),hours(0)), zone);
1393// period for the entire month of Jan 2005
1394local_time_period ltp(beg, end);</pre>
1395            </td></tr>
1396<tr>
1397<td rowspan="2" valign="top"><pre class="screen">local_time_period(...)
1398  Parameters:
1399    local_date_time beginning
1400    time_duration length</pre></td>
1401<td>Create a period as [begin, begin+len) where end would be begin+len. If len is &lt;= zero then the period will be defined as invalid.</td>
1402</tr>
1403<tr><td>
1404<pre class="screen">time_zone_ptr
1405  zone(new posix_time_zone("MST-07"));
1406local_date_time
1407  beg(ptime(date(2005,Jan,1),hours(0)), zone);
1408// period for the whole day of 2005-Jan-01
1409local_time_period ltp(beg, hours(24));</pre>
1410            </td></tr>
1411<tr>
1412<td rowspan="2" valign="top"><pre class="screen">local_time_period(local_time_period rhs)</pre></td>
1413<td>Copy constructor</td>
1414</tr>
1415<tr><td><pre class="screen">local_time_period ltp1(ltp);</pre></td></tr>
1416</tbody>
1417</table></div>
1418<p>
1419  </p>
1420<a name="local_time_period_accessors"></a><h3>
1421<a name="id996988"></a>Accessors</h3>
1422<p>
1423    </p>
1424<div class="informaltable"><table class="table">
1425<colgroup>
1426<col>
1427<col>
1428</colgroup>
1429<thead>
1430<tr>
1431<th rowspan="2" valign="top">Syntax</th>
1432<th>Description</th>
1433</tr>
1434<tr><th>Example</th></tr>
1435</thead>
1436<tbody>
1437<tr>
1438<td rowspan="2" valign="top"><pre class="screen">local_date_time begin()</pre></td>
1439<td>Return first local_date_time of the period.</td>
1440</tr>
1441<tr><td>
1442<pre class="screen">time_zone_ptr
1443  zone(new posix_time_zone("MST-07"));
1444local_date_time
1445  ldt((ptime(date(2005,Jan,1)),hours(0)), zone);
1446local_time_period ltp(ldt, hours(2));
1447ltp.begin(); // =&gt; 2005-Jan-01 00:00:00</pre>
1448            </td></tr>
1449<tr>
1450<td rowspan="2" valign="top"><pre class="screen">local_date_time last()</pre></td>
1451<td>Return last local_date_time in the period</td>
1452</tr>
1453<tr><td>
1454<pre class="screen">time_zone_ptr
1455  zone(new posix_time_zone("MST-07"));
1456local_date_time
1457  ldt((ptime(date(2005,Jan,1),hours(0))), zone);
1458local_time_period ltp(ldt, hours(2));
1459ltp.last(); // =&gt; 2005-Jan-01 01:59:59.999999999</pre>
1460            </td></tr>
1461<tr>
1462<td rowspan="2" valign="top"><pre class="screen">local_date_time end()</pre></td>
1463<td>Return one past the last in period</td>
1464</tr>
1465<tr><td>
1466<pre class="screen">time_zone_ptr
1467  zone(new posix_time_zone("MST-07"));
1468local_date_time
1469  ldt((ptime(date(2005,Jan,1),hours(0))), zone);
1470local_time_period ltp(ldt, hours(2));
1471ltp.end(); // =&gt; 2005-Jan-01 02:00:00</pre>
1472            </td></tr>
1473<tr>
1474<td rowspan="2" valign="top"><pre class="screen">time_duration length()</pre></td>
1475<td>Return the length of the local_time period.</td>
1476</tr>
1477<tr><td>
1478<pre class="screen">time_zone_ptr
1479  zone(new posix_time_zone("MST-07"));
1480local_date_time
1481  ldt((ptime(date(2005,Jan,1),hours(0))), zone);
1482local_time_period ltp(ldt, hours(2));
1483ltp.length(); // =&gt; 02:00:00</pre>
1484            </td></tr>
1485<tr>
1486<td rowspan="2" valign="top"><pre class="screen">bool is_null()</pre></td>
1487<td>True if period is not well formed. eg: end less than or equal to begin.</td>
1488</tr>
1489<tr><td>
1490<pre class="screen">time_zone_ptr
1491  zone(new posix_time_zone("MST-07"));
1492local_date_time
1493  beg((ptime(date(2005,Feb,1),hours(0))), zone);
1494local_date_time
1495  end((ptime(date(2005,Jan,1),hours(0))), zone);
1496local_time_period ltp(beg, end);
1497ltp.is_null(); // =&gt; true</pre>
1498            </td></tr>
1499<tr>
1500<td rowspan="2" valign="top"><pre class="screen">bool contains(local_date_time)</pre></td>
1501<td>True if local_date_time is within the period. Zero length periods cannot contain any points</td>
1502</tr>
1503<tr><td><pre class="screen">time_zone_ptr
1504  zone(new posix_time_zone("MST-07"));
1505local_date_time
1506  beg((ptime(date(2005,Jan,1),hours(0))), zone);
1507local_date_time
1508  end((ptime(date(2005,Feb,1),hours(0))), zone);
1509local_time_period jan_mst(beg, end);
1510
1511local_date_time
1512ldt((ptime(date(2005,Jan,15),hours(12))), zone);
1513jan_mst.contains(ldt); // =&gt; true
1514
1515local_time_period zero(beg, beg);
1516zero.contains(beg); // false</pre></td></tr>
1517<tr>
1518<td rowspan="2" valign="top"><pre class="screen">bool contains(local_time_period)</pre></td>
1519<td>True if period is within the period</td>
1520</tr>
1521<tr><td><pre class="screen">// using jan_mst period from previous example
1522
1523local_date_time
1524  beg((ptime(date(2005,Jan,7),hours(0))), zone);
1525local_time_period ltp(beg, hours(24));
1526
1527jan_mst.contains(ltp); // =&gt; true</pre></td></tr>
1528<tr>
1529<td rowspan="2" valign="top"><pre class="screen">bool intersects(local_time_period)</pre></td>
1530<td> True if periods overlap</td>
1531</tr>
1532<tr><td><pre class="screen">// using jan_mst period from previous example
1533
1534local_date_time
1535  beg((ptime(date(2005,Jan,7),hours(0))), zone);
1536local_date_time
1537  end((ptime(date(2005,Feb,7),hours(0))), zone);
1538local_time_period ltp(beg, end);
1539
1540jan_mst.intersects(ltp); // =&gt; true</pre></td></tr>
1541<tr>
1542<td rowspan="2" valign="top"><pre class="screen">local_time_period intersection(local_time_period)</pre></td>
1543<td>Calculate the intersection of 2 periods. Null if no intersection.</td>
1544</tr>
1545<tr><td><pre class="screen">// using jan_mst period from previous example
1546
1547local_date_time
1548  beg((ptime(date(2005,Jan,7),hours(0))), zone);
1549local_date_time
1550  end((ptime(date(2005,Feb,7),hours(0))), zone);
1551local_time_period ltp(beg, end);
1552
1553local_time_period res(jan_mst.intersection(ltp));
1554// res =&gt; 2005-Jan-07 00:00:00 through
1555// 2005-Jan-31 23:59:59.999999999 (inclusive)</pre></td></tr>
1556<tr>
1557<td rowspan="2" valign="top"><pre class="screen">local_time_period merge(local_time_period)</pre></td>
1558<td>Returns union of two periods. Null if no intersection.</td>
1559</tr>
1560<tr><td><pre class="screen">// using jan_mst period from previous example
1561
1562local_date_time
1563  beg((ptime(date(2005,Jan,7),hours(0))), zone);
1564local_date_time
1565  end((ptime(date(2005,Feb,7),hours(0))), zone);
1566local_time_period ltp(beg, end);
1567
1568local_time_period res(jan_mst.merge(ltp));
1569// res =&gt; 2005-Jan-07 00:00:00 through
1570// 2005-Feb-06 23:59:59.999999999 (inclusive)</pre></td></tr>
1571<tr>
1572<td rowspan="2" valign="top"><pre class="screen">local_time_period span(local_time_period)</pre></td>
1573<td>Combines two periods and any gap between them such that begin = min(p1.begin, p2.begin) and end = max(p1.end , p2.end).</td>
1574</tr>
1575<tr><td><pre class="screen">// using jan_mst period from previous example
1576
1577local_date_time
1578  beg((ptime(date(2005,Mar,1),hours(0))), zone);
1579local_date_time
1580  end((ptime(date(2005,Apr,1),hours(0))), zone);
1581local_time_period mar_mst(beg, end);
1582
1583local_time_period res(jan_mst.span(mar_mst));
1584// res =&gt; 2005-Jan-01 00:00:00 through
1585// 2005-Mar-31 23:59:59.999999999 (inclusive)</pre></td></tr>
1586<tr>
1587<td rowspan="2" valign="top"><pre class="screen">void shift(time_duration)</pre></td>
1588<td>Add duration to both begin and end.</td>
1589</tr>
1590<tr><td><pre class="screen">local_date_time
1591  beg((ptime(date(2005,Mar,1),hours(0))), zone);
1592local_date_time
1593  end((ptime(date(2005,Apr,1),hours(0))), zone);
1594local_time_period mar_mst(beg, end);
1595
1596mar_mst.shift(hours(48));
1597// mar_mst =&gt; 2005-Mar-03 00:00:00 through
1598// 2005-Apr-02 23:59:59.999999999 (inclusive)</pre></td></tr>
1599</tbody>
1600</table></div>
1601<p>
1602  </p>
1603<a name="local_time_period_operators"></a><h3>
1604<a name="id997417"></a>Operators</h3>
1605<p>
1606    </p>
1607<div class="informaltable"><table class="table">
1608<colgroup>
1609<col>
1610<col>
1611</colgroup>
1612<thead>
1613<tr>
1614<th rowspan="2" valign="top">Syntax</th>
1615<th>Description</th>
1616</tr>
1617<tr><th>Example</th></tr>
1618</thead>
1619<tbody>
1620<tr>
1621<td rowspan="2" valign="top"><pre class="screen">operator==, operator!=</pre></td>
1622<td>Equality operators. Periods are equal if ltp1.begin == ltp2.begin &amp;&amp; ltp1.last == ltp2.last</td>
1623</tr>
1624<tr><td><pre class="screen">if (ltp1 == ltp2) {...</pre></td></tr>
1625<tr>
1626<td rowspan="2" valign="top"><pre class="screen">operator&lt;</pre></td>
1627<td>Ordering with no overlap. True if ltp1.end() less than ltp2.begin()</td>
1628</tr>
1629<tr><td><pre class="screen">if (ltp1 &lt; ltp2) {...</pre></td></tr>
1630<tr>
1631<td rowspan="2" valign="top"><pre class="screen">operator&gt;</pre></td>
1632<td>Ordering with no overlap. True if ltp1.begin() greater than ltp2.end()</td>
1633</tr>
1634<tr><td><pre class="screen">if (ltp1 &gt; ltp2) {... etc</pre></td></tr>
1635<tr>
1636<td rowspan="2" valign="top"><pre class="screen">operator&lt;=, operator&gt;=</pre></td>
1637<td>Defined in terms of the other operators.</td>
1638</tr>
1639<tr><td> </td></tr>
1640</tbody>
1641</table></div>
1642<p>
1643  </p>
1644</div>
1645</div>
1646<table width="100%"><tr>
1647<td align="left"></td>
1648<td align="right"><small>Copyright © 2001-2005 CrystalClear Software, Inc</small></td>
1649</tr></table>
1650<hr>
1651<div class="spirit-nav">
1652<a accesskey="p" href="posix_time.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../date_time.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="date_time_io.html"><img src="../images/next.png" alt="Next"></a>
1653</div>
1654</body>
1655</html>
Note: See TracBrowser for help on using the repository browser.