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 /src/corelib/global/qnamespace.qdoc | |
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 'src/corelib/global/qnamespace.qdoc')
-rw-r--r-- | src/corelib/global/qnamespace.qdoc | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/src/corelib/global/qnamespace.qdoc b/src/corelib/global/qnamespace.qdoc index a877b17a4f..3cddb711c5 100644 --- a/src/corelib/global/qnamespace.qdoc +++ b/src/corelib/global/qnamespace.qdoc @@ -709,18 +709,17 @@ fractional part suffix on the preceding field, which may be separated from that field either by a comma \c{','} or the dot \c{'.'} shown. Precision beyond milliseconds is accepted but discarded, rounding to the nearest - millisecond or, when rounding fractional seconds up would change the second - field, rounded down. The presence of a literal \c T character is used to - separate the date and time when both are specified. For the \c TextDate and - \c RFC2822Date formats, \c{ddd} stands for the first three letters of the - name of the day of the week and \c{MMM} stands for the first three letters - of the month name. The names of days and months are always in English (C - locale) regardless of user preferences or system settings. The other format - characters have the same meaning as for the ISODate format, except that 24 - is not accepted as an hour. Parts of a format enclosed in square brackets - \c{[...]} are optional; the square brackets do not form part of the - format. The plus-or-minus character \c{'±'} here stands for either sign - character, \c{'-'} for minus or \c{'+'} for plus. + representable millisecond. The presence of a literal \c T character is used + to separate the date and time when both are specified. For the \c TextDate + and \c RFC2822Date formats, \c{ddd} stands for the first three letters of + the name of the day of the week and \c{MMM} stands for the first three + letters of the month name. The names of days and months are always in + English (C locale) regardless of user preferences or system settings. The + other format characters have the same meaning as for the ISODate format, + except that 24 is not accepted as an hour. Parts of a format enclosed in + square brackets \c{[...]} are optional; the square brackets do not form part + of the format. The plus-or-minus character \c{'±'} here stands for either + sign character, \c{'-'} for minus or \c{'+'} for plus. \sa QDate::toString(), QTime::toString(), QDateTime::toString(), QDate::fromString(), QTime::fromString(), QDateTime::fromString() |