|
| iMatix home page | << | < | > | >> |
SFLVersion 2.10 |
#include "sflmime.h" Bool decode_mime_time (const char *mime_string, long *date, long *time)
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 |
| Monday, 12-Jan-1995 12:05:01 GMT | RFC 850 iMatix extension |
| Mon, 12 Jan 1995 12:05:01 GMT | RFC 1123 |
{
int
cent = 0,
year = 0,
month = 0,
day = 0,
hour = 0,
min = 0,
sec = 0;
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);
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]);
/* Use windowing at 1970 if century is missing */
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);
if (year > 100)
{
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 );
gmt to local (*date, *time, date, time);
return (TRUE);
}
| | << | < | > | >> |
|