diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2016-09-30 11:18:05 -0700 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2017-07-07 07:21:53 +0000 |
commit | bcd19b723a4adad4d5f1dbbd35079cc24331dfa8 (patch) | |
tree | 88ff2e51b7a2ddb6de1557b352e9f550092acc48 /src/corelib/tools/qlocale.cpp | |
parent | e1d7f7dfbc0191f585fde8695d315e3ffb98ccc5 (diff) |
QLocale: fix handling of milliseconds in string format and document
[ChangeLog][QtCore][QLocale] Fixed the conversion of QTime to string
form and parsing from string form to always treat the value as the
decimal fraction of the seconds component. That is, the string format
".z" produces/parses ".2" for 200 milliseconds and ".002" for 2
milliseconds. Use of "z" or "zzz" is discouraged outside decimal
fractions to avoid surprises.
Task-number: QTBUG-53565
Change-Id: Ia19de85ad35e4eb7bb95fffd14792caf9b4a5156
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/corelib/tools/qlocale.cpp')
-rw-r--r-- | src/corelib/tools/qlocale.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index dcdf6b5ed7..ab95f60115 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -2742,14 +2742,17 @@ QString QLocalePrivate::dateTimeToString(const QString &format, const QDateTime } else { repeat = 1; } - switch (repeat) { - case 1: - result.append(m_data->longLongToString(time.msec())); - break; - case 3: - result.append(m_data->longLongToString(time.msec(), -1, 10, 3, QLocaleData::ZeroPadded)); - break; + + // note: the millisecond component is treated like the decimal part of the seconds + // so ms == 2 is always printed as "002", but ms == 200 can be either "2" or "200" + result.append(m_data->longLongToString(time.msec(), -1, 10, 3, QLocaleData::ZeroPadded)); + if (repeat == 1) { + if (result.endsWith(zero())) + result.chop(1); + if (result.endsWith(zero())) + result.chop(1); } + break; case 't': |