QDate: use more constexpr vars instead of plain numbers
Change-Id: I95580c199f868d632324f7f1fcbd56fa4dc85958 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
parent
9c0e0e39f0
commit
fa9244700e
@ -435,6 +435,9 @@ static int fromOffsetString(QStringView offsetString, bool *valid) noexcept
|
||||
|
||||
QDate::QDate(int y, int m, int d)
|
||||
{
|
||||
static_assert(QDate::maxJd() == JulianDayMax);
|
||||
static_assert(QDate::minJd() == JulianDayMin);
|
||||
|
||||
if (!QGregorianCalendar::julianFromParts(y, m, d, &jd))
|
||||
jd = nullJd();
|
||||
}
|
||||
|
@ -122,6 +122,9 @@ constexpr qint64 MSECS_PER_HOUR = SECS_PER_HOUR * MSECS_PER_SEC;
|
||||
constexpr qint64 MSECS_PER_DAY = SECS_PER_DAY * MSECS_PER_SEC;
|
||||
|
||||
constexpr qint64 JULIAN_DAY_FOR_EPOCH = 2440588; // result of QDate(1970, 1, 1).toJulianDay()
|
||||
|
||||
constexpr qint64 JulianDayMax = Q_INT64_C( 784354017364);
|
||||
constexpr qint64 JulianDayMin = Q_INT64_C(-784350574879);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,8 @@
|
||||
#include <private/qglobal_p.h> // for the icu feature test
|
||||
#include <private/qdatetime_p.h>
|
||||
|
||||
using namespace QtPrivate::DateTimeConstants;
|
||||
|
||||
class tst_QDate : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -98,8 +100,8 @@ void tst_QDate::isNull_data()
|
||||
QTest::addColumn<qint64>("jd");
|
||||
QTest::addColumn<bool>("null");
|
||||
|
||||
qint64 minJd = Q_INT64_C(-784350574879);
|
||||
qint64 maxJd = Q_INT64_C( 784354017364);
|
||||
qint64 minJd = JulianDayMin;
|
||||
qint64 maxJd = JulianDayMax;
|
||||
|
||||
QTest::newRow("qint64 min") << std::numeric_limits<qint64>::min() << true;
|
||||
QTest::newRow("minJd - 1") << minJd - 1 << true;
|
||||
@ -693,8 +695,8 @@ void tst_QDate::julianDaysLimits()
|
||||
{
|
||||
qint64 min = std::numeric_limits<qint64>::min();
|
||||
qint64 max = std::numeric_limits<qint64>::max();
|
||||
qint64 minJd = Q_INT64_C(-784350574879);
|
||||
qint64 maxJd = Q_INT64_C( 784354017364);
|
||||
qint64 minJd = JulianDayMin;
|
||||
qint64 maxJd = JulianDayMax;
|
||||
|
||||
QDate maxDate = QDate::fromJulianDay(maxJd);
|
||||
QDate minDate = QDate::fromJulianDay(minJd);
|
||||
@ -917,8 +919,8 @@ void tst_QDate::addYears_data()
|
||||
|
||||
void tst_QDate::daysTo()
|
||||
{
|
||||
qint64 minJd = Q_INT64_C(-784350574879);
|
||||
qint64 maxJd = Q_INT64_C( 784354017364);
|
||||
qint64 minJd = JulianDayMin;
|
||||
qint64 maxJd = JulianDayMax;
|
||||
|
||||
QDate dt1(2000, 1, 1);
|
||||
QDate dt2(2000, 1, 5);
|
||||
@ -1682,8 +1684,8 @@ void tst_QDate::roundtrip() const
|
||||
loopDate = loopDate.addDays(1);
|
||||
}
|
||||
|
||||
qint64 minJd = Q_INT64_C(-784350574879);
|
||||
qint64 maxJd = Q_INT64_C( 784354017364);
|
||||
qint64 minJd = JulianDayMin;
|
||||
qint64 maxJd = JulianDayMax;
|
||||
|
||||
// Test Gregorian round trip at top end of conversion range
|
||||
loopDate = QDate::fromJulianDay(maxJd);
|
||||
|
Loading…
Reference in New Issue
Block a user