qt5base-lts/tests/auto
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
..
cmake Generate instances of types in the CMake tests. 2012-10-31 07:16:03 +01:00
compilerwarnings/data Change copyrights from Nokia to Digia 2012-09-22 19:20:11 +02:00
concurrent Fix for leak in QFuture 2012-11-01 16:09:29 +01:00
corelib Fix the gregorian date <-> julian day calculations in QDate 2012-11-02 12:16:49 +01:00
dbus normalise signal/slot signatures [QtDBus tests] 2012-10-19 00:44:54 +02:00
gui Introduced QWindow properties {min/max}imum{Width/Height} 2012-11-02 12:16:49 +01:00
guiapplauncher
network SSL certificate printing: Fix auto test for OpenSSL 1.0.1 version. 2012-11-02 03:58:16 +01:00
opengl Change the default major version of QGLFormat to 2. 2012-10-19 02:43:05 +02:00
other Expose IAccessibleTable2 to non-conformant screen readers 2012-11-02 10:28:34 +01:00
printsupport Only use the user set page margins for custom paper 2012-10-30 12:53:46 +01:00
shared Auto tests: add PlatformClipboard::isAvailable() 2012-09-27 06:07:13 +02:00
sql normalise signal/slot signatures [QtSql tests] 2012-10-19 13:02:17 +02:00
testlib add a .qmake.conf file which load()s qt_build_config 2012-10-18 17:42:40 +02:00
tools Fix qmake's pro file cache to interact correctly with write_file 2012-10-25 16:22:00 +02:00
widgets Compile fix for tst_qstylesheetstyle.cpp 2012-11-01 16:12:15 +01:00
xml Change copyrights from Nokia to Digia 2012-09-22 19:20:11 +02:00
auto.pro Test: Redo remove QSKIP from printsupport tests 2012-09-13 19:33:08 +02:00
network-settings.h Change copyrights from Nokia to Digia 2012-09-22 19:20:11 +02:00
qtest-config.h Auto tests: revise cursor dependant tests 2012-10-13 05:51:19 +02:00
test.pl Change copyrights from Nokia to Digia 2012-09-22 19:20:11 +02:00