Simplify QDate::weekNumber()
Eliminate two local variables and don't even compute the year if we don't need it. Change-Id: If968c619750cead317641885a0fb9b9974954782 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
c1ab14496a
commit
ad554707dc
@ -735,14 +735,12 @@ int QDate::weekNumber(int *yearNumber) const
|
||||
|
||||
// This could be replaced by use of QIso8601Calendar, once we implement it.
|
||||
// The Thursday of the same week determines our answer:
|
||||
QDate thursday(addDays(4 - dayOfWeek()));
|
||||
int year = thursday.year();
|
||||
// Week n's Thurs's DOY has 1 <= DOY - 7*(n-1) < 8, so 0 <= DOY + 6 - 7*n < 7:
|
||||
int week = (thursday.dayOfYear() + 6) / 7;
|
||||
|
||||
const QDate thursday(addDays(4 - dayOfWeek()));
|
||||
if (yearNumber)
|
||||
*yearNumber = year;
|
||||
return week;
|
||||
*yearNumber = thursday.year();
|
||||
|
||||
// Week n's Thurs's DOY has 1 <= DOY - 7*(n-1) < 8, so 0 <= DOY + 6 - 7*n < 7:
|
||||
return (thursday.dayOfYear() + 6) / 7;
|
||||
}
|
||||
|
||||
static bool inDateTimeRange(qint64 jd, bool start)
|
||||
|
Loading…
Reference in New Issue
Block a user