HELPLIB.HLB  —  DECdts  utc_mkanytime
    Converts a tm structure and TDF (expressing the time in an
    arbitrary time zone) to a binary timestamp.

    Format

      #include <utc.h>

      int utc_mkanytime(*utc, *timetm, tns, *inacctm, ins, tdf)

         utc_t *utc;
         const struct tm *timetm;
         long tns;
         const struct tm *inacctm;
         long ins;
         long tdf;

1  –  Parameters

    Input

 timetm

    A tm structure that expresses the local time; tm_wday and tm_yday
    are ignored on input.

 tns

    Nanoseconds since time component.

 inacctm

    A tm structure that expresses days, hours, minutes, and seconds
    of inaccuracy. If tm_yday is negative, the inaccuracy is
    considered to be infinite; tm_mday, tm_mon, tm_wday, tm_isdst,
    tm_gmtoff, and tm_zone are ignored on input.

 ins

    Nanoseconds of inaccuracy component.

 tdf

    Time differential factor to use in conversion.

    Output

 utc

    Resulting binary timestamp.

2  –  Description

    The Make Any Time routine converts a tm structure and TDF
    (expressing the time in an arbitrary time zone) to a binary
    timestamp. Required inputs include nanoseconds since time and
    nanoseconds of inaccuracy.

3  –  Returns

     0   Indicates that the routine executed successfully.
    -1   Indicates an invalid time argument or invalid results.

4  –  Example

    The following example converts a string ISO format time in an
    arbitrary time zone to a binary timestamp. This may be part of
    an input timestamp routine, although a real implementation will
    include range checking.

    utc_t       utc;
    struct tm   tmtime, tminacc;
    float       tsec, isec;
    double      tmp;
    long        tnsec, insec;
    int         i, offset, tzhour, tzmin, year, mon;
    char        *string;

    /*  Try to convert the string...                               */

    if(sscanf(string, "%d-%d-%d-%d:%d:%e+%d:%dI%e",
              &year, &mon, &tmtime.tm_mday, &tmtime.tm_hour,
              &tmtime.tm_min, &tsec, &tzhour, &tzmin, &isec) != 9) {

    /*  Try again with a negative TDF...                           */

    if (sscanf(string, "%d-%d-%d-%d:%d:%e-%d:%dI%e",
               &year, &mon, &tmtime.tm_mday, &tmtime.tm_hour,
               &tmtime.tm_min, &tsec, &tzhour, &tzmin, &isec) != 9) {

    /*  ERROR                                                      */

            exit(1);
        }

    /*  TDF is negative                                            */

        tzhour = -tzhour;
        tzmin = -tzmin;

    }

    /*  Fill in the fields...                                      */

    tmtime.tm_year = year - 1900;
    tmtime.tm_mon = --mon;
    tmtime.tm_sec = tsec;
    tnsec = (modf(tsec, &tmp)*1.0E9);
    offset = tzhour*3600 + tzmin*60;
    tminacc.tm_sec = isec;
    insec = (modf(isec, &tmp)*1.0E9);

    /* Convert to a binary timestamp...                             */

    utc_mkanytime(&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          */
                  offset);  /* In:  TDF from input                  */

5  –  Related Functions

    utc_anytime, utc_anyzone
Close Help