diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2021-05-27 16:30:35 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2021-06-07 18:43:17 +0200 |
commit | ad554707dc1e564fa0ac0f164ed093ddc80f14b0 (patch) | |
tree | ba899d6cdccb3deb39641f3b4b59e305a82ecfe5 /src/corelib/time/qdatetime.cpp | |
parent | c1ab14496a57c41ef63ed3a5e5abd110a235ecc7 (diff) |
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>
Diffstat (limited to 'src/corelib/time/qdatetime.cpp')
-rw-r--r-- | src/corelib/time/qdatetime.cpp | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/src/corelib/time/qdatetime.cpp b/src/corelib/time/qdatetime.cpp index 6b6674dcce..94ea0112d4 100644 --- a/src/corelib/time/qdatetime.cpp +++ b/src/corelib/time/qdatetime.cpp @@ -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) |