Back to index

avfs  1.0.1
Functions
dates.h File Reference
#include <sys/types.h>
#include "neon_defs.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

BEGIN_NEON_DECLS char * rfc1123_date (time_t anytime)
time_t rfc1123_parse (const char *date)
time_t rfc1036_parse (const char *date)
time_t asctime_parse (const char *date)

Function Documentation

time_t asctime_parse ( const char *  date)

Definition at line 126 of file dates.c.

{
    struct tm gmt = {0};
    int n;
    static char wkday[4], mon[4];
    n = sscanf(date, ASCTIME_FORMAT,
              wkday, mon, &gmt.tm_mday, 
              &gmt.tm_hour, &gmt.tm_min, &gmt.tm_sec,
              &gmt.tm_year);
    /* portable to check n here? */
    for (n=0; n<12; n++)
       if (strcmp(mon, short_months[n]) == 0)
           break;
    /* tm_mon comes out as 12 if the month is corrupt, which is desired,
     * since the mktime will then fail */
    gmt.tm_mon = n;
    return mktime(&gmt);
}
time_t rfc1036_parse ( const char *  date)

Definition at line 103 of file dates.c.

{
    struct tm gmt = {0};
    int n;
    static char wkday[10], mon[4];
    /* RFC850/1036 style dates: Sunday, 06-Nov-94 08:49:37 GMT */
    n = sscanf(date, RFC1036_FORMAT,
              wkday, &gmt.tm_mday, mon, &gmt.tm_year,
              &gmt.tm_hour, &gmt.tm_min, &gmt.tm_sec);
    /* portable to check n here? */
    for (n=0; n<12; n++)
       if (strcmp(mon, short_months[n]) == 0)
           break;
    /* tm_mon comes out as 12 if the month is corrupt, which is desired,
     * since the mktime will then fail */
    gmt.tm_mon = n;
    return mktime(&gmt);
}
BEGIN_NEON_DECLS char* rfc1123_date ( time_t  anytime)

Definition at line 64 of file dates.c.

                                   {
    struct tm *gmt;
    char *ret;
    gmt = gmtime(&anytime);
    if (gmt == NULL)
       return NULL;
    ret = ne_malloc(29 + 1); /* dates are 29 chars long */
/*  it goes: Sun, 06 Nov 1994 08:49:37 GMT */
    snprintf(ret, 30, RFC1123_FORMAT,
             rfc1123_weekdays[gmt->tm_wday], gmt->tm_mday, 
             short_months[gmt->tm_mon], 1900 + gmt->tm_year, 
             gmt->tm_hour, gmt->tm_min, gmt->tm_sec);
    
    return ret;
}
time_t rfc1123_parse ( const char *  date)

Definition at line 82 of file dates.c.

{
    struct tm gmt = {0};
    static char wkday[4], mon[4];
    int n;
/*  it goes: Sun, 06 Nov 1994 08:49:37 GMT */
    n = sscanf(date, RFC1123_FORMAT,
           wkday, &gmt.tm_mday, mon, &gmt.tm_year, &gmt.tm_hour,
           &gmt.tm_min, &gmt.tm_sec);
    /* Is it portable to check n==7 here? */
    gmt.tm_year -= 1900;
    for (n=0; n<12; n++)
       if (strcmp(mon, short_months[n]) == 0)
           break;
    /* tm_mon comes out as 12 if the month is corrupt, which is desired,
     * since the mktime will then fail */
    gmt.tm_mon = n;
    return mktime(&gmt);
}