VMS Help
DECdts, utc_mkreltime
*Conan The Librarian
|
Converts a tm structure that expresses relative time to a
relative binary timestamp.
Format
#include <utc.h>
int utc_mkreltime(*utc, *timetm, tns, *inacctm, ins)
utc_t *utc;
const struct tm *timetm;
long tns;
const struct tm *inacctm;
long ins;
Input
timetm
A tm structure that expresses a relative time. On input, tm_wday
and tm_yday are ignored.
tns
Nanoseconds since time component.
inacctm
A tm structure that expresses seconds of inaccuracy. If tm_yday
is negative, the inaccuracy is considered to be infinite. On
input, tm_mday, tm_mon, tm_year, tm_wday, tm_isdst, and tm_zone
are ignored.
ins
Nanoseconds of inaccuracy component.
Output
utc
Resulting relative binary timestamp.
The Make Relative Time routine converts a tm structure that
expresses relative time to a relative binary timestamp.
Additional inputs include nanoseconds since the last second of
time and nanoseconds of inaccuracy.
0 Indicates that the routine executed successfully.
-1 Indicates an invalid time argument or invalid results.
The following example converts a string relative time in the
format (1991-04-01-12:12:12.12I12.12) to a binary timestamp. This
may be part of an input relative timestamp routine, though a real
implementation will include range checking.
utc_t utc;
struct tm tmtime, tminacc;
float tsec, isec;
double tmp;
long tnsec, insec;
int i, tzhour, tzmin, year, mon;
char *string;
/*
* Try to convert the string...
*/
if(sscanf(string, "%d-%d-%d-%d:%d:%eI%e",
&year, &mon, &tmtime.tm_mday, &tmtime.tm_hour,
&tmtime.tm_min, &tsec, &isec) != 7) {
/*
* ERROR...
*/
exit(1);
}
/*
* Fill in the fields...
*/
tmtime.tm_year = year - 1900;
tmtime.tm_mon = --mon;
tmtime.tm_sec = tsec;
tnsec = (modf(tsec, &tmp)*1.0E9);
tminacc.tm_sec = isec;
insec = (modf(isec, &tmp)*1.0E9);
/*
* Convert to a binary timestamp...
*/
utc_mkreltime(&utc, /* Out: Resultant binary timestamp */
&tmtime, /* In: tm struct that represents input */
tnsec, /* In: Nanoseconds from input */
&tminacc, /* In: tm struct that represents inacc */
insec); /* In: Nanoseconds from input */
utc_reltime