summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qlocale.cpp
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2023-10-25 14:53:56 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2023-10-26 16:57:01 +0200
commit31dc17c13a1977ce60bf9ec73a8762b0087c48df (patch)
tree2be7909313518c38e376d9c7250350d1bcf49194 /src/corelib/text/qlocale.cpp
parentb7b2375751ca098eaa564202b00a46ad58c87399 (diff)
Rework massaging of time zone offsets in formatted date-times
Add a missing std::move() and rearrange comments. Change-Id: I2d93e88f7b9b6f62e7d1cca5cacf794d2fef53b5 Reviewed-by: Paul Wicking <paul.wicking@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/text/qlocale.cpp')
-rw-r--r--src/corelib/text/qlocale.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp
index 16a0341a7e..bdd000a452 100644
--- a/src/corelib/text/qlocale.cpp
+++ b/src/corelib/text/qlocale.cpp
@@ -3593,14 +3593,14 @@ QString QCalendarBackend::dateTimeToString(QStringView format, const QDateTime &
text = when.timeZone().displayName(when, QTimeZone::LongName);
break;
#endif // timezone
- case 3:
- case 2:
+ case 3: // ±hh:mm
+ case 2: // ±hhmm (we'll remove the ':' at the end)
text = when.toOffsetFromUtc(when.offsetFromUtc()).timeZoneAbbreviation();
// If the offset is UTC that'll be a Qt::UTC, otherwise Qt::OffsetFromUTC.
- Q_ASSERT(text.startsWith("UTC"_L1));
- // The Qt::UTC case omits the zero offset, which we want:
- text = text.size() == 3 ? u"+00:00"_s : text.sliced(3);
- if (repeat == 2) // +hhmm format, rather than +hh:mm format
+ Q_ASSERT(text.startsWith("UTC"_L1)); // Need to strip this.
+ // The Qt::UTC case omits the zero offset:
+ text = text.size() == 3 ? u"+00:00"_s : std::move(text).sliced(3);
+ if (repeat == 2)
text = text.remove(u':');
break;
default: