summaryrefslogtreecommitdiffstats
path: root/mimelib/dw_date.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'mimelib/dw_date.cpp')
-rw-r--r--mimelib/dw_date.cpp54
1 files changed, 35 insertions, 19 deletions
diff --git a/mimelib/dw_date.cpp b/mimelib/dw_date.cpp
index c8f89766..e4436bbe 100644
--- a/mimelib/dw_date.cpp
+++ b/mimelib/dw_date.cpp
@@ -246,7 +246,7 @@ int ParseRfc822Date(const char *str, struct tm *tms, int *z)
case 'O':
case 'o':
/* Oct */
- if ((str[pos+1] == 'c' || str[pos+1] == 'c')
+ if ((str[pos+1] == 'c' || str[pos+1] == 'C')
&& (str[pos+2] == 't' || str[pos+2] == 'T')) {
n = 9;
pos += 3;
@@ -713,6 +713,7 @@ int main()
// "WWW MMM dd HH:MM:SS [Z] YYYY" zone is optional
// e.g.: Fri Oct 14 09:21:49 CEST 2005
// or: Tue Mar 23 18:00:02 2004
+// also: Tue, Feb 04, 2003 00:01:20 +0000
#include <string.h>
#include <stdio.h>
@@ -733,6 +734,7 @@ int ParseDate(const char *str, struct tm *tms, int *z)
int day=1, month=0, year=1970, hour=0, minute=0, second=0, zone=0;
int i;
+ // check for week day
for (i = 0; i < 7; i++)
if ( strncmp(str, wdays[i], 3) == 0 )
break;
@@ -740,8 +742,10 @@ int ParseDate(const char *str, struct tm *tms, int *z)
if ( i == 7 )
return -1;
+ // check for month name
+ int offset = (str[3] == ',') ? 5 : 4; // allow weekday be terminated with ","
for (i = 0; i < 12; i++)
- if ( strncmp(str+4, months[i], 3) == 0 )
+ if ( strncmp(str+offset, months[i], 3) == 0 )
break;
if ( i == 12 )
@@ -749,27 +753,39 @@ int ParseDate(const char *str, struct tm *tms, int *z)
month = i;
- if ( sscanf(str+8, "%d %d:%d:%d", &day, &hour, &minute, &second) != 4 )
- return -1;
-
- if ( isdigit(str[20]) ) { // year without zone info, as in ctime()
- if ( sscanf(str+20, "%d", &year) != 1 )
- return -1;
+ // try "dd, YYYY HH:MM:SS +ZZZZ"
+ int h, m;
+ char sign;
+ if ( sscanf(str+offset+4, "%d, %d %d:%d:%d %c%2d%2d", &day, &year, &hour, &minute, &second, &sign, &h, &m) == 8 ) {
+ // ok, worked, calculate zone
+ zone = h * 60 + m;
+ if ( sign == '-' )
+ zone = -zone;
}
else {
- if ( sscanf(str+20, "%*s %d", &year) != 1 )
+ // try "dd HH:MM:SS"
+ if ( sscanf(str+8, "%d %d:%d:%d", &day, &hour, &minute, &second) != 4 )
return -1;
- if ( strncmp(str+20, "EST" , 3) == 0 ) zone = -5 * 60;
- else if ( strncmp(str+20, "EDT" , 3) == 0 ) zone = -4 * 60;
- else if ( strncmp(str+20, "CST" , 3) == 0 ) zone = -6 * 60;
- else if ( strncmp(str+20, "CDT" , 3) == 0 ) zone = -5 * 60;
- else if ( strncmp(str+20, "MST" , 3) == 0 ) zone = -7 * 60;
- else if ( strncmp(str+20, "MDT" , 3) == 0 ) zone = -6 * 60;
- else if ( strncmp(str+20, "PST" , 3) == 0 ) zone = -8 * 60;
- else if ( strncmp(str+20, "PDT" , 3) == 0 ) zone = -7 * 60;
- else if ( strncmp(str+20, "CET" , 3) == 0 ) zone = 60;
- else if ( strncmp(str+20, "CEST", 4) == 0 ) zone = 120;
+ if ( isdigit(str[20]) ) { // year without zone info, as in ctime()
+ if ( sscanf(str+20, "%d", &year) != 1 )
+ return -1;
+ }
+ else {
+ if ( sscanf(str+20, "%*s %d", &year) != 1 )
+ return -1;
+
+ if ( strncmp(str+20, "EST" , 3) == 0 ) zone = -5 * 60;
+ else if ( strncmp(str+20, "EDT" , 3) == 0 ) zone = -4 * 60;
+ else if ( strncmp(str+20, "CST" , 3) == 0 ) zone = -6 * 60;
+ else if ( strncmp(str+20, "CDT" , 3) == 0 ) zone = -5 * 60;
+ else if ( strncmp(str+20, "MST" , 3) == 0 ) zone = -7 * 60;
+ else if ( strncmp(str+20, "MDT" , 3) == 0 ) zone = -6 * 60;
+ else if ( strncmp(str+20, "PST" , 3) == 0 ) zone = -8 * 60;
+ else if ( strncmp(str+20, "PDT" , 3) == 0 ) zone = -7 * 60;
+ else if ( strncmp(str+20, "CET" , 3) == 0 ) zone = 60;
+ else if ( strncmp(str+20, "CEST", 4) == 0 ) zone = 120;
+ }
}
if ( (day < 1) || (day > 31) ||