<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>

<head>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Microsoft FrontPage 2.0">
<title>Durations</title>
</head>

<body bgcolor="#FFFFFF">

<table border="0" width="100%">
    <tr>
        <td><font size="6"><strong>Durations</strong></font></td>
        <td align="right"><a href="absolute.html"><img
        src="../image/previous.gif" alt="Previous" border="0"
        width="40" height="40"></a><a href="clock.html"><img
        src="../image/next.gif" alt="Next" border="0" width="40"
        height="40"></a></td>
    </tr>
</table>

<hr size="1">

<p align="center"><!--webbot bot="ImageMap" startspan
rectangle=" (144,311) (284, 343)  flatshort/dt_date_time_duration.html"
rectangle=" (148,236) (276, 268)  flatshort/dt_date_time_value.html"
rectangle=" (307,236) (419, 268)  flatshort/dt_time_duration.html"
rectangle=" (8,236) (118, 269)  flatshort/dt_date_duration.html"
rectangle=" (221,161) (317, 192)  flatshort/dt_time_value.html"
rectangle=" (108,161) (205, 192)  flatshort/dt_date_value.html"
rectangle=" (167,87) (259, 119)  flatshort/dt_duration.html"
src="image/duration.gif" border="0" width="428" height="356" --><MAP NAME="FrontPageMap0"><AREA SHAPE="RECT" COORDS="144, 311, 284, 343" HREF="flatshort/dt_date_time_duration.html"><AREA SHAPE="RECT" COORDS="148, 236, 276, 268" HREF="flatshort/dt_date_time_value.html"><AREA SHAPE="RECT" COORDS="307, 236, 419, 268" HREF="flatshort/dt_time_duration.html"><AREA SHAPE="RECT" COORDS="8, 236, 118, 269" HREF="flatshort/dt_date_duration.html"><AREA SHAPE="RECT" COORDS="221, 161, 317, 192" HREF="flatshort/dt_time_value.html"><AREA SHAPE="RECT" COORDS="108, 161, 205, 192" HREF="flatshort/dt_date_value.html"><AREA SHAPE="RECT" COORDS="167, 87, 259, 119" HREF="flatshort/dt_duration.html"></MAP><img src="image/duration.gif" border="0" width="428" height="356" usemap="#FrontPageMap0"><!--webbot
bot="ImageMap" i-checksum="61460" endspan --></p>

<p>A duration is an amount of time between two dates, two times
or two date/times. Durations can therefore be added to an <a
href="absolute.html">absolute time</a> and hence get a new
absolute time shifted on the oriented time axis by the
corresponding amount of time. Although time durations can be
compared using a total order relationship, we will see that this
is not the case for date durations and date/time durations for
which the order relationship is only partial because of the
irregularities in the Gregorian calendar. Therefore class <a
href="flatshort/dt_duration.html"><font color="#008080"><em><tt>DT_DURATION</tt></em></font></a>
is a descendant of <font color="#008080"><em><tt>KL_PART_COMPARABLE</tt></em></font>.
It also inherits from <font color="#008080"><em><tt>HASHABLE</tt></em></font>
in order to allow durations to be used as keys in hash tables.
Durations can be added together or subtracted using the operators
<a href="flatshort/dt_duration.html#infix_plus"><font
color="#008080"><em><strong><tt>infix</tt></strong></em><em><tt> </tt></em><tt>&quot;+&quot;</tt></font></a>,
<a href="flatshort/dt_duration.html#infix_minus"><font
color="#008080"><em><strong><tt>infix</tt></strong></em><em><tt> </tt></em><tt>&quot;-&quot;</tt></font></a>,
<a href="flatshort/dt_duration.html#prefix_plus"><font
color="#008080"><em><strong><tt>prefix</tt></strong></em><em><tt>
</tt></em><tt>&quot;+&quot;</tt></font></a> and <a
href="flatshort/dt_duration.html#prefix_minus"><font
color="#008080"><em><strong><tt>prefix</tt></strong></em><em><tt>
</tt></em><tt>&quot;-&quot;</tt></font></a>. There are three
kinds of durations. Time durations, instances of class <a
href="flatshort/dt_time_duration.html"><font color="#008080"><em><tt>DT_TIME_DURATION</tt></em></font></a>,
represent the amount of time between two <a
href="absolute.html#time">times</a> such as <em>2 hours and 30
minutes</em>. Date durations, instances of class <a
href="flatshort/dt_date_duration.html"><font color="#008080"><em><tt>DT_DATE_DURATION</tt></em></font></a>,
are amounts of time between two <a href="absolute.html#date">dates</a>
such as <em>1 year and 3 months</em>. And date/time durations,
instances of class <a href="flatshort/dt_date_time_duration.html"><font
color="#008080"><em><tt>DT_DATE_TIME_DURATION</tt></em></font></a>,
are amounts of time between two <a href="absolute.html#date_time">date/times</a>
such as <em>5 days and 10 hours</em>.</p>

