qt5base-lts/tests/auto/corelib/tools
Jon Severinsson 53e6cb3ff6 Fix the gregorian date <-> julian day calculations in QDate
The old code is just plain wrong for negative julian days. Replaced
with plain math from The Calendar FAQ [1], which is correct for all
julian days, provided you use mathematical integer division (round to
negative infinity) rather than c++11 integer division (round to zero).

[1] http://www.tondering.dk/claus/cal/julperiod.php

While the conversion code works for up to around JD +/- (2^63/4), we
only use an int for the year in the API, so this patch limits minJd()
and maxJd() to 1 Jan (2^31) BC and 31 Dec (2^31-1) AD, respectively.

Note that while the new conversion code looks like it would be more
expensive than the old, gcc will in fact be able to optimize it to be
slightly faster (probably because x86 hardware implements round to
negative infinity, and so GCC manages to optimize floordiv to a single
instruction, compared to the three instuctions needed for operator/).

In the following test application, run with a release mode Qt and
redirecting stderr to /dev/null, I measured an improvement from
6.81s +/- 0.08s to 6.26s +/- 0.16s user time over five runs on an
otherwise idle x86_64 system.

int main(int, char *[])
{
    int year, month, day;
    qint64 jd;
    for (qint64 i = Q_INT64_C(-1048576) ; i < Q_INT64_C(1048576); ++i) {
        QDate::fromJulianDay(i).getDate(&year, &month, &day);
        jd = QDate(year, month, day).toJulianDay();
        qDebug() << jd << year << month << day;
    }
}

Change-Id: Ifd0dd01f0027f260401f7f9b4f1201d2b7a3b087
Reviewed-by: David Faure (KDE) <faure@kde.org>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2012-11-02 12:16:49 +01:00
..
qalgorithms Change copyrights from Nokia to Digia 2012-09-22 19:20:11 +02:00
qarraydata Test: remove QSKIP in tst_qarraydata 2012-10-18 14:55:23 +02:00
qbitarray Change copyrights from Nokia to Digia 2012-09-22 19:20:11 +02:00
qbytearray test: Remove QSKIP from tst_QByteArray::literals() 2012-10-30 12:53:46 +01:00
qbytearraymatcher Change copyrights from Nokia to Digia 2012-09-22 19:20:11 +02:00
qcache Change copyrights from Nokia to Digia 2012-09-22 19:20:11 +02:00
qchar Update the Unicode Data and Algorithms up to Unicode 6.2 2012-10-09 03:04:41 +02:00
qcontiguouscache Make QContiguousCache with zero capacity not crash 2012-10-19 07:50:29 +02:00
qcryptographichash Change copyrights from Nokia to Digia 2012-09-22 19:20:11 +02:00
qdate Fix the gregorian date <-> julian day calculations in QDate 2012-11-02 12:16:49 +01:00
qdatetime Improve QDateTime test coverage. 2012-11-02 12:16:49 +01:00
qeasingcurve Change copyrights from Nokia to Digia 2012-09-22 19:20:11 +02:00
qelapsedtimer Remove #if 0 usage in QElapsedTimer autotest. 2012-10-04 03:03:35 +02:00
qexplicitlyshareddatapointer Change copyrights from Nokia to Digia 2012-09-22 19:20:11 +02:00
qfreelist Change copyrights from Nokia to Digia 2012-09-22 19:20:11 +02:00
qhash Change copyrights from Nokia to Digia 2012-09-22 19:20:11 +02:00
qline Change copyrights from Nokia to Digia 2012-09-22 19:20:11 +02:00
qlist Change copyrights from Nokia to Digia 2012-09-22 19:20:11 +02:00
qlocale Output leading zeroes for yyyy date formats in QLocale::toString(). 2012-10-24 01:38:49 +02:00
qmap QMap - improve QMap stl-map ctor 2012-10-29 22:21:32 +01:00
qmargins Change copyrights from Nokia to Digia 2012-09-22 19:20:11 +02:00
qpair Change copyrights from Nokia to Digia 2012-09-22 19:20:11 +02:00
qpoint Change copyrights from Nokia to Digia 2012-09-22 19:20:11 +02:00
qpointf Change copyrights from Nokia to Digia 2012-09-22 19:20:11 +02:00
qqueue Change copyrights from Nokia to Digia 2012-09-22 19:20:11 +02:00
qrect Change copyrights from Nokia to Digia 2012-09-22 19:20:11 +02:00
qregexp Change copyrights from Nokia to Digia 2012-09-22 19:20:11 +02:00
qregularexpression Change copyrights from Nokia to Digia 2012-09-22 19:20:11 +02:00
qringbuffer Change copyrights from Nokia to Digia 2012-09-22 19:20:11 +02:00
qscopedpointer Change copyrights from Nokia to Digia 2012-09-22 19:20:11 +02:00
qscopedvaluerollback Change copyrights from Nokia to Digia 2012-09-22 19:20:11 +02:00
qset Change copyrights from Nokia to Digia 2012-09-22 19:20:11 +02:00
qsharedpointer Test: remove QSKIP in tst_QSharedPointer::lambdaCustomDeleter 2012-10-16 20:43:37 +02:00
qsize Change copyrights from Nokia to Digia 2012-09-22 19:20:11 +02:00
qsizef Change copyrights from Nokia to Digia 2012-09-22 19:20:11 +02:00
qstl Change copyrights from Nokia to Digia 2012-09-22 19:20:11 +02:00
qstring Test: remove QSKIP from tst_qstring 2012-10-25 16:22:39 +02:00
qstring_no_cast_from_bytearray Change copyrights from Nokia to Digia 2012-09-22 19:20:11 +02:00
qstringbuilder Change copyrights from Nokia to Digia 2012-09-22 19:20:11 +02:00
qstringlist Test: remove QSKIP from tst_QStringList::initializeList() 2012-10-19 09:41:36 +02:00
qstringmatcher Change copyrights from Nokia to Digia 2012-09-22 19:20:11 +02:00
qstringref Change copyrights from Nokia to Digia 2012-09-22 19:20:11 +02:00
qtextboundaryfinder QTextBoundaryFinder: Fix handling of break opportunities 2012-10-12 07:44:51 +02:00
qtime Improve QTime test coverage. 2012-10-24 01:38:56 +02:00
qtimeline Change copyrights from Nokia to Digia 2012-09-22 19:20:11 +02:00
qvarlengtharray Test: Split tst_QVarLengthArray::oldTests 2012-09-27 21:13:52 +02:00
qvector detach() safely in QVector::erase(), and update callers to not detach. 2012-10-19 18:04:11 +02:00
tools.pro Improve QPoint and QPointF auto tests. 2012-07-11 14:52:17 +02:00