< previous page page_212 next page >

Page 212
(continued)
Listing 8.8
#include "scdtl_2.h"
#include "iso_2.h"


struct ISO_PERIOD iso_begin_and_end_to_period (struct ISO_DATE_TIME *begin,
                                               struct ISO_DATE_TIME *end)
{
   double jdb, jde, jdd;
   struct ISO_PERIOD p;


   p.begin = *begin;
   p.end = *end;
   jdb = iso_date_time_to_double (&(p.begin));
   jde = iso_date_time_to_double (&(p.end));
   jdd = jde - jdb;
   if (jdd < 0.0)
      {
      jdd = -jdd;
      p.begin = *end;
      p.end = *begin;
      }
   p.duration = iso_double_to_duration (jdd);


   return (p);
}

Listing 8.9 iso_duration_and_end_to_period ()
/* ide2per.c
   +-------------------------------------------+
   |   Copyright (C) 1995 by Lance W. Latham.  |
   |         All rights reserved.              |
   +-------------------------------------------+


   Routine builds an ISO_PERIOD structure, using the duration, expressed as an
   ISO_DURATION structure, and the end date/time, expressed as an ISO_DATE_TIME
   structure. The begin date/time is calculated from the duration and the end
   date/time, and inserted into the ISO_PERIOD structure.


   INPUTS:
   1. duration, a pointer to an ISO_DURATION structure containing the
      'duration' elapsed time for an ISO_PERIOD structure.


   2. end, a pointer to an ISO_DATE_TIME structure containing the
      'end' date/time for an ISO_PERIOD structure.


   OUTPUTS:
   1. Returned by routine, an ISO_PERIOD structure containing the
      begin date/time calculated as a consequence of the other two
      inputs, the duration and the end date/time.
   NOTES:
   1. If an item in the duration is negative, the sign of the item is
      inverted, so that the calculated begin date/time falls before,
      rather than after, the end date/time. No other validation is
      performed, and no warning is issued in this case.
*/

 
< previous page page_212 next page >