<h2><a name="time">Time</a> Duration</h2>

<p>Time durations are made up of <a
href="flatshort/dt_time_duration.html#hour"><font color="#008080"><em><tt>hour</tt></em></font></a>,
<a href="flatshort/dt_time_duration.html#minute"><font
color="#008080"><em><tt>minute</tt></em></font></a> and <a
href="flatshort/dt_time_duration.html#second"><font
color="#008080"><em><tt>second</tt></em></font></a>. Contrary to
time objects, these features can have arbitrary values such as <em>36
hours, -6 minutes and 70 seconds</em>. Precision up to the
millisecond is also available thanks to the feature <a
href="flatshort/dt_time_duration.html#millisecond"><font
color="#008080"><em><tt>millisecond</tt></em></font></a>. These
four fields of class <font color="#008080"><em><tt>DT_TIME_DURATION</tt></em></font>
can be set individually or together with the following routines: <a
href="flatshort/dt_time_duration.html#set_hour"><font
color="#008080"><em><tt>set_hour</tt></em></font></a>, <a
href="flatshort/dt_time_duration.html#set_minute"><font
color="#008080"><em><tt>set_minute</tt></em></font></a>, <a
href="flatshort/dt_time_duration.html#set_second"><font
color="#008080"><em><tt>set_second</tt></em></font></a>, <a
href="flatshort/dt_time_duration.html#set_millisecond"><font
color="#008080"><em><tt>set_millisecond</tt></em></font></a>, <a
href="flatshort/dt_time_duration.html#set_hour_minute_second"><font
color="#008080"><em><tt>set_hour_minute_second</tt></em></font></a>
and <a
href="flatshort/dt_time_duration.html#set_precise_hour_minute_second"><font
color="#008080"><em><tt>set_precise_hour_minute_second</tt></em></font></a>.
The <font color="#008080"><em><tt>precise</tt></em></font> prefix
in feature names implies that the <font color="#008080"><em><tt>millisecond</tt></em></font>
field is involved. Two other routines, <a
href="flatshort/dt_time_duration.html#second_count"><font
color="#008080"><em><tt>second_count</tt></em></font></a> and <a
href="flatshort/dt_time_duration.html#millisecond_count"><font
color="#008080"><em><tt>millisecond_count</tt></em></font></a>,
return the total number of seconds and milliseconds making up the
duration.</p>

<p>Although the fields of a time duration can have arbitrary
values, there is one special form called canonical where all
fields have the same sign and where the absolute value of the
number of minutes is between 0 and 59 and absolute value of the
number of seconds is between 0 and 59. One can check whether a
time duration is canonical using the boolean query <a
href="flatshort/dt_time_duration.html#is_canonical"><font
color="#008080"><em><tt>is_canonical</tt></em></font></a>.
Furthermore, given a time duration, there is one and only one
equivalent canonical duration. For example the canonical form of <em>48
hours, -5 minutes and 61 seconds</em> is <em>47 hours, 56 minutes
and 1 second</em>. There are three ways to get a canonical time
duration: either call the setting routine <a
href="flatshort/dt_time_duration.html#set_canonical"><font
color="#008080"><em><tt>set_canonical</tt></em></font></a>, call
the conversion routine <a
href="flatshort/dt_time_duration.html#to_canonical"><font
color="#008080"><em><tt>to_canonical</tt></em></font></a> to get
a new duration object corresponding to the canonical version of
the current duration, or call <a
href="flatshort/dt_time.html#canonical_duration"><font
color="#008080"><em><tt>canonical_duration</tt></em></font></a>
in class <a href="flatshort/dt_time.html"><font color="#008080"><em><tt>DT_TIME</tt></em></font></a>.
For time duration comparison, the canonical form is used. For
example the duration <em>65 seconds</em> and the other duration <em>1
minute and 5 seconds</em> are considered equal, whereas <em>30
minutes</em> is less than <em>-1 hour and 120 minutes</em>
because the canonical form of the latter is <em>1 hour</em>.</p>

