|
|
|
|
|
|
|
8.4.2.1 iso_date_time_to_double () |
|
|
|
|
|
|
|
|
The routine iso_date_time_to_double () (Listing 8.5) converts a date and time, combined as an ISO_DATE_TIME structure, to a type double. |
|
|
|
|
| Listing 8.4 | |
|
|
|
|
#include <limits.h>
#include "scdtl_2.h"
#include "iso_2.h"
struct ISO_DURATION iso_double_to_duration (double diff)
{
double jd1, JD0, frac;
double h, m, s;
long jdl, yl, ml, dl, rem;
long hl, mnl, sl, max_int;
struct ISO_DURATION dur;
jd1 = diff;
if (jd1 < 0.0)
jd1 = -jd1;
jdl = (long) jd1;
JD0 = (double) jdl;
frac = jd1 - JD0;
h = frac * 24.0;
hl = (long) h;
frac = h - ((double) hl);
m = frac * 60.0;
mnl = (long) m;
frac = m - ((double) mnl);
s = frac * 60.0 + 0.5;
sl = (long) s;
dur.time.hours = (int) hl;
dur.time.minutes = (int) mnl;
dur.time.seconds = (int) sl;
if (dur.time.seconds == 60)
{
dur.time.seconds = 0;
dur.time.minutes++;
}
if (dur.time.minutes == 60)
{
dur.time.minutes = 0;
dur.time.hours++;
}
yl = jdl / 360L;
max_int = (long) INT_MAX;
if (yl > max_int)
yl = max_int;
|
|
|
|
|
|
|
|