| iMatix home page
| << | < | > | >>
SFL Logo SFL
Version 1.91

 

decode_mime_time

#include "sflmime.h"
Bool
decode_mime_time (const char *mime_string, long *date, long *time)

Synopsis

Takes a MIME date and time string in various formats and converts to a date and time (both long values). Returns TRUE if it could convert the date and time okay, else returns FALSE. Accepts these formats:
Mon Jan 12 12:05:01 1995 ctime format
Monday, 12- Jan-95 12:05:01 GMT RFC 850
Mon, 12 Jan 1995 12:05:01 GMT RFC 1123

Source Code - (sflmime.c)

{
    int
        cent  = 0,
        year  = 0,
        month = 0,
        day   = 0,
        hour  = 0,
        min   = 0,
        sec   = 0;
    static char
        month_name [20],
        buffer     [50],
        *p_char;

    ASSERT (mime_string);
    ASSERT (date);
    ASSERT (time);

    /*  Whatever format we're looking at, it will start with weekday.        */
    /*  Skip to first space.                                                 */
    if (!(p_char = strchr (mime_string, ' ')))
        return FALSE;
    else
        while (isspace (*p_char))
            ++p_char;

    if (isalpha (*p_char))
      {
        /*  ctime                                                            */
        sscanf (p_char, "%s %d %d:%d:%d %d",
                month_name, &day, &hour, &min, &sec, &year);
        cent = (int) year / 100;
        year -= cent * 100;
      }
    else
    if (p_char [2] == '-')
      {
        /*  RFC 850                                                          */
        sscanf (p_char, "%s %d:%d:%d",
                buffer, &hour, &min, &sec);
        buffer [2] = '\0';
        day        = atoi (buffer);
        buffer [6] = '\0';
        strcpy (month_name, &buffer [3]);
        year = atoi (&buffer [7]);
        /*  Prevent wraparound from ambiguity                                */
        if (year < 70)
            cent = 20;
         else
            cent = 19;
      }
    else
      {
        /*  RFC 1123                                                         */
        sscanf (p_char, "%d %s %d %d:%d:%d",
                &day, month_name, &year, &hour, &min, &sec);
        cent = (int) year / 100;
        year -= cent * 100;
      }
    month = find_month (month_name);
    *date = MAKE_DATE (cent, year, month, day);
    *time = MAKE_TIME (hour, min,  sec,   0  );

    return (TRUE);
}

| << | < | > | >> iMatix Copyright © 1996-98 iMatix