<p>Four creation procedures are provided. <a
href="flatshort/dt_time_duration.html#make"><font color="#008080"><em><tt>make</tt></em></font></a>
requires three arguments to set the hour, minute and second,
whereas <a href="flatshort/dt_time_duration.html#make_precise"><font
color="#008080"><em><tt>make_precise</tt></em></font></a> needs
an extra argument to set the millisecond precision. On the other
hand <a href="flatshort/dt_time_duration.html#make_canonical"><font
color="#008080"><em><tt>make_canonical</tt></em></font></a> and <a
href="flatshort/dt_time_duration.html#make_precise_canonical"><font
color="#008080"><em><tt>make_precise_canonical</tt></em></font></a>
create a new canonical time duration based on its total number of
seconds or milliseconds.</p>

<p>It is possible to add or subtract hours, minutes, seconds
and/or milliseconds to a time duration using features <a
href="flatshort/dt_time_duration.html#add_hours"><font
color="#008080"><em><tt>add_hours</tt></em></font></a>, <a
href="flatshort/dt_time_duration.html#add_minutes"><font
color="#008080"><em><tt>add_minutes</tt></em></font></a>, <a
href="flatshort/dt_time_duration.html#add_seconds"><font
color="#008080"><em><tt>add_seconds</tt></em></font></a>, <a
href="flatshort/dt_time_duration.html#add_milliseconds"><font
color="#008080"><em><tt>add_milliseconds</tt></em></font></a>, <a
href="flatshort/dt_time_duration.html#add_hours_minutes_seconds"><font
color="#008080"><em><tt>add_hours_minutes_seconds</tt></em></font></a>
and <a
href="flatshort/dt_time_duration.html#add_precise_hours_minutes_seconds"><font
color="#008080"><em><tt>add_precise_hours_minutes_seconds</tt></em></font></a>
with positive or negative arguments. Fields are added field by
field. For example adding <em>25 minutes</em> to the duration <em>14
hours, 44 minutes and 10 seconds</em> yields <em>14 hours, 69
minutes and 10 seconds</em>. Conversion routines described above
can then be used in order to get a canonical form.</p>

<h2><a name="date">Date</a> Duration</h2>

<p>Date durations are made up of <a
href="flatshort/dt_date_duration.html#year"><font color="#008080"><em><tt>year</tt></em></font></a>,
<a href="flatshort/dt_date_duration.html#month"><font
color="#008080"><em><tt>month</tt></em></font></a> and <a
href="flatshort/dt_date_duration.html#day"><font color="#008080"><em><tt>day</tt></em></font></a>.
Contrary to date objects, these features can have arbitrary
values such as <em>2 years, -18 months and 3 days</em>. These
three fields of class <font color="#008080"><em><tt>DT_DATE_DURATION</tt></em></font>
can be set individually or together with the following routines: <a
href="flatshort/dt_date_duration.html#set_year"><font
color="#008080"><em><tt>set_year</tt></em></font></a>, <a
href="flatshort/dt_date_duration.html#set_month"><font
color="#008080"><em><tt>set_month</tt></em></font></a>, <a
href="flatshort/dt_date_duration.html#set_day"><font
color="#008080"><em><tt>set_day</tt></em></font></a> and <a
href="flatshort/dt_date_duration.html#set_year_month_day"><font
color="#008080"><em><tt>set_year_month_day</tt></em></font></a>.</p>

