/sys$common/syshlp/HELPLIB.HLB  —  DECdts  utc_mkreltime, Example
    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          */
Close Help