local_time_period.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
  3. "../../../tools/boostbook/dtd/boostbook.dtd">
  4. <!-- Copyright (c) 2001-2005 CrystalClear Software, Inc.
  5. Subject to the Boost Software License, Version 1.0.
  6. (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
  7. -->
  8. <section id="date_time.local_time.local_time_period">
  9. <title>Local Time Period</title>
  10. <link linkend="local_time_period_intro">Introduction</link> --
  11. <link linkend="local_time_period_header">Header</link> --
  12. <link linkend="local_time_period_constr">Construction</link> --
  13. <link linkend="local_time_period_accessors">Accessors</link> --
  14. <link linkend="local_time_period_operators">Operators</link>
  15. <anchor id="local_time_period_intro" />
  16. <bridgehead renderas="sect3">Introduction</bridgehead>
  17. <para>
  18. The class <code>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.
  19. </para>
  20. <para>
  21. 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.
  22. </para>
  23. <anchor id="local_time_period_header" />
  24. <bridgehead renderas="sect3">Header</bridgehead>
  25. <para>
  26. <programlisting>#include "boost/date_time/local_time/local_time.hpp" //include all types plus i/o
  27. or
  28. #include "boost/date_time/local_time/local_time_types.hpp" //no i/o just types</programlisting>
  29. </para>
  30. <anchor id="local_time_period_constr" />
  31. <bridgehead renderas="sect3">Construction</bridgehead>
  32. <para>
  33. <informaltable frame="all">
  34. <tgroup cols="2">
  35. <thead>
  36. <row>
  37. <entry valign="top" morerows="1">Syntax</entry>
  38. <entry>Description</entry>
  39. </row>
  40. <row>
  41. <entry>Example</entry>
  42. </row>
  43. </thead>
  44. <tbody>
  45. <row>
  46. <entry valign="top" morerows="1"><screen>local_time_period(...)
  47. Parameters:
  48. local_date_time beginning
  49. local_date_time end</screen></entry>
  50. <entry> Create a period as [begin, end). If end is &lt;= begin then the period will be defined as invalid.</entry>
  51. </row>
  52. <row>
  53. <entry><screen>time_zone_ptr
  54. zone(new posix_time_zone("MST-07"));
  55. local_date_time
  56. beg(ptime(date(2005,Jan,1),hours(0)), zone);
  57. local_date_time
  58. end(ptime(date(2005,Feb,1),hours(0)), zone);
  59. // period for the entire month of Jan 2005
  60. local_time_period ltp(beg, end);</screen>
  61. </entry>
  62. </row>
  63. <row>
  64. <entry valign="top" morerows="1"><screen>local_time_period(...)
  65. Parameters:
  66. local_date_time beginning
  67. time_duration length</screen></entry>
  68. <entry>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.</entry>
  69. </row>
  70. <row>
  71. <entry><screen>time_zone_ptr
  72. zone(new posix_time_zone("MST-07"));
  73. local_date_time
  74. beg(ptime(date(2005,Jan,1),hours(0)), zone);
  75. // period for the whole day of 2005-Jan-01
  76. local_time_period ltp(beg, hours(24));</screen>
  77. </entry>
  78. </row>
  79. <row>
  80. <entry valign="top" morerows="1"><screen>local_time_period(local_time_period rhs)</screen></entry>
  81. <entry>Copy constructor</entry>
  82. </row>
  83. <row>
  84. <entry><screen>local_time_period ltp1(ltp);</screen></entry>
  85. </row>
  86. </tbody>
  87. </tgroup>
  88. </informaltable>
  89. </para>
  90. <anchor id="local_time_period_accessors" />
  91. <bridgehead renderas="sect3">Accessors</bridgehead>
  92. <para>
  93. <informaltable frame="all">
  94. <tgroup cols="2">
  95. <thead>
  96. <row>
  97. <entry valign="top" morerows="1">Syntax</entry>
  98. <entry>Description</entry>
  99. </row>
  100. <row>
  101. <entry>Example</entry>
  102. </row>
  103. </thead>
  104. <tbody>
  105. <row>
  106. <entry valign="top" morerows="1"><screen>local_date_time begin()</screen></entry>
  107. <entry>Return first local_date_time of the period.</entry>
  108. </row>
  109. <row>
  110. <entry><screen>time_zone_ptr
  111. zone(new posix_time_zone("MST-07"));
  112. local_date_time
  113. ldt((ptime(date(2005,Jan,1)),hours(0)), zone);
  114. local_time_period ltp(ldt, hours(2));
  115. ltp.begin(); // => 2005-Jan-01 00:00:00</screen>
  116. </entry>
  117. </row>
  118. <row>
  119. <entry valign="top" morerows="1"><screen>local_date_time last()</screen></entry>
  120. <entry>Return last local_date_time in the period</entry>
  121. </row>
  122. <row>
  123. <entry><screen>time_zone_ptr
  124. zone(new posix_time_zone("MST-07"));
  125. local_date_time
  126. ldt((ptime(date(2005,Jan,1),hours(0))), zone);
  127. local_time_period ltp(ldt, hours(2));
  128. ltp.last(); // => 2005-Jan-01 01:59:59.999999999</screen>
  129. </entry>
  130. </row>
  131. <row>
  132. <entry valign="top" morerows="1"><screen>local_date_time end()</screen></entry>
  133. <entry>Return one past the last in period</entry>
  134. </row>
  135. <row>
  136. <entry><screen>time_zone_ptr
  137. zone(new posix_time_zone("MST-07"));
  138. local_date_time
  139. ldt((ptime(date(2005,Jan,1),hours(0))), zone);
  140. local_time_period ltp(ldt, hours(2));
  141. ltp.end(); // => 2005-Jan-01 02:00:00</screen>
  142. </entry>
  143. </row>
  144. <row>
  145. <entry valign="top" morerows="1"><screen>time_duration length()</screen></entry>
  146. <entry>Return the length of the local_time period.</entry>
  147. </row>
  148. <row>
  149. <entry><screen>time_zone_ptr
  150. zone(new posix_time_zone("MST-07"));
  151. local_date_time
  152. ldt((ptime(date(2005,Jan,1),hours(0))), zone);
  153. local_time_period ltp(ldt, hours(2));
  154. ltp.length(); // => 02:00:00</screen>
  155. </entry>
  156. </row>
  157. <row>
  158. <entry valign="top" morerows="1"><screen>bool is_null()</screen></entry>
  159. <entry>True if period is not well formed. eg: end less than or equal to begin.</entry>
  160. </row>
  161. <row>
  162. <entry><screen>time_zone_ptr
  163. zone(new posix_time_zone("MST-07"));
  164. local_date_time
  165. beg((ptime(date(2005,Feb,1),hours(0))), zone);
  166. local_date_time
  167. end((ptime(date(2005,Jan,1),hours(0))), zone);
  168. local_time_period ltp(beg, end);
  169. ltp.is_null(); // => true</screen>
  170. </entry>
  171. </row>
  172. <row>
  173. <entry valign="top" morerows="1"><screen>bool contains(local_date_time)</screen></entry>
  174. <entry>True if local_date_time is within the period. Zero length periods cannot contain any points</entry>
  175. </row>
  176. <row>
  177. <entry><screen>time_zone_ptr
  178. zone(new posix_time_zone("MST-07"));
  179. local_date_time
  180. beg((ptime(date(2005,Jan,1),hours(0))), zone);
  181. local_date_time
  182. end((ptime(date(2005,Feb,1),hours(0))), zone);
  183. local_time_period jan_mst(beg, end);
  184. local_date_time
  185. ldt((ptime(date(2005,Jan,15),hours(12))), zone);
  186. jan_mst.contains(ldt); // => true
  187. local_time_period zero(beg, beg);
  188. zero.contains(beg); // false</screen></entry>
  189. </row>
  190. <row>
  191. <entry valign="top" morerows="1"><screen>bool contains(local_time_period)</screen></entry>
  192. <entry>True if period is within the period</entry>
  193. </row>
  194. <row>
  195. <entry><screen>// using jan_mst period from previous example
  196. local_date_time
  197. beg((ptime(date(2005,Jan,7),hours(0))), zone);
  198. local_time_period ltp(beg, hours(24));
  199. jan_mst.contains(ltp); // => true</screen></entry>
  200. </row>
  201. <row>
  202. <entry valign="top" morerows="1"><screen>bool intersects(local_time_period)</screen></entry>
  203. <entry> True if periods overlap</entry>
  204. </row>
  205. <row>
  206. <entry><screen>// using jan_mst period from previous example
  207. local_date_time
  208. beg((ptime(date(2005,Jan,7),hours(0))), zone);
  209. local_date_time
  210. end((ptime(date(2005,Feb,7),hours(0))), zone);
  211. local_time_period ltp(beg, end);
  212. jan_mst.intersects(ltp); // => true</screen></entry>
  213. </row>
  214. <row>
  215. <entry valign="top" morerows="1"><screen>local_time_period intersection(local_time_period)</screen></entry>
  216. <entry>Calculate the intersection of 2 periods. Null if no intersection.</entry>
  217. </row>
  218. <row>
  219. <entry><screen>// using jan_mst period from previous example
  220. local_date_time
  221. beg((ptime(date(2005,Jan,7),hours(0))), zone);
  222. local_date_time
  223. end((ptime(date(2005,Feb,7),hours(0))), zone);
  224. local_time_period ltp(beg, end);
  225. local_time_period res(jan_mst.intersection(ltp));
  226. // res => 2005-Jan-07 00:00:00 through
  227. // 2005-Jan-31 23:59:59.999999999 (inclusive)</screen></entry>
  228. </row>
  229. <row>
  230. <entry valign="top" morerows="1"><screen>local_time_period merge(local_time_period)</screen></entry>
  231. <entry>Returns union of two periods. Null if no intersection.</entry>
  232. </row>
  233. <row>
  234. <entry><screen>// using jan_mst period from previous example
  235. local_date_time
  236. beg((ptime(date(2005,Jan,7),hours(0))), zone);
  237. local_date_time
  238. end((ptime(date(2005,Feb,7),hours(0))), zone);
  239. local_time_period ltp(beg, end);
  240. local_time_period res(jan_mst.merge(ltp));
  241. // res => 2005-Jan-07 00:00:00 through
  242. // 2005-Feb-06 23:59:59.999999999 (inclusive)</screen></entry>
  243. </row>
  244. <row>
  245. <entry valign="top" morerows="1"><screen>local_time_period span(local_time_period)</screen></entry>
  246. <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>
  247. </row>
  248. <row>
  249. <entry><screen>// using jan_mst period from previous example
  250. local_date_time
  251. beg((ptime(date(2005,Mar,1),hours(0))), zone);
  252. local_date_time
  253. end((ptime(date(2005,Apr,1),hours(0))), zone);
  254. local_time_period mar_mst(beg, end);
  255. local_time_period res(jan_mst.span(mar_mst));
  256. // res => 2005-Jan-01 00:00:00 through
  257. // 2005-Mar-31 23:59:59.999999999 (inclusive)</screen></entry>
  258. </row>
  259. <row>
  260. <entry valign="top" morerows="1"><screen>void shift(time_duration)</screen></entry>
  261. <entry>Add duration to both begin and end.</entry>
  262. </row>
  263. <row>
  264. <entry><screen>local_date_time
  265. beg((ptime(date(2005,Mar,1),hours(0))), zone);
  266. local_date_time
  267. end((ptime(date(2005,Apr,1),hours(0))), zone);
  268. local_time_period mar_mst(beg, end);
  269. mar_mst.shift(hours(48));
  270. // mar_mst => 2005-Mar-03 00:00:00 through
  271. // 2005-Apr-02 23:59:59.999999999 (inclusive)</screen></entry>
  272. </row>
  273. </tbody>
  274. </tgroup>
  275. </informaltable>
  276. </para>
  277. <anchor id="local_time_period_operators" />
  278. <bridgehead renderas="sect3">Operators</bridgehead>
  279. <para>
  280. <informaltable frame="all">
  281. <tgroup cols="2">
  282. <thead>
  283. <row>
  284. <entry valign="top" morerows="1">Syntax</entry>
  285. <entry>Description</entry>
  286. </row>
  287. <row>
  288. <entry>Example</entry>
  289. </row>
  290. </thead>
  291. <tbody>
  292. <!-- TODO: the streaming operators have not bee changed from time_period to local_time_period
  293. <row>
  294. <entry valign="top" morerows="1"><screen>operator&lt;&lt;</screen></entry>
  295. <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>
  296. </row>
  297. <row>
  298. <entry><screen>[2002-Jan-01 01:25:10.000000001/ \
  299. 2002-Jan-31 01:25:10.123456789]</screen></entry>
  300. </row>
  301. <row>
  302. <entry valign="top" morerows="1"><screen>operator&gt;&gt;</screen></entry>
  303. <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>
  304. </row>
  305. <row>
  306. <entry><screen>[2002-Jan-01 01:25:10.000000001/ \
  307. 2002-Jan-31 01:25:10.123456789]</screen></entry>
  308. </row>
  309. -->
  310. <row>
  311. <entry valign="top" morerows="1"><screen>operator==, operator!=</screen></entry>
  312. <entry>Equality operators. Periods are equal if ltp1.begin == ltp2.begin &amp;&amp; ltp1.last == ltp2.last</entry>
  313. </row>
  314. <row>
  315. <entry><screen>if (ltp1 == ltp2) {...</screen></entry>
  316. </row>
  317. <row>
  318. <entry valign="top" morerows="1"><screen>operator&lt;</screen></entry>
  319. <entry>Ordering with no overlap. True if ltp1.end() less than ltp2.begin()</entry>
  320. </row>
  321. <row>
  322. <entry><screen>if (ltp1 &lt; ltp2) {...</screen></entry>
  323. </row>
  324. <row>
  325. <entry valign="top" morerows="1"><screen>operator&gt;</screen></entry>
  326. <entry>Ordering with no overlap. True if ltp1.begin() greater than ltp2.end()</entry>
  327. </row>
  328. <row>
  329. <entry><screen>if (ltp1 > ltp2) {... etc</screen></entry>
  330. </row>
  331. <row>
  332. <entry valign="top" morerows="1"><screen>operator&lt;=, operator&gt;=</screen></entry>
  333. <entry>Defined in terms of the other operators.</entry>
  334. </row>
  335. <row>
  336. <entry></entry>
  337. </row>
  338. </tbody>
  339. </tgroup>
  340. </informaltable>
  341. </para>
  342. </section>