|
|
|
|
|
|
|
8.4.3.1 iso_begin_and_duration_to_period () |
|
|
|
|
|
|
|
|
This routine (Listing 8.7) builds an ISO_PERIOD structure, using the begin date/time expressed as an ISO_DATE_TIME structure, and the duration, expressed as an ISO_DURATION structure. The end date/time is calculated from the begin date/time and duration and inserted into the ISO_PERIOD structure. |
|
|
|
|
| Listing 8.7 | |
|
|
|
|
OUTPUTS:
1. Returned by routine, an ISO_PERIOD structure containing the
begin date/time, the duration and the end date/time calculated
as a consequence of the other two inputs.
NOTES:
1. If the any item in the duration is negative, the sign of the item
is inverted, so that the calculated end date/time falls after, rather
than before, the begin date/time. No other validation is performed,
and no warning is issued in this case.
*/
#include "scdtl_2.h"
#include "iso_2.h"
struct ISO_PERIOD iso_begin_and_duration_to_period
(struct ISO_DATE_TIME *begin, struct ISO_DURATION *duration)
{
double jdb, jde, jdd;
struct ISO_PERIOD p;
p.begin = *begin;
jdb = iso_date_time_to_double (&(p.begin));
p.duration = *duration;
if (p.duration.date.year < 0)
p.duration.date.year = -p.duration.date.year;
if (p.duration.date.month < 0)
p.duration.date.month = -p.duration.date.month;
if (p.duration.date.day < 0)
p.duration.date.day = -p.duration.date.day;
if (p.duration.time.hours < 0)
p.duration.time.hours = -p.duration.time.hours;
if (p.duration.time.minutes < 0)
p.duration.time.minutes = -p.duration.time.minutes;
if (p.duration.time.seconds < 0)
p.duration.time.seconds = -p.duration.time.seconds;
jdd = iso_duration_to_double (&(p.duration));
if (jdd < 0.0)
jdd = -jdd;
jde = jdb + jdd;
p.end = iso_double_to_date_time (jde);
return (p):
}
|
|
|
|
|
|
|
|