mirror of
https://github.com/boostorg/date_time.git
synced 2026-01-28 19:12:17 +00:00
121 lines
4.4 KiB
HTML
121 lines
4.4 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
|
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
|
|
<title>Date-Time Concepts - Calculation</title>
|
|
<link href="doxygen.css" rel="stylesheet" type="text/css">
|
|
</head>
|
|
|
|
<body>
|
|
<a href="../../../index.htm">
|
|
<img align="left" src="../../../c++boost.gif" alt="C++ Boost">
|
|
</a>
|
|
|
|
<h1>Date-Time Concepts - Calculation</h1>
|
|
<p> <p>
|
|
<hr>
|
|
<a href="index.html">Overall Index</a> --
|
|
<a href="gregorian.html">Gregorian Index</a> --
|
|
<a href="posix_time.html">Posix Time Index</a>
|
|
<p>
|
|
<a href="#timepoints">Timepoints</a> --
|
|
<a href="#durations">Durations</a> --
|
|
<a href="#intervals">Intervals (Periods)</a> --
|
|
<a href="#special">Special Value Handling</a>
|
|
<p>
|
|
|
|
<h2><a name="timepoints">Timepoints</a></h2>
|
|
|
|
<p>
|
|
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:
|
|
|
|
<PRE>
|
|
Timepoint + Duration --> Timepoint
|
|
Timepoint - Duration --> Timepoint
|
|
Timepoint - Timepoint --> Duration
|
|
</PRE>
|
|
|
|
Unlike regular numeric types, the following operations are undefined:
|
|
<PRE>
|
|
Duration + Timepoint --> Undefined
|
|
Duration - Timepoint --> Undefined
|
|
Timepoint + Timepoint --> Undefined
|
|
</PRE>
|
|
<p>
|
|
<h2><a name="durations">Durations</a></h2>
|
|
<p>
|
|
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:
|
|
<PRE>
|
|
Duration + Duration --> Duration
|
|
Duration - Duration --> Duration
|
|
|
|
Duration * Integer --> Duration
|
|
Integer * Duration --> Duration
|
|
Duration / Integer --> Duration (Integer Division rules)
|
|
|
|
</PRE>
|
|
|
|
|
|
<p>
|
|
<h2><a name="intervals">Intervals (Periods)</a></h2>
|
|
<p>
|
|
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:
|
|
|
|
<PRE>
|
|
Timeperiod intersection Timeperiod --> Timeperiod (null interval if no intersection)
|
|
Timeperiod merge Timeperiod --> Timeperiod (null interval if no intersection)
|
|
Timeperiod shift Duration --> Timeperiod (shift start and end by duration amount)
|
|
</PRE>
|
|
|
|
In addition, periods support various queries that calculate boolean results. The first set is caluculations with other time periods:
|
|
<PRE>
|
|
Timeperiod == Timeperiod --> bool
|
|
Timeperiod < Timeperiod --> bool (true if lhs.last <= rhs.begin)
|
|
Timeperiod intersects Timeperiod --> bool
|
|
Timeperiod contains Timeperiod --> bool
|
|
Timeperiod is_adjacent Timeperiod --> bool
|
|
</PRE>
|
|
|
|
The following calculations are performed versus the Timepoint.
|
|
<PRE>
|
|
Timeperiod contains Timepoint --> bool
|
|
Timeperiod is_before Timepoint --> bool
|
|
Timeperiod is_after Timepoint --> bool
|
|
</PRE>
|
|
|
|
<p>
|
|
<h2><a name="special">Special Value Handling</a></h2>
|
|
|
|
<p> 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.
|
|
<PRE>
|
|
Timepoint(NADT) + Duration --> Timepoint(NADT)
|
|
Timepoint(∞) + Duration --> Timepoint(∞)
|
|
Timepoint + Duration(∞) --> Timepoint(∞)
|
|
Timepoint - Duration(∞) --> Timepoint(-∞)
|
|
</PRE>
|
|
<p>When performing operations on both positive and negative infinities, the library will produce results consistent with the following.
|
|
<PRE>
|
|
Timepoint(+∞) + Duration(-∞) --> NADT
|
|
Duration(+∞) + Duration(-∞) --> NADT
|
|
Duration(±∞) * Zero --> NADT
|
|
|
|
Duration(∞) * Integer(Not Zero) --> Duration(∞)
|
|
Duration(+∞) * -Integer --> Duration(-∞)
|
|
Duration(∞) / Integer --> Duration(∞)
|
|
|
|
</PRE>
|
|
|
|
|
|
<hr>
|
|
<address><small>
|
|
<!-- hhmts start -->
|
|
Last modified: Sat Aug 9 09:42:19 MST 2003
|
|
<!-- hhmts end -->
|
|
by <a href="mailto:jeff@crystalclearsoftware.com">Jeff Garland</a> © 2000-2002
|
|
</small></address>
|
|
</body>
|
|
</html>
|
|
|
|
|