Improved CSV date import

SVN revision: 2168
This commit is contained in:
Stefan Ritt 2009-01-22 08:22:04 +00:00
parent 10f11e013e
commit 6cb8827af6

View File

@ -14243,6 +14243,11 @@ void csv_import(LOGBOOK * lbs, const char *csv, const char *csvfile)
/* get date and check it */ /* get date and check it */
strlcpy(date, list + datecol*NAME_LENGTH, sizeof(date)); strlcpy(date, list + datecol*NAME_LENGTH, sizeof(date));
ltime = date_to_ltime(date); ltime = date_to_ltime(date);
if (ltime <= 0) {
/* try other date formats */
ltime = convert_datetime(date);
if (ltime <= 0)
ltime = convert_date(date);
if (ltime <= 0) { if (ltime <= 0) {
strcpy(str, loc("Invalid date format")); strcpy(str, loc("Invalid date format"));
strlcat(str, ": \"", sizeof(str)); strlcat(str, ": \"", sizeof(str));
@ -14250,7 +14255,11 @@ void csv_import(LOGBOOK * lbs, const char *csv, const char *csvfile)
strlcat(str, "\"", sizeof(str)); strlcat(str, "\"", sizeof(str));
show_error(str); show_error(str);
return; return;
} else { }
/* convert back ltime to date */
get_rfc2822_date(date, sizeof(date), ltime);
}
if (!filltext) { if (!filltext) {
/* submit entry */ /* submit entry */
if (el_submit if (el_submit
@ -14274,7 +14283,6 @@ void csv_import(LOGBOOK * lbs, const char *csv, const char *csvfile)
} }
} }
} }
}
first = FALSE; first = FALSE;
@ -18596,8 +18604,12 @@ time_t convert_datetime(char *date_string)
} else } else
return 0; return 0;
if (!strchr(p, ' '))
return 0;
p = strchr(p, ' ')+1;
strlcpy(str, p, sizeof(str)); strlcpy(str, p, sizeof(str));
p = strtok(p, ":"); p = strtok(str, ":");
if (p) { if (p) {
hour = atoi(p); hour = atoi(p);
p = strtok(NULL, ":"); p = strtok(NULL, ":");