diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2022-07-15 15:59:40 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2022-08-03 18:38:53 +0200 |
commit | 0a36a7c1db173089c25ea09029505a589a1c59e5 (patch) | |
tree | c7db940804c19ee48e90d92edc103e6230f48f9b /src/corelib/text | |
parent | effd6f63f1a4b7dc7b5e6bca41594f1d1562a713 (diff) |
Make 'zz' format an alias for 'z' in time format strings
Also document the (seldom helpful) handling of over-long repeats of a
format. Add test to QDateTime and amend QLocale test.
[ChangeLog][QtCore][QDateTime] Doubling the 'z' format in a date-time
or time format string now produces the same output as a single 'z'.
Previously, this would have produced two copies of the milliseconds
field (eliding any trailing zeros in each). Contrast with 'zzz', which
produces the full milliseconds field, including any trailing zeros.
Change-Id: I4c60462b062fee4079370096d745c191c1939506
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/text')
-rw-r--r-- | src/corelib/text/qlocale.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp index b19e4498d3..d3670c119a 100644 --- a/src/corelib/text/qlocale.cpp +++ b/src/corelib/text/qlocale.cpp @@ -3484,13 +3484,13 @@ QString QCalendarBackend::dateTimeToString(QStringView format, const QDateTime & case 'z': used = true; - repeat = (repeat >= 3) ? 3 : 1; + repeat = qMin(repeat, 3); // 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(locale.d->m_data->longLongToString(time.msec(), -1, 10, 3, QLocaleData::ZeroPadded)); - if (repeat == 1) { + if (repeat != 3) { if (result.endsWith(locale.zeroDigit())) result.chop(1); if (result.endsWith(locale.zeroDigit())) |