From b3a119e72d30a60ed40f3f093745971ae5fa7dc6 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Mon, 5 Jun 2017 11:51:23 -0400 Subject: Add more CFGAS_FormatString tests. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This CL adds some more time tests for CFGAS_FormatString. Change-Id: Ida7d9e665f304b984508ff3b404e7ea9c38ef415 Reviewed-on: https://pdfium-review.googlesource.com/6270 Reviewed-by: Nicolás Peña Commit-Queue: dsinclair --- xfa/fgas/crt/cfgas_formatstring.cpp | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'xfa/fgas/crt/cfgas_formatstring.cpp') diff --git a/xfa/fgas/crt/cfgas_formatstring.cpp b/xfa/fgas/crt/cfgas_formatstring.cpp index 58e4c9562e..22e9325df2 100644 --- a/xfa/fgas/crt/cfgas_formatstring.cpp +++ b/xfa/fgas/crt/cfgas_formatstring.cpp @@ -448,9 +448,9 @@ bool ParseLocaleTime(const CFX_WideString& wsTime, dwSymbol == FXBSTR_ID(0, 0, 'H', '1') || dwSymbol == FXBSTR_ID(0, 0, 'h', '1') || dwSymbol == FXBSTR_ID(0, 0, 'K', '1')) { - if (!FXSYS_isDecimalDigit(str[cc])) { + if (!FXSYS_isDecimalDigit(str[cc])) return false; - } + hour = str[cc++] - '0'; if (cc < len && FXSYS_isDecimalDigit(str[cc])) hour = hour * 10 + str[cc++] - '0'; @@ -871,7 +871,7 @@ bool TimeFormat(const CFX_WideString& wsTimePattern, } } else if (dwSymbol == FXBSTR_ID(0, 0, 'z', '1')) { FX_TIMEZONE tz = pLocale->GetTimeZone(); - if (tz.tzHour != 0 && tz.tzMinute != 0) { + if (tz.tzHour != 0 || tz.tzMinute != 0) { wsResult += tz.tzHour < 0 ? L"-" : L"+"; CFX_WideString wsTimezone; @@ -996,6 +996,7 @@ bool FX_TimeFromCanonical(const CFX_WideStringC& wsTime, hour = hour * 10 + str[cc++] - '0'; } + if (cc < 2 || hour >= 24) return false; if (cc < len) { @@ -1042,6 +1043,23 @@ bool FX_TimeFromCanonical(const CFX_WideStringC& wsTime, } } + while (cc < len) { + // Skip until we find a + or - for the time zone. + if (str[cc] != '+' && str[cc] != '-') { + ++cc; + continue; + } + + FX_TIMEZONE tzDiff; + tzDiff.tzHour = 0; + tzDiff.tzMinute = 0; + if (str[cc] != 'Z') + cc += ParseTimeZone(str + cc, len - cc, &tzDiff); + + ResolveZone(hour, minute, tzDiff, pLocale); + break; + } + if (cc < len) { FX_TIMEZONE tzDiff; tzDiff.tzHour = 0; @@ -1992,7 +2010,8 @@ bool CFGAS_FormatString::ParseDateTime(const CFX_WideString& wsSrcDateTime, if (wsSrcDateTime.IsEmpty() || wsPattern.IsEmpty()) return false; - CFX_WideString wsDatePattern, wsTimePattern; + CFX_WideString wsDatePattern; + CFX_WideString wsTimePattern; IFX_Locale* pLocale = nullptr; FX_DATETIMETYPE eCategory = GetDateTimeFormat(wsPattern, pLocale, wsDatePattern, wsTimePattern); -- cgit v1.2.3