<p>Because of the irregularities in the Gregorian calendar, the
months in a year don't have the same number of days. For example
there are 31 days in January whereas there are only 30 days in
April and 28 or 29 days in Februay depending on whether the year
is a leap year or not. As a consequence a duration of 1 month is
either made up of 28, 29, 30 or 31 days depending on the date to
which the duration is to be added. For example adding <em>1 month</em>
to the date <em>20 April 2000</em> is equivalent to adding <em>30
days</em> whereas adding <em>1 month</em> to the date <em>5 May
2000</em> is equivalent to adding <em>31 days</em>. Therefore
date durations are not deterministic. One way to address this
problem is to use definite durations. A date duration is said to
be definite when it is expressed only in terms of days, leaving
the year and month parts empty. For example the duration <em>40
days</em> is definite where as <em>2 months and 3 days</em> is
not. One can check whether a date duration is definite or not by
calling the boolean query <a
href="flatshort/dt_date_duration.html#is_definite"><font
color="#008080"><em><tt>is_definite</tt></em></font></a>. There
are three ways to get a definite date duration: either call the
setting routine <a
href="flatshort/dt_date_duration.html#set_definite"><font
color="#008080"><em><tt>set_definite</tt></em></font></a>, call
the conversion routine <a
href="flatshort/dt_date_duration.html#to_definite"><font
color="#008080"><em><tt>to_definite</tt></em></font></a><font
color="#008080"><em><tt> </tt></em></font>to get a new duration
object corresponding to the definite version of the current
duration, or call <a href="flatshort/dt_date.html#duration"><font
color="#008080"><em><tt>duration</tt></em></font></a> in class <a
href="flatshort/dt_date.html"><font color="#008080"><em><tt>DT_DATE</tt></em></font></a>.
Note that the first two routines need a date as argument which is
used as origin in order to make the duration deterministic before
the conversion.</p>

<p>As for time duration, canonical forms are also available for
date duration. A date duration is canonical when its fields have
all the same sign and when the absolute value of the number of
days is the smallest possible one and the absolute value of the number
of months is between 0 and 11. Here again, because of the
irregularities in the Gregorian calendar, the canonical form
depends on the date to which the duration is to be added. For
example the canonical form of the duration <em>34 days</em> when
to be added to the date <em>23 September 2000</em> is <em>1 month
and 4 days</em>, whereas it will only be <em>1 month and 3 days</em>
when to be added to the date <em>12 October 2000</em>. Note that
this might become tricky in some cases. For example the canonical
duration between <em>31 May 2000</em> and <em>30 June 2000</em>
is <em>1 month</em> and not <em>30 days</em>! Indeed, if we
follow the definition of canonical duration, <em>0 day</em> is
smaller than <em>30 days</em> and adding <em>1 month</em> to <em>31
May 2000</em> yields the expected date thanks to the truncation
of the day which occurs in the addition routines of class <font
color="#008080"><em><tt>DT_DATE</tt></em></font>. There are three
ways to get a canonical date duration: either call the setting
routine <a href="flatshort/dt_date_duration.html#set_canonical"><font
color="#008080"><em><tt>set_canonical</tt></em></font></a>, call
the conversion routine <a
href="flatshort/dt_date_duration.html#to_canonical"><font
color="#008080"><em><tt>to_canonical</tt></em></font></a> to get
a new duration object corresponding to the canonical version of
the current duration, or call <a
href="flatshort/dt_date.html#canonical_duration"><font
color="#008080"><em><tt>canonical_duration</tt></em></font></a>
in class <font color="#008080"><em><tt>DT_DATE</tt></em></font>.
Note that for the same reason as for definite durations, the
first two routines need a date as argument.</p>

<p>Two creation procedures are provided. <a
href="flatshort/dt_date_duration.html#make"><font color="#008080"><em><tt>make</tt></em></font></a>
requires three arguments to set the year, month and day. On the
other hand <a
href="flatshort/dt_date_duration.html#make_definite"><font
color="#008080"><em><tt>make_definite</tt></em></font></a> just
needs the number of days since the number of years and months
will be set to zero in order to get a definite date duration.</p>

<p>It is possible to add or subtract years, months and/or days to
a date duration using features <a
href="flatshort/dt_date_duration.html#add_years"><font
color="#008080"><em><tt>add_years</tt></em></font></a>, <a
href="flatshort/dt_date_duration.html#add_months"><font
color="#008080"><em><tt>add_months</tt></em></font></a>, <a
href="flatshort/dt_date_duration.html#add_days"><font
color="#008080"><em><tt>add_days</tt></em></font></a> and <a
href="flatshort/dt_date_duration.html#add_years_months_days"><font
color="#008080"><em><tt>add_years_months_days</tt></em></font></a>
with positive or negative arguments. For example adding <em>8
months</em> to the date duration <em>3 years, 11 months and 23
days</em> yields <em>3 years, 19 months and 23 days</em>.</p>

<p>Since a month is not always equivalent to the same number of
days, the comparison of date durations is a partial order
relationship. For example it is impossible to say whether <em>1
month</em> is less than, equal to or greater than <em>30 days</em>.
It depends on the date that we use as origin for the operations
with these durations. Therefore <font color="#008080"><em><tt>DT_DATE_DURATION</tt></em></font>
is not a descendant of <font color="#008080"><em><tt>COMPARABLE</tt></em></font>
but inherits from <font color="#008080"><em><tt>KL_PART_COMPARABLE</tt></em></font>
instead. The comparison routines are implemented as follows. On
one side we compare the day part of the two date durations. On
the other side we convert the year part into months (<em>1 year</em>
yields <em>12 months</em>), add them to the month part and then
compare the results. If the comparisons on both sides give the
same results, then this is the result of the global comparison
routine, otherwise we return false. For example the duration <em>2
years and 2 days</em> is equal to <em>1 year, 12 months and 2
days</em>; the duration <em>2 months and 5 days</em> is less than
<em>1 year and 10 days</em>. However we cannot say much about the
duration <em>2 months and 1 day</em> and the other duration <em>1
month and 31 days</em>. On one side the day part is smaller, but
on the other side the combination of the month and year parts is
larger. Without the hint of the date to which these durations
will be added we have no choice but return false in all
comparison routines.</p>

<h2><a name="date_time">Date Time</a> Duration</h2>

<p>Date/time durations are a combination of a date duration and a
time duration. They are made up of <a
href="flatshort/dt_date_time_duration.html#year"><font
color="#008080"><em><tt>year</tt></em></font></a>, <a
href="flatshort/dt_date_time_duration.html#month"><font
color="#008080"><em><tt>month</tt></em></font></a>, <a
href="flatshort/dt_date_time_duration.html#day"><font
color="#008080"><em><tt>day</tt></em></font></a>, <a
href="flatshort/dt_date_time_duration.html#hour"><font
color="#008080"><em><tt>hour</tt></em></font></a>, <a
href="flatshort/dt_date_time_duration.html#minute"><font
color="#008080"><em><tt>minute</tt></em></font></a>, <a
href="flatshort/dt_date_time_duration.html#second"><font
color="#008080"><em><tt>second</tt></em></font></a> and <a
href="flatshort/dt_date_time_duration.html#millisecond"><font
color="#008080"><em><tt>millisecond</tt></em></font></a>. Class <a
href="flatshort/dt_date_time_duration.html"><font color="#008080"><em><tt>DT_DATE_TIME_DURATION</tt></em></font></a>
is equipped with the same setting routines as <font
color="#008080"><em><tt>DT_DATE_DURATION</tt></em></font> and <font
color="#008080"><em><tt>DT_TIME_DURATION</tt></em></font>. In
addition to the features inherited from these two classes, one
can also get or set the date duration and the time duration parts
of a date/time duration with routines <a
href="flatshort/dt_date_time_duration.html#date_duration"><font
color="#008080"><em><tt>date_duration</tt></em></font></a>, <a
href="flatshort/dt_date_time_duration.html#time_duration"><font
color="#008080"><em><tt>time_duration</tt></em></font></a>, <a
href="flatshort/dt_date_time_duration.html#set_date_duration"><font
color="#008080"><em><tt>set_date_duration</tt></em></font></a>
and <a
href="flatshort/dt_date_time_duration.html#set_time_duration"><font
color="#008080"><em><tt>set_time_duration</tt></em></font></a>.
It is worthwhile to note that the two routines <a
href="flatshort/dt_date_time_duration.html#second_count"><font
color="#008080"><em><tt>second_count</tt></em></font></a> and <a
href="flatshort/dt_date_time_duration.html#millisecond_count"><font
color="#008080"><em><tt>millisecond_count</tt></em></font></a>,
inherited from <font color="#008080"><em><tt>DT_TIME_DURATION</tt></em></font>,
return the total number of seconds and milliseconds making up
only the time duration part of the date/time duration. The date
duration part is not taken into account in this calculation.</p>

