From 28d676960b32fa996b9a278476c00d63a91386f9 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Wed, 7 Jun 2017 15:41:07 -0400 Subject: Fix some CFGAS_FormatString issues MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This CL fixes the solar days calculation for months after August. Simplifies the minute rounding method. Change-Id: I5f335338ecac911ef0ab57602f41bb98c6f9fa6c Reviewed-on: https://pdfium-review.googlesource.com/6331 Commit-Queue: dsinclair Reviewed-by: Nicolás Peña Reviewed-by: Lei Zhang --- xfa/fgas/crt/cfgas_formatstring.cpp | 17 +++++++++-------- xfa/fgas/crt/cfgas_formatstring_unittest.cpp | 7 +++++++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/xfa/fgas/crt/cfgas_formatstring.cpp b/xfa/fgas/crt/cfgas_formatstring.cpp index 6e2952a7cc..77dfb45941 100644 --- a/xfa/fgas/crt/cfgas_formatstring.cpp +++ b/xfa/fgas/crt/cfgas_formatstring.cpp @@ -391,9 +391,9 @@ void ResolveZone(FX_TIMEZONE tzDiff, (tzLocale.tzHour < 0 ? -tzLocale.tzMinute : tzLocale.tzMinute); iMinuteDiff -= tzDiff.tzHour * 60 + (tzDiff.tzHour < 0 ? -tzDiff.tzMinute : tzDiff.tzMinute); - while (iMinuteDiff > 1440) - iMinuteDiff -= 1440; - while (iMinuteDiff < 0) + + iMinuteDiff %= 1440; + if (iMinuteDiff < 0) iMinuteDiff += 1440; *wHour = iMinuteDiff / 60; @@ -604,19 +604,20 @@ int32_t GetNumTrailingLimit(const CFX_WideString& wsFormat, return iTreading; } +// |month| is 1-based. e.g. 1 means January. uint16_t GetSolarMonthDays(uint16_t year, uint16_t month) { - if (month % 2) - return 31; if (month == 2) return FX_IsLeapYear(year) ? 29 : 28; - return 30; + if (month == 4 || month == 6 || month == 9 || month == 11) + return 30; + return 31; } uint16_t GetWeekDay(uint16_t year, uint16_t month, uint16_t day) { - uint16_t g_month_day[] = {0, 3, 3, 6, 1, 4, 6, 2, 5, 0, 3, 5}; + static const uint16_t month_day[] = {0, 3, 3, 6, 1, 4, 6, 2, 5, 0, 3, 5}; uint16_t nDays = (year - 1) % 7 + (year - 1) / 4 - (year - 1) / 100 + (year - 1) / 400; - nDays += g_month_day[month - 1] + day; + nDays += month_day[month - 1] + day; if (FX_IsLeapYear(year) && month > 2) nDays++; return nDays % 7; diff --git a/xfa/fgas/crt/cfgas_formatstring_unittest.cpp b/xfa/fgas/crt/cfgas_formatstring_unittest.cpp index 37fb3e62a4..32bb23b22c 100644 --- a/xfa/fgas/crt/cfgas_formatstring_unittest.cpp +++ b/xfa/fgas/crt/cfgas_formatstring_unittest.cpp @@ -80,6 +80,13 @@ TEST_F(CFGAS_FormatStringTest, DateFormat) { {L"en", L"19990110", L"MMM D, YYYY", L"Jan 10, 1999"}, {L"en", L"19990202", L"J", L"33"}, {L"en", L"19990202", L"JJJ", L"033"}, + {L"en", L"19991231", L"J", L"365"}, + {L"en", L"20001231", L"J", L"366"}, + {L"en", L"19990501", L"J", L"121"}, + {L"en", L"19990901", L"J", L"244"}, + {L"en", L"19990228", L"J", L"59"}, + {L"en", L"20000229", L"J", L"60"}, + {L"en", L"21000501", L"J", L"121"}, {L"en", L"19990102", L"M", L"1"}, {L"en", L"19990102", L"MMM", L"Jan"}, {L"en", L"19990102", L"YYYY G", L"1999 AD"}, -- cgit v1.2.3