1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
|
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
"../../../tools/boostbook/dtd/boostbook.dtd">
<!-- Copyright (c) 2001-2006 CrystalClear Software, Inc.
Subject to the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
-->
<section id="date_time.posix_time.time_period">
<title>Time Period</title>
<link linkend="time_period_intro">Introduction</link> --
<link linkend="time_period_header">Header</link> --
<link linkend="time_period_constr">Construction</link> --
<link linkend="time_period_mutators">Mutators</link> --
<link linkend="time_period_accessors">Accessors</link> --
<link linkend="time_period_to_string">Conversion To String</link> --
<link linkend="time_period_operators">Operators</link>
<anchor id="time_period_intro" />
<bridgehead renderas="sect3">Introduction</bridgehead>
<para>
The class boost::posix_time::time_period provides direct representation for ranges between two times. Periods provide the ability to simplify some types of calculations by simplifying the conditional logic of the program.
</para>
<para>
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>last</code> point will always be one unit less that the <code>begin</code> point.
</para>
<para>
The <link linkend="date_time.examples.time_periods">time periods example</link> provides an example of using time periods.
</para>
<anchor id="time_period_header" />
<bridgehead renderas="sect3">Header</bridgehead>
<para>
<programlisting>#include "boost/date_time/posix_time/posix_time.hpp" //include all types plus i/o
or
#include "boost/date_time/posix_time/posix_time_types.hpp" //no i/o just types</programlisting>
</para>
<anchor id="time_period_constr" />
<bridgehead renderas="sect3">Construction</bridgehead>
<para>
<informaltable frame="all">
<tgroup cols="2">
<thead>
<row>
<entry valign="top" morerows="1">Syntax</entry>
<entry>Description</entry>
</row>
<row>
<entry>Example</entry>
</row>
</thead>
<tbody>
<row>
<entry valign="top" morerows="1"><screen>time_period(ptime,
ptime)</screen></entry>
<entry> Create a period as [begin, end). If end is <= begin then the period will be defined as invalid.</entry>
</row>
<row>
<entry><screen>date d(2002,Jan,01);
ptime t(d, seconds(10)); //10 sec after midnight
time_period tp(t, hours(3));</screen>
</entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>time_period(ptime,
time_duration)</screen></entry>
<entry> Create a period as [begin, begin+len) where end would be begin+len. If len is <= zero then the period will be defined as invalid.</entry>
</row>
<row>
<entry><screen>date d(2002,Jan,01);
ptime t1(d, seconds(10)); //10 sec after midnight
ptime t2(d, hours(10)); //10 hours after midnight
time_period tp(t1, t2);</screen>
</entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>time_period(time_period rhs)</screen></entry>
<entry> Copy constructor</entry>
</row>
<row>
<entry><screen>time_period tp1(tp);</screen></entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
<anchor id="time_period_mutators" />
<bridgehead renderas="sect3">Mutators</bridgehead>
<para>
<informaltable frame="all">
<tgroup cols="2">
<thead>
<row>
<entry valign="top" morerows="1">Syntax</entry>
<entry>Description</entry>
</row>
<row>
<entry>Example</entry>
</row>
</thead>
<tbody>
<row>
<entry valign="top" morerows="1"><screen>time_period shift(time_duration)</screen></entry>
<entry>Add duration to both begin and end.</entry>
</row>
<row>
<entry>
<screen>
time_period tp(ptime(date(2005,Jan,1),hours(1)), hours(2));
tp.shift(minutes(5));
// tp == 2005-Jan-01 01:05:00 to 2005-Jan-01 03:05:00
</screen>
</entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>time_period expand(days)</screen></entry>
<entry>Add duration to both begin and end.</entry>
</row>
<row>
<screen>
time_period tp(ptime(date(2005,Jan,1),hours(1)), hours(2));
tp.expand(minutes(5));
// tp == 2005-Jan-01 00:55:00 to 2005-Jan-01 03:05:00
</screen>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
<anchor id="time_period_accessors" />
<bridgehead renderas="sect3">Accessors</bridgehead>
<para>
<informaltable frame="all">
<tgroup cols="2">
<thead>
<row>
<entry valign="top" morerows="1">Syntax</entry>
<entry>Description</entry>
</row>
<row>
<entry>Example</entry>
</row>
</thead>
<tbody>
<row>
<entry valign="top" morerows="1"><screen>ptime begin()</screen></entry>
<entry>Return first time of period.</entry>
</row>
<row>
<entry><screen>date d(2002,Jan,01);
ptime t1(d, seconds(10)); //10 sec after midnight
ptime t2(d, hours(10)); //10 hours after midnight
time_period tp(t1, t2);
tp.begin(); // --> 2002-Jan-01 00:00:10</screen>
</entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>ptime last()</screen></entry>
<entry>Return last time in the period</entry>
</row>
<row>
<entry><screen>date d(2002,Jan,01);
ptime t1(d, seconds(10)); //10 sec after midnight
ptime t2(d, hours(10)); //10 hours after midnight
time_period tp(t1, t2);
tp.last();// --> 2002-Jan-01 09:59:59.999999999</screen>
</entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>ptime end()</screen></entry>
<entry> Return one past the last in period</entry>
</row>
<row>
<entry><screen>date d(2002,Jan,01);
ptime t1(d, seconds(10)); //10 sec after midnight
ptime t2(d, hours(10)); //10 hours after midnight
time_period tp(t1, t2);
tp.last(); // --> 2002-Jan-01 10:00:00</screen>
</entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>time_duration length()</screen></entry>
<entry>Return the length of the time period.</entry>
</row>
<row>
<entry><screen>date d(2002,Jan,01);
ptime t1(d); //midnight
time_period tp(t1, hours(1));
tp.length() --> 1 hour</screen>
</entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>bool is_null()</screen></entry>
<entry>True if period is not well formed. eg: end is less than or equal to begin.</entry>
</row>
<row>
<entry><screen>date d(2002,Jan,01);
ptime t1(d, hours(12)); // noon on Jan 1st
ptime t2(d, hours(9)); // 9am on Jan 1st
time_period tp(t1, t2);
tp.is_null(); // true</screen>
</entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>bool contains(ptime)</screen></entry>
<entry>True if ptime is within the period. Zero length periods cannot contain any points.</entry>
</row>
<row>
<entry><screen>date d(2002,Jan,01);
ptime t1(d, seconds(10)); //10 sec after midnight
ptime t2(d, hours(10)); //10 hours after midnight
ptime t3(d, hours(2)); //2 hours after midnight
time_period tp(t1, t2);
tp.contains(t3); // true
time_period tp2(t1, t1);
tp2.contains(t1); // false</screen>
</entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>bool contains(time_period)</screen></entry>
<entry>True if period is within the period</entry>
</row>
<row>
<entry><screen>time_period tp1(ptime(d,hours(1)),
ptime(d,hours(12)));
time_period tp2(ptime(d,hours(2)),
ptime(d,hours(4)));
tp1.contains(tp2); // --> true
tp2.contains(tp1); // --> false</screen>
</entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>bool intersects(time_period)</screen></entry>
<entry> True if periods overlap</entry>
</row>
<row>
<entry><screen>time_period tp1(ptime(d,hours(1)),
ptime(d,hours(12)));
time_period tp2(ptime(d,hours(2)),
ptime(d,hours(4)));
tp2.intersects(tp1); // --> true</screen>
</entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>time_period intersection(time_period)</screen></entry>
<entry>Calculate the intersection of 2 periods. Null if no intersection.</entry>
</row>
<row>
<entry></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>time_period merge(time_period)</screen></entry>
<entry>Returns union of two periods. Null if no intersection.</entry>
</row>
<row>
<entry></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>time_period span(time_period)</screen></entry>
<entry>Combines two periods and any gap between them such that begin = min(p1.begin, p2.begin) and end = max(p1.end , p2.end).</entry>
</row>
<row>
<entry></entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
<anchor id="time_period_to_string" />
<bridgehead renderas="sect3">Conversion To String</bridgehead>
<para>
<informaltable frame="all">
<tgroup cols="2">
<thead>
<row>
<entry valign="top" morerows="1">Syntax</entry>
<entry>Description</entry>
</row>
<row>
<entry>Example</entry>
</row>
</thead>
<tbody>
<row>
<entry valign="top" morerows="1"><screen>std::string
to_simple_string(time_period dp)</screen></entry>
<entry>To <code>[YYYY-mmm-DD hh:mm:ss.fffffffff/YYYY-mmm-DD hh:mm:ss.fffffffff]</code> string where <code>mmm</code> is 3 char month name.</entry>
</row>
<row>
<entry><screen>[2002-Jan-01 01:25:10.000000001/
2002-Jan-31 01:25:10.123456789]
// string occupies one line</screen></entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
<anchor id="time_period_operators" />
<bridgehead renderas="sect3">Operators</bridgehead>
<para>
<informaltable frame="all">
<tgroup cols="2">
<thead>
<row>
<entry valign="top" morerows="1">Syntax</entry>
<entry>Description</entry>
</row>
<row>
<entry>Example</entry>
</row>
</thead>
<tbody>
<row>
<entry valign="top" morerows="1"><screen>operator<<</screen></entry>
<entry>Output streaming operator for time duration. Uses facet to output [date time_of_day/date time_of_day]. The default is format is <code>[YYYY-mmm-DD hh:mm:ss.fffffffff/YYYY-mmm-DD hh:mm:ss.fffffffff]</code> string where <code>mmm</code> is 3 char month name and the fractional seconds are left out when zero.</entry>
</row>
<row>
<entry><screen>[2002-Jan-01 01:25:10.000000001/ \
2002-Jan-31 01:25:10.123456789]</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>operator>></screen></entry>
<entry>Input streaming operator for time duration. Uses facet to read [date time_of_day/date time_of_day]. The default is format is <code>[YYYY-mmm-DD hh:mm:ss.fffffffff/YYYY-mmm-DD hh:mm:ss.fffffffff]</code> string where <code>mmm</code> is 3 char month name and the fractional seconds are left out when zero.</entry>
</row>
<row>
<entry><screen>[2002-Jan-01 01:25:10.000000001/ \
2002-Jan-31 01:25:10.123456789]</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>operator==, operator!=</screen></entry>
<entry>Equality operators. Periods are equal if p1.begin == p2.begin && p1.last == p2.last</entry>
</row>
<row>
<entry><screen>if (tp1 == tp2) {...</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>operator<</screen></entry>
<entry>Ordering with no overlap. True if tp1.end() less than tp2.begin()</entry>
</row>
<row>
<entry><screen>if (tp1 < tp2) {...</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>operator></screen></entry>
<entry>Ordering with no overlap. True if tp1.begin() greater than tp2.end()</entry>
</row>
<row>
<entry><screen>if (tp1 > tp2) {... etc</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>operator<=, operator>=</screen></entry>
<entry>Defined in terms of the other operators.</entry>
</row>
<row>
<entry></entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
</section>
|