<p>As we already noticed for date duration, date/time durations
are not deterministic because of the irregularities in the
Gregorian calendar. For example adding <em>1 month and 1 hour </em>to
the date <em>20 April 2000 at 10:12:30 </em>is equivalent to
adding <em>30 days and 1 hour </em>whereas adding <em>1 month and
1 hour </em>to the date <em>5 May 2000 and 10:12:30 </em>is
equivalent to adding <em>31 days and 1 hour</em>. One way to
address this problem is to use definite durations. A date/time
duration is said to be definite when it is expressed only in
terms of days, hours, minutes and seconds, leaving the year and
month parts empty. For example the duration <em>40 days and 2
minutes </em>is definite where as <em>2 months, 3 days and 1 hour
</em>is not. One can check whether a date/time duration is
definite or not by calling the boolean query <a
href="flatshort/dt_date_time_duration.html#is_definite"><font
color="#008080"><em><tt>is_definite</tt></em></font></a>. There
are three ways to get a definite date/time duration: either call
the setting routine <a
href="flatshort/dt_date_time_duration.html#set_definite"><font
color="#008080"><em><tt>set_definite</tt></em></font></a>, call
the conversion routine <a
href="flatshort/dt_date_time_duration.html#to_definite"><font
color="#008080"><em><tt>to_definite</tt></em></font></a><font
color="#008080"><em><tt> </tt></em></font>to get a new duration
object corresponding to the definite version of the current
duration, or call <a href="flatshort/dt_date_time.html#duration"><font
color="#008080"><em><tt>duration</tt></em></font></a> in class <a
href="flatshort/dt_date_time.html"><font color="#008080"><em><tt>DT_DATE_TIME</tt></em></font></a>.
Note that the first two routines need a date/time as argument
which is used as origin in order to make the duration
deterministic before the conversion.</p>

<p>Although the fields of a date/time duration can have arbitrary
values, there is one special form called canonical where all
fields have the same sign and where the absolute value of the
number of days is the smallest possible one, the absolute value of the
number of months is between 0 and 11, the absolute value of the
number of hours is between 0 and 23, the absolute value of the
number of minutes is between 0 and 59 and absolute value of the
number of seconds is between 0 and 59. Here again, because of the
irregularities in the Gregorian calendar, the canonical form
depends on the date/time to which the duration is to be added.
For example the canonical form of the duration <em>34 days and 72
minutes </em>when to be added to the date/time <em>23 September
2000 at 14:05:00 </em>is <em>1 month, 4 days, 1 hour and 2
minutes</em>, whereas it will only be <em>1 month, 3 days, 1 hour
and 2 minutes </em>when to be added to the date <em>12 October
2000 at 14:05:00</em>. Note that this might become tricky in some
cases. For example the canonical duration between <em>31 May 2000
at 17:45:00 </em>and <em>30 June 2000 at 18:00:00 </em>is <em>1
month and 15 minutes </em>and not <em>30 days and 15 minutes</em>!
Indeed, if we follow the definition of canonical duration, <em>0
day</em> is smaller than <em>30 days</em> and adding <em>1 month
and 15 minutes </em>to <em>31 May 2000 at 17:45:00 </em>yields
the expected date thanks to the truncation of the day which
occurs in the addition routines of class <font color="#008080"><em><tt>DT_DATE_TIME</tt></em></font>.
There are three ways to get a canonical date/time duration:
either call the setting routine <a
href="flatshort/dt_date_time_duration.html#set_canonical"><font
color="#008080"><em><tt>set_canonical</tt></em></font></a>, call
the conversion routine <a
href="flatshort/dt_date_time_duration.html#to_canonical"><font
color="#008080"><em><tt>to_canonical</tt></em></font></a> to get
a new duration object corresponding to the canonical version of
the current duration, or call <a
href="flatshort/dt_date_time.html#canonical_duration"><font
color="#008080"><em><tt>canonical_duration</tt></em></font></a>
in class <font color="#008080"><em><tt>DT_DATE_TIME</tt></em></font>.
Note that for the same reason as for definite durations, the
first two routines need a date/time as argument. One can check
whether a date/time duration is canonical using the boolean query
<a href="flatshort/dt_date_time_duration.html#is_canonical"><font
color="#008080"><em><tt>is_canonical</tt></em></font></a>. There
is also a way to check whether the time duration part of a
date/time duration is canonical with the boolean query <a
href="flatshort/dt_date_time_duration.html#is_time_canonical"><font
color="#008080"><em><tt>is_time_canonical</tt></em></font></a>.
This will be true when all fields of the time duration part have
the same sign as the day part and when the absolute value of the
number of hours is between 0 and 23, the absolute value of the
number of minutes is between 0 and 59 and absolute value of the
number of seconds is between 0 and 59. Because the year and month
parts are not involved here, there is no need to provide a
date/time as origin when calling <a
href="flatshort/dt_date_time_duration.html#set_time_canonical"><font
color="#008080"><em><tt>set_time_canonical</tt></em></font></a>
and <a
href="flatshort/dt_date_time_duration.html#to_time_canonical"><font
color="#008080"><em><tt>to_time_canonical</tt></em></font></a>
which are the counterparts of <font color="#008080"><em><tt>set_canonical</tt></em></font>
and <font color="#008080"><em><tt>to_canonical</tt></em></font>.</p>

<p>Eight creation procedures are provided. <a
href="flatshort/dt_date_time_duration.html#make"><font
color="#008080"><em><tt>make</tt></em></font></a> requires six
arguments to set the year, month, day, hour, minute and second,
whereas <a
href="flatshort/dt_date_time_duration.html#make_precise"><font
color="#008080"><em><tt>make_precise</tt></em></font></a> needs
an extra argument to set the millisecond precision. On the other
hand <a
href="flatshort/dt_date_time_duration.html#make_from_date_time_duration"><font
color="#008080"><em><tt>make_from_date_time_duration</tt></em></font></a>
and <a
href="flatshort/dt_date_time_duration.html#make_from_date_duration"><font
color="#008080"><em><tt>make_from_date_duration</tt></em></font></a>
create a new date/time duration based on its date duration and
time duration parts. <a
href="flatshort/dt_date_time_duration.html#make_definite"><font
color="#008080"><em><tt>make_definite</tt></em></font></a> just
needs the number of days along with the number of hours, minutes
and seconds since the number of years and months will be set to
zero in order to get a definite date/time duration. The creation
procedure <a
href="flatshort/dt_date_time_duration.html#make_precise_definite"><font
color="#008080"><em><tt>make_precise_definite</tt></em></font></a><font
color="#008080"><em><tt> </tt></em></font>is similar to <font
color="#008080"><em><tt>make_definite </tt></em></font>except
that it needs an extra argument to set the millisecond precision.
Finally <a
href="flatshort/dt_date_time_duration.html#make_canonical_definite"><font
color="#008080"><em><tt>make_canonical_definite</tt></em></font></a>
and <a
href="flatshort/dt_date_time_duration.html#make_precise_canonical_definite"><font
color="#008080"><em><tt>make_precise_canonical_definite</tt></em></font></a>
create a new definite date/time duration based on its total
number of seconds or milliseconds. The time duration part of the
resulting date/time duration will be canonical as defined by <font
color="#008080"><em><tt>is_time_canonical </tt></em></font>above.</p>

