Commit 314950e0 authored by Claes's avatar Claes Committed by Esteban Blanc

time_AsciiToA() handles different formats

parent 20dfb924
...@@ -1069,9 +1069,23 @@ pwr_tStatus time_AsciiToTm(const char* tstr, struct tm* tmptr) ...@@ -1069,9 +1069,23 @@ pwr_tStatus time_AsciiToTm(const char* tstr, struct tm* tmptr)
struct tm tt; struct tm tt;
int i; int i;
pwr_tStatus sts; pwr_tStatus sts;
int monstr = 0;
sscanf(tstr, "%02d-%3c-%4d %02d:%02d:%02d", &tt.tm_mday, tmpMonStr, if (tstr[5] == '-') {
&tt.tm_year, &tt.tm_hour, &tt.tm_min, &tt.tm_sec); sscanf(tstr, "%02d-%02d-%4d %02d:%02d:%02d", &tt.tm_mday, &tt.tm_mon,
&tt.tm_year, &tt.tm_hour, &tt.tm_min, &tt.tm_sec);
tt.tm_mon--;
}
else if (tstr[4] == '-') {
sscanf(tstr, "%4d-%02d-%02d %02d:%02d:%02d", &tt.tm_year, &tt.tm_mon,
&tt.tm_mday, &tt.tm_hour, &tt.tm_min, &tt.tm_sec);
tt.tm_mon--;
}
else {
sscanf(tstr, "%02d-%3c-%4d %02d:%02d:%02d", &tt.tm_mday, tmpMonStr,
&tt.tm_year, &tt.tm_hour, &tt.tm_min, &tt.tm_sec);
monstr = 1;
}
tmpMonStr[3] = '\0'; tmpMonStr[3] = '\0';
tt.tm_year -= 1900; tt.tm_year -= 1900;
...@@ -1083,14 +1097,16 @@ pwr_tStatus time_AsciiToTm(const char* tstr, struct tm* tmptr) ...@@ -1083,14 +1097,16 @@ pwr_tStatus time_AsciiToTm(const char* tstr, struct tm* tmptr)
tt.tm_isdst = -1; tt.tm_isdst = -1;
/* check month */ /* check month */
for (cp = tmpMonStr; *cp; cp++) if (monstr) {
*cp = toupper(*cp); for (cp = tmpMonStr; *cp; cp++)
*cp = toupper(*cp);
tt.tm_mon = -1;
for (i = 0; i < 12; i++) { tt.tm_mon = -1;
if (streq(tmpMonStr, monStr[i])) { for (i = 0; i < 12; i++) {
tt.tm_mon = i; if (streq(tmpMonStr, monStr[i])) {
break; tt.tm_mon = i;
break;
}
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment