From: Jacob Czekalla jczekalla@codeweavers.com
Order of day or month and time or year needs to be considered. --- dlls/wininet/internet.c | 128 +++++++++++++++++++++++++++------------- 1 file changed, 88 insertions(+), 40 deletions(-)
diff --git a/dlls/wininet/internet.c b/dlls/wininet/internet.c index 17a7ce9385e..5d7b48a3069 100644 --- a/dlls/wininet/internet.c +++ b/dlls/wininet/internet.c @@ -3960,6 +3960,70 @@ BOOL WINAPI InternetTimeToSystemTimeA( LPCSTR string, SYSTEMTIME* time, DWORD re return ret; }
+static inline BOOL calc_month(SYSTEMTIME* time, const WCHAR **s, WCHAR *end) +{ + time->wMonth = 0; + if (**s == '\0') return TRUE; + + if (iswalpha(**s)) + { + if ((*s)[1] == '\0' || (*s)[2] == '\0') return TRUE; + for (int i = 0; i < 12; i++) + { + if (!wcsnicmp(WININET_month[i], *s, 3)) + { + time->wMonth = i + 1; + *s += 3; + break; + } + } + } + else if (is_time_digit(**s)) + { + time->wMonth = wcstol(*s, &end, 10); + *s = end; + } + return (time->wMonth == 0); +} + +static inline void calc_day(SYSTEMTIME* time, const WCHAR **s, WCHAR *end) +{ + time->wDay = wcstol( *s, &end, 10 ); + *s = end; +} + +static inline BOOL calc_time(SYSTEMTIME* time, const WCHAR **s, WCHAR *end) +{ + if (**s == '\0') return TRUE; + time->wHour = wcstol( *s, &end, 10 ); + *s = end; + + while (**s && !is_time_digit(**s)) (*s)++; + if (**s == '\0') return TRUE; + time->wMinute = wcstol( *s, &end, 10 ); + *s = end; + + while (**s && !is_time_digit(**s)) (*s)++; + if (**s == '\0') return TRUE; + time->wSecond = wcstol( *s, &end, 10 ); + *s = end; + + time->wMilliseconds = 0; + return FALSE; +} + +static inline BOOL calc_year(SYSTEMTIME* time, const WCHAR **s, WCHAR *end) +{ + time->wYear = wcstol( *s, &end, 10 ); + *s = end; + return FALSE; +} + +static inline BOOL is_time(const WCHAR *s) +{ + return (s[1] == L':' || s[2] == L':'); +} + /*********************************************************************** * InternetTimeToSystemTimeW (WININET.@) */ @@ -3992,6 +4056,7 @@ BOOL WINAPI InternetTimeToSystemTimeW( LPCWSTR string, SYSTEMTIME* time, DWORD r if (!wcsnicmp(WININET_wkday[i], s, 3)) { time->wDayOfWeek = i; + s += 3; break; } } @@ -4003,54 +4068,37 @@ BOOL WINAPI InternetTimeToSystemTimeW( LPCWSTR string, SYSTEMTIME* time, DWORD r } if (time->wDayOfWeek > 6) return TRUE;
- while (*s && !is_time_digit(*s)) s++; - time->wDay = wcstol( s, &end, 10 ); - s = end; - while (*s && !iswalpha(*s) && !is_time_digit(*s)) s++; if (*s == '\0') return TRUE; - time->wMonth = 0; - - if (iswalpha(*s)) + if (is_time_digit(*s)) { - if (s[1] == '\0' || s[2] == '\0') return TRUE; - for (i = 0; i < 12; i++) - { - if (!wcsnicmp(WININET_month[i], s, 3)) - { - time->wMonth = i + 1; - break; - } - } - } - else if (is_time_digit(*s)) + calc_day(time, &s, end); + while (*s && !iswalpha(*s) && !is_time_digit(*s)) s++; + if (calc_month(time, &s, end)) + return TRUE; + }else { - time->wMonth = wcstol(s, &end, 10); - s = end; + if (calc_month(time, &s, end)) + return TRUE; + while (*s && !iswalpha(*s) && !is_time_digit(*s)) s++; + calc_day(time, &s, end); } - if (time->wMonth == 0) return TRUE; - - while (*s && !is_time_digit(*s)) s++; - if (*s == '\0') return TRUE; - time->wYear = wcstol( s, &end, 10 ); - s = end;
while (*s && !is_time_digit(*s)) s++; if (*s == '\0') return TRUE; - time->wHour = wcstol( s, &end, 10 ); - s = end; - - while (*s && !is_time_digit(*s)) s++; - if (*s == '\0') return TRUE; - time->wMinute = wcstol( s, &end, 10 ); - s = end; - - while (*s && !is_time_digit(*s)) s++; - if (*s == '\0') return TRUE; - time->wSecond = wcstol( s, &end, 10 ); - s = end; - - time->wMilliseconds = 0; + if (is_time(s)) + { + if (calc_time(time, &s, end)) + return TRUE; + while (*s && !is_time_digit(*s)) s++; + calc_year(time, &s, end); + }else + { + if (calc_year(time, &s, end)) + return TRUE; + while (*s && !is_time_digit(*s)) s++; + calc_time(time, &s, end); + } return TRUE; }