<p>It is possible to add or subtract years, months, days, hours,
minutes, seconds and/or milliseconds to a date/time duration
using features <a
href="flatshort/dt_date_time_duration.html#add_years"><font
color="#008080"><em><tt>add_years</tt></em></font></a>, <a
href="flatshort/dt_date_time_duration.html#add_months"><font
color="#008080"><em><tt>add_months</tt></em></font></a>, <a
href="flatshort/dt_date_time_duration.html#add_days"><font
color="#008080"><em><tt>add_days</tt></em></font></a>, <a
href="flatshort/dt_date_time_duration.html#add_years_months_days"><font
color="#008080"><em><tt>add_years_months_days</tt></em></font></a>,
<a href="flatshort/dt_date_time_duration.html#add_hours"><font
color="#008080"><em><tt>add_hours</tt></em></font></a>, <a
href="flatshort/dt_date_time_duration.html#add_minutes"><font
color="#008080"><em><tt>add_minutes</tt></em></font></a>, <a
href="flatshort/dt_date_time_duration.html#add_seconds"><font
color="#008080"><em><tt>add_seconds</tt></em></font></a>, <a
href="flatshort/dt_date_time_duration.html#add_milliseconds"><font
color="#008080"><em><tt>add_milliseconds</tt></em></font></a>, <a
href="flatshort/dt_date_time_duration.html#add_hours_minutes_seconds"><font
color="#008080"><em><tt>add_hours_minutes_seconds</tt></em></font></a>
and <a
href="flatshort/dt_date_time_duration.html#add_precise_hours_minutes_seconds"><font
color="#008080"><em><tt>add_precise_hours_minutes_seconds</tt></em></font></a>
with positive or negative arguments. For example adding <em>8
months and 2 hours </em>to the date/time duration <em>3 years, 11
months, 23 days, 23 hours and 12 minutes </em>yields <em>3 years,
19 months, 23 days, 25 hours and 12 minutes</em>.</p>

<p>Since a month is not always equivalent to the same number of
days, the comparison of date/time durations is a partial order
relationship. For example it is impossible to say whether <em>1
month and 2 hours </em>is less than, equal to or greater than <em>30
days and 2 hours</em>. It depends on the date/time that we use as
origin for the operations with these durations. Therefore <font
color="#008080"><em><tt>DT_DATE_TIME_DURATION</tt></em></font> is
not a descendant of <font color="#008080"><em><tt>COMPARABLE</tt></em></font>
but inherits from <font color="#008080"><em><tt>KL_PART_COMPARABLE</tt></em></font>
instead. The comparison routines are implemented as follows. On
one side we compare the day and time duration parts of the two
date/time durations using their time-canonical forms. On the
other side we convert the year part into months (<em>1 year</em>
yields <em>12 months</em>), add them to the month part and then
compare the results. If the comparisons on both sides give the
same results, then this is the result of the global comparison
routine, otherwise we return false. For example the duration <em>2
years, 2 days and 34 minutes </em>is equal to <em>1 year, 12
months, 1 day, 24 hours and 34 minutes</em>; the duration <em>2
months, 5 days and 2 hours </em>is less than <em>1 year, 10 days
and 1 hour</em>. However we cannot say much about the duration <em>2
months, 1 day and 2 hours </em>and the other duration <em>1
month, 31 days and 2 hours</em>. On one side the combination of
day and time duration parts is smaller, but on the other side the
combination of the month and year parts is larger. Without the
hint of the date/time to which these durations will be added we
have no choice but return false in all comparison routines.</p>

<hr size="1">

<table border="0" width="100%">
    <tr>
        <td><address>
            <font size="2"><b>Copyright © 2000-2005</b></font><font
            size="1"><b>, </b></font><font size="2"><strong>Eric
            Bezault</strong></font><strong> </strong><font
            size="2"><br>
            <strong>mailto:</strong></font><a
            href="mailto:ericb@gobosoft.com"><font size="2">ericb@gobosoft.com</font></a><font
            size="2"><br>
            <strong>http:</strong></font><a
            href="http://www.gobosoft.com"><font size="2">//www.gobosoft.com</font></a><font
            size="2"><br>
            <strong>Last Updated:</strong> 21 February 2005</font><br>
            <!--webbot bot="PurpleText"
            preview="
$Date$ 
$Revision$"
            --> 
        </address>
        </td>
        <td align="right" valign="top"><a
        href="http://www.gobosoft.com"><img
        src="../image/home.gif" alt="Home" border="0" width="40"
        height="40"></a><a href="index.html"><img
        src="../image/toc.gif" alt="Toc" border="0" width="40"
        height="40"></a><a href="absolute.html"><img
        src="../image/previous.gif" alt="Previous" border="0"
        width="40" height="40"></a><a href="clock.html"><img
        src="../image/next.gif" alt="Next" border="0" width="40"
        height="40"></a></td>
    </tr>
</table>
</body>
</html>
