From 100e0485572146e903fb96698cf6a5f34dd6c1f6 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 23 Jun 2021 18:35:04 +0200 Subject: [PATCH] Use qMod(, 7) rather than % 7 in day-of-week calculation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Otherwise, for the first day of a negative year, we'd get an invalid day of the week (required to be in the range 1 through 7). This is a follow-up to commit 1f4b237dade9d0d2ed5439e3834ac22985797561. Change-Id: If1afcd42065c26d5fa5799b0cd47921a3d424dc8 Reviewed-by: Thiago Macieira Reviewed-by: Andrei Golubev Reviewed-by: MÃ¥rten Nordheim --- src/corelib/time/qgregoriancalendar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/time/qgregoriancalendar.cpp b/src/corelib/time/qgregoriancalendar.cpp index ca3c19b85c..d8e39786fa 100644 --- a/src/corelib/time/qgregoriancalendar.cpp +++ b/src/corelib/time/qgregoriancalendar.cpp @@ -144,7 +144,7 @@ int QGregorianCalendar::yearStartWeekDay(int year) { // Equivalent to weekDayOfJulian(julianForParts({year, 1, 1}) const int y = year - (year < 0 ? 800 : 801); - return (y + qDiv(y, 4) - qDiv(y, 100) + qDiv(y, 400)) % 7 + 1; + return qMod(y + qDiv(y, 4) - qDiv(y, 100) + qDiv(y, 400), 7) + 1; } QCalendar::YearMonthDay QGregorianCalendar::julianDayToDate(qint64 jd) const