From f291575d95ab0159fa809c63855f787ccb1877f5 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 24 Apr 2023 16:58:46 +0200 Subject: [PATCH] Relocate two helpers from QLocalTime to an anonymous namespace MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When I broke them out from functions in the QLocalTime namespace I didn't notice that's where I was putting them; they don't belong there. Change-Id: If4c9d996b3e46b3b46a29a97d0bcc2cac72c91ab Reviewed-by: MÃ¥rten Nordheim --- src/corelib/time/qlocaltime.cpp | 36 ++++++++++++++++----------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/corelib/time/qlocaltime.cpp b/src/corelib/time/qlocaltime.cpp index d8c0a3f823..84a96a48d4 100644 --- a/src/corelib/time/qlocaltime.cpp +++ b/src/corelib/time/qlocaltime.cpp @@ -165,6 +165,24 @@ struct tm timeToTm(qint64 localDay, int secs, QDateTimePrivate::DaylightStatus d return local; } +#define IC(N) std::integral_constant() + +// True if combining day and seconds overflows qint64; otherwise, sets *epochSeconds +inline bool daysAndSecondsOverflow(qint64 julianDay, qint64 daySeconds, qint64 *epochSeconds) +{ + return mul_overflow(julianDay - JULIAN_DAY_FOR_EPOCH, IC(SECS_PER_DAY), epochSeconds) + || add_overflow(*epochSeconds, daySeconds, epochSeconds); +} + +// True if combining seconds and millis overflows; otherwise sets *epochMillis +inline bool secondsAndMillisOverflow(qint64 epochSeconds, qint64 millis, qint64 *epochMillis) +{ + return mul_overflow(epochSeconds, IC(MSECS_PER_SEC), epochMillis) + || add_overflow(*epochMillis, millis, epochMillis); +} + +#undef IC + } // namespace namespace QLocalTime { @@ -232,24 +250,6 @@ int getUtcOffset(qint64 atMSecsSinceEpoch) } #endif // QT_BOOTSTRAPPED -#define IC(N) std::integral_constant() - -// True if combining day and seconds overflows qint64; otherwise, sets *epochSeconds -inline bool daysAndSecondsOverflow(qint64 julianDay, qint64 daySeconds, qint64 *epochSeconds) -{ - return mul_overflow(julianDay - JULIAN_DAY_FOR_EPOCH, IC(SECS_PER_DAY), epochSeconds) - || add_overflow(*epochSeconds, daySeconds, epochSeconds); -} - -// True if combining seconds and millis overflows; otherwise sets *epochMillis -inline bool secondsAndMillisOverflow(qint64 epochSeconds, qint64 millis, qint64 *epochMillis) -{ - return mul_overflow(epochSeconds, IC(MSECS_PER_SEC), epochMillis) - || add_overflow(*epochMillis, millis, epochMillis); -} - -#undef IC - // Calls the platform variant of localtime() for the given utcMillis, and // returns the local milliseconds, offset from UTC and DST status. QDateTimePrivate::ZoneState utcToLocal(qint64 utcMillis)