Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/date_time/xmldoc/calculations.xml @ 12

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

added boost

File size: 4.6 KB
Line 
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
5<!-- Copyright (c) 2001-2004 CrystalClear Software, Inc.
6     Subject to the Boost Software License, Version 1.0.
7     (See accompanying file LICENSE-1.0 or  http://www.boost.org/LICENSE-1.0)
8-->
9
10<section id="date_time.calculations">
11  <title>Calculations</title>
12
13  <para>
14    <link linkend="timepoints">Timepoints</link> --
15    <link linkend="durations">Durations</link> --
16    <link linkend="intervals">Intervals (Periods)</link> --
17    <link linkend="special_value_handling">Special Value Handling</link>
18  </para>
19  <anchor id="timepoints" />
20  <bridgehead renderas="sect3">Timepoints</bridgehead>
21  <para>
22    This section describes some of basic arithmetic rules that can be performed with timepoints. In general, Timepoints support basic arithmetic in conjunction with Durations as follows:
23    <programlisting>
24      Timepoint + Duration  --> Timepoint
25      Timepoint - Duration  --> Timepoint
26      Timepoint - Timepoint --> Duration
27    </programlisting>
28    Unlike regular numeric types, the following operations are undefined:
29    <programlisting>
30      Duration + Timepoint  --> Undefined
31      Duration - Timepoint  --> Undefined
32      Timepoint + Timepoint --> Undefined
33    </programlisting>
34  </para>
35  <anchor id="durations" />
36  <bridgehead renderas="sect3">Durations</bridgehead>
37  <para>
38    Durations represent a length of time and can have positive and negative values. It is frequently useful to be able to perform calculations with other durations and with simple integral values. The following describes these calculations:
39    <programlisting>
40      Duration + Duration  --> Duration
41      Duration - Duration  --> Duration
42     
43      Duration * Integer   --> Duration
44      Integer  * Duration  --> Duration
45      Duration / Integer   --> Duration  (Integer Division rules)
46    </programlisting>
47  </para>
48  <anchor id="intervals" />
49  <bridgehead renderas="sect3">Intervals (Periods)</bridgehead>
50  <para>
51    Interval logic is extremely useful for simplifying many 'calculations' for dates and times. The following describes the operations provided by periods which are based on half-open range. The following operations calculate new time periods based on two input time periods:
52    <programlisting>
53Timeperiod intersection Timeperiod --> Timeperiod
54  (null interval if no intersection)
55Timeperiod merge Timeperiod        --> Timeperiod
56  (null interval if no intersection)
57Timeperiod shift Duration          --> Timeperiod
58  (shift start and end by duration amount)
59    </programlisting>
60    In addition, periods support various queries that calculate boolean results. The first set is caluculations with other time periods:
61    <programlisting>
62  Timeperiod == Timeperiod           --> bool
63  Timeperiod &lt; Timeperiod            --> bool (true if lhs.last &lt;= rhs.begin)
64  Timeperiod intersects Timeperiod   --> bool
65  Timeperiod contains Timeperiod     --> bool
66  Timeperiod is_adjacent Timeperiod  --> bool
67    </programlisting>
68    The following calculations are performed versus the Timepoint.
69    <programlisting>
70  Timeperiod contains Timepoint      --> bool
71  Timeperiod is_before Timepoint     --> bool
72  Timeperiod is_after Timepoint      --> bool
73    </programlisting>
74  </para>
75  <anchor id="special_value_handling" />
76  <bridgehead renderas="sect3">Special Value Handling</bridgehead>
77  <para>
78    For many temporal problems it is useful for Duration and Timepoint types to support special values such as Not A Date Time (NADT) and infinity. In general special values such as Not A Date Time (NADT) and infinity should follow rules like floating point values. Note that it should be possible to configure NADT based systems to throw an exception instead of result in NADT.
79    <programlisting>
80  Timepoint(NADT) + Duration --> Timepoint(NADT)
81  Timepoint(&#8734;) + Duration    --> Timepoint(&#8734;)
82  Timepoint + Duration(&#8734;)    --> Timepoint(&#8734;)
83  Timepoint - Duration(&#8734;)    --> Timepoint(-&#8734;)
84    </programlisting>
85    When performing operations on both positive and negative infinities, the library will produce results consistent with the following.
86    <programlisting>
87  Timepoint(+&#8734;) + Duration(-&#8734;) --> NADT
88  Duration(+&#8734;) + Duration(-&#8734;)  --> NADT
89  Duration(&#177;&#8734;) * Zero          --> NADT
90 
91  Duration(&#8734;) * Integer(Not Zero) --> Duration(&#8734;)
92  Duration(+&#8734;) * -Integer         --> Duration(-&#8734;)
93  Duration(&#8734;) / Integer           --> Duration(&#8734;)
94    </programlisting>
95  </para>
96</section>
Note: See TracBrowser for help on using the repository browser.