diff options
author | Ahmad Samir <a.samirh78@gmail.com> | 2023-04-03 13:44:25 +0200 |
---|---|---|
committer | Ahmad Samir <a.samirh78@gmail.com> | 2023-04-22 20:04:31 +0200 |
commit | b9786f21b816ed33ad671230624821b8998be2ff (patch) | |
tree | 4e83f8bbd6620a3abee42ced681dc50184bc8b6b /src/corelib/time/qdatetime.cpp | |
parent | b490bd0265491e8af0bcb1c08159a3a23ac4331e (diff) |
QDateTime: replace a bool parameter with an enum
Change-Id: Ie72b1d482c67c83cb0e2e0bfd1e00f1be2fa4899
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/corelib/time/qdatetime.cpp')
-rw-r--r-- | src/corelib/time/qdatetime.cpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/corelib/time/qdatetime.cpp b/src/corelib/time/qdatetime.cpp index 05031e22db..59da4cb730 100644 --- a/src/corelib/time/qdatetime.cpp +++ b/src/corelib/time/qdatetime.cpp @@ -831,7 +831,9 @@ static QTimeZone asTimeZone(Qt::TimeSpec spec, int offset, const char *warner) } #endif // Helper for 6.9 deprecation -static bool inDateTimeRange(qint64 jd, bool start) +enum class DaySide { Start, End }; + +static bool inDateTimeRange(qint64 jd, DaySide side) { using Bounds = std::numeric_limits<qint64>; if (jd < Bounds::min() + JULIAN_DAY_FOR_EPOCH) @@ -842,9 +844,13 @@ static bool inDateTimeRange(qint64 jd, bool start) // (Divisions rounded towards zero, as MSECS_PER_DAY is even - so doesn't // divide max() - and has factors other than two, so doesn't divide min().) // Range includes start of last day and end of first: - if (start) + switch (side) { + case DaySide::Start: return jd > minDay && jd <= maxDay; - return jd >= minDay && jd < maxDay; + case DaySide::End: + return jd >= minDay && jd < maxDay; + } + Q_UNREACHABLE_RETURN(false); } static QDateTime toEarliest(QDate day, const QTimeZone &zone) @@ -927,7 +933,7 @@ static QDateTime toEarliest(QDate day, const QTimeZone &zone) */ QDateTime QDate::startOfDay(const QTimeZone &zone) const { - if (!inDateTimeRange(jd, true) || !zone.isValid()) + if (!inDateTimeRange(jd, DaySide::Start) || !zone.isValid()) return QDateTime(); QDateTime when(*this, QTime(0, 0), zone); @@ -1077,7 +1083,7 @@ static QDateTime toLatest(QDate day, const QTimeZone &zone) */ QDateTime QDate::endOfDay(const QTimeZone &zone) const { - if (!inDateTimeRange(jd, false) || !zone.isValid()) + if (!inDateTimeRange(jd, DaySide::End) || !zone.isValid()) return QDateTime(); QDateTime when(*this, QTime(23, 59, 59, 999), zone); |