diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2020-09-30 12:27:59 +0200 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2020-10-07 13:58:33 +0000 |
commit | e5dc46d966a0c98eee4360444963b4d0c3ab9e49 (patch) | |
tree | 11b09bfc1095a16d914538055bd55abbbecd2ecc /tests/auto/corelib/time/qtime/tst_qtime.cpp | |
parent | 51a16a686209452e99e281fc1d80170e87ff6fd2 (diff) |
Allow millisecond-overflow when the result remains valid
Even before adding support for fractional hours, a fraction of a
minute might potentially have represented a whole number of seconds by
a fractional part that, due to rounding, was less than the whole
number of seconds by less than half a millisecond. Previously, the
parsing would have clipped the fractional part at 999 milliseconds, in
the preceding second, instead of correctly rounding it up to the whole
second.
For QTime::fromString(), which can't represent 24:00, and for
TextDate, which doesn't allow 24:00 as a synomym for the next day's
0:0, applying such rounding to 23:59:59.999999 would produce an
invalid result from a string that does represent a valid time, so use
the nearest representable time, as previously.
Added some tests and amended others.
[ChangeLog][QtCore][QDateTime] QDateTime and QTime, in fromString()
with format ISODate or TextDate, now allow a fractional part of the
hour, minute or seconds to round up to the next second (hence
potentially into the next minute, etc.) when this is the closest
representable value to the exact fractional part given. When rounding
up would turn a valid result into an invalid one, however, the old
behavior of clipping to 999 milliseconds is retained.
Change-Id: I8104848d246cdb4545a12819fb4b6755da2b1372
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Andreas Buhr <andreas.buhr@qt.io>
Diffstat (limited to 'tests/auto/corelib/time/qtime/tst_qtime.cpp')
-rw-r--r-- | tests/auto/corelib/time/qtime/tst_qtime.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/tests/auto/corelib/time/qtime/tst_qtime.cpp b/tests/auto/corelib/time/qtime/tst_qtime.cpp index b79cb609e7..ce8a24515b 100644 --- a/tests/auto/corelib/time/qtime/tst_qtime.cpp +++ b/tests/auto/corelib/time/qtime/tst_qtime.cpp @@ -588,10 +588,12 @@ void tst_QTime::fromStringDateFormat_data() << QString("10:12:34") << Qt::TextDate << QTime(10, 12, 34); QTest::newRow("TextDate - milli-max") << QString("19:03:54.998601") << Qt::TextDate << QTime(19, 3, 54, 999); - QTest::newRow("TextDate - milli-no-overflow") - << QString("19:03:54.999601") << Qt::TextDate << QTime(19, 3, 54, 999); + QTest::newRow("TextDate - milli-wrap") + << QString("19:03:54.999601") << Qt::TextDate << QTime(19, 3, 55); QTest::newRow("TextDate - no-secs") << QString("10:12") << Qt::TextDate << QTime(10, 12); + QTest::newRow("TextDate - midnight-nowrap") + << QString("23:59:59.9999") << Qt::TextDate << QTime(23, 59, 59, 999); QTest::newRow("TextDate - invalid, minutes") << QString::fromLatin1("23:XX:00") << Qt::TextDate << invalidTime(); QTest::newRow("TextDate - invalid, minute fraction") << QString::fromLatin1("23:00.123456") << Qt::TextDate << invalidTime(); QTest::newRow("TextDate - invalid, seconds") << QString::fromLatin1("23:00:XX") << Qt::TextDate << invalidTime(); @@ -601,6 +603,8 @@ void tst_QTime::fromStringDateFormat_data() QTest::newRow("IsoDate - valid, start of day, omit seconds") << QString::fromLatin1("00:00") << Qt::ISODate << QTime(0, 0, 0); QTest::newRow("IsoDate - valid, omit seconds") << QString::fromLatin1("22:21") << Qt::ISODate << QTime(22, 21, 0); + QTest::newRow("IsoDate - minute fraction") // 60 * 0.816666 = 48.99996 should round up: + << QString::fromLatin1("22:21.816666") << Qt::ISODate << QTime(22, 21, 49); QTest::newRow("IsoDate - valid, omit seconds (2)") << QString::fromLatin1("23:59") << Qt::ISODate << QTime(23, 59, 0); QTest::newRow("IsoDate - valid, end of day") << QString::fromLatin1("23:59:59") << Qt::ISODate << QTime(23, 59, 59); @@ -619,8 +623,10 @@ void tst_QTime::fromStringDateFormat_data() QTest::newRow("IsoDate - ordinary") << QString("10:12:34") << Qt::ISODate << QTime(10, 12, 34); QTest::newRow("IsoDate - milli-max") << QString("19:03:54.998601") << Qt::ISODate << QTime(19, 3, 54, 999); - QTest::newRow("IsoDate - milli-no-overflow") - << QString("19:03:54.999601") << Qt::ISODate << QTime(19, 3, 54, 999); + QTest::newRow("IsoDate - milli-wrap") + << QString("19:03:54.999601") << Qt::ISODate << QTime(19, 3, 55); + QTest::newRow("IsoDate - midnight-nowrap") + << QString("23:59:59.9999") << Qt::ISODate << QTime(23, 59, 59, 999); QTest::newRow("IsoDate - midnight 24") << QString("24:00:00") << Qt::ISODate << QTime(0, 0); QTest::newRow("IsoDate - minute fraction midnight") |