Durations |

A duration is an amount of time between two dates, two times
or two date/times. Durations can therefore be added to an absolute time 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 * DT_DURATION*
is a descendant of

Time durations are made up of * hour*,

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 * is_canonical*.
Furthermore, given a time duration, there is one and only one
equivalent canonical duration. For example the canonical form of

Four creation procedures are provided. * make*
requires three arguments to set the hour, minute and second,
whereas

It is possible to add or subtract hours, minutes, seconds
and/or milliseconds to a time duration using features * add_hours*,

Date durations are made up of * year*,

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 *1 month*
to the date *20 April 2000* is equivalent to adding *30
days* whereas adding *1 month* to the date *5 May
2000* is equivalent to adding *31 days*. 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 *40
days* is definite where as *2 months and 3 days* is
not. One can check whether a date duration is definite or not by
calling the boolean query * is_definite*. There
are three ways to get a definite date duration: either call the
setting routine

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 *34 days* when
to be added to the date *23 September 2000* is *1 month
and 4 days*, whereas it will only be *1 month and 3 days*
when to be added to the date *12 October 2000*. Note that
this might become tricky in some cases. For example the canonical
duration between *31 May 2000* and *30 June 2000*
is *1 month* and not *30 days*! Indeed, if we
follow the definition of canonical duration, *0 day* is
smaller than *30 days* and adding *1 month* to *31
May 2000* yields the expected date thanks to the truncation
of the day which occurs in the addition routines of class * DT_DATE*. There are three
ways to get a canonical date duration: either call the setting
routine

Two creation procedures are provided. * make*
requires three arguments to set the year, month and day. On the
other hand

It is possible to add or subtract years, months and/or days to
a date duration using features * add_years*,

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 *1
month* is less than, equal to or greater than *30 days*.
It depends on the date that we use as origin for the operations
with these durations. Therefore * DT_DATE_DURATION*
is not a descendant of

Date/time durations are a combination of a date duration and a
time duration. They are made up of * year*,

As we already noticed for date duration, date/time durations
are not deterministic because of the irregularities in the
Gregorian calendar. For example adding *1 month and 1 hour *to
the date *20 April 2000 at 10:12:30 *is equivalent to
adding *30 days and 1 hour *whereas adding *1 month and
1 hour *to the date *5 May 2000 and 10:12:30 *is
equivalent to adding *31 days and 1 hour*. 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 *40 days and 2
minutes *is definite where as *2 months, 3 days and 1 hour
*is not. One can check whether a date/time duration is
definite or not by calling the boolean query * is_definite*. There
are three ways to get a definite date/time duration: either call
the setting routine

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 *34 days and 72
minutes *when to be added to the date/time *23 September
2000 at 14:05:00 *is *1 month, 4 days, 1 hour and 2
minutes*, whereas it will only be *1 month, 3 days, 1 hour
and 2 minutes *when to be added to the date *12 October
2000 at 14:05:00*. Note that this might become tricky in some
cases. For example the canonical duration between *31 May 2000
at 17:45:00 *and *30 June 2000 at 18:00:00 *is *1
month and 15 minutes *and not *30 days and 15 minutes*!
Indeed, if we follow the definition of canonical duration, *0
day* is smaller than *30 days* and adding *1 month
and 15 minutes *to *31 May 2000 at 17:45:00 *yields
the expected date thanks to the truncation of the day which
occurs in the addition routines of class * DT_DATE_TIME*.
There are three ways to get a canonical date/time duration:
either call the setting routine

Eight creation procedures are provided. * make* requires six
arguments to set the year, month, day, hour, minute and second,
whereas

It is possible to add or subtract years, months, days, hours,
minutes, seconds and/or milliseconds to a date/time duration
using features * add_years*,

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 *1
month and 2 hours *is less than, equal to or greater than *30
days and 2 hours*. It depends on the date/time that we use as
origin for the operations with these durations. Therefore * DT_DATE_TIME_DURATION* is
not a descendant of

Copyright © 2000-2016, Eric
Bezault mailto:ericb@gobosoft.comhttp://www.gobosoft.comLast Updated: 27 December 2016 |