HELPLIB.HLB  —  DECdts  utc_mkanytime, 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                  */
Close Help