From cc57089a7cd3915e51ddf3cc76efcac3d6b87774 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 8 Oct 2024 19:01:57 +0200 Subject: [PATCH] Round to nearest minutes in L10n'd zone-offset representations The CLDR formats only have minute precision, ignoring seconds. If the zone has some seconds in its offset, I initially implemented that to round down. Change from that to rounding to the nearest minute (e.g. Netherlands until 1937, at +01:19:32.13, gets to be 01:20 instead of 01:19), prefering the even minute if the offset is exactly some minutes plus 30 seconds. Change-Id: Ic49ccbd5fd687098b6dc40e227eec1a9eb939054 Reviewed-by: Thiago Macieira --- src/corelib/time/qtimezonelocale.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/corelib/time/qtimezonelocale.cpp b/src/corelib/time/qtimezonelocale.cpp index cf4a1e55e1b..b33e9c840d3 100644 --- a/src/corelib/time/qtimezonelocale.cpp +++ b/src/corelib/time/qtimezonelocale.cpp @@ -378,9 +378,11 @@ QString zoneOffsetFormat(const QLocale &locale, qsizetype locInd, QLocale::Forma Q_ASSERT(!hourFormat.isEmpty()); // Sign is already handled by choice of the hourFormat: offsetSeconds = qAbs(offsetSeconds); + // Offsets are only displayed in minutes - round seconds (if any) to nearest + // minute (prefering an even minute when rounding an exact half): + const int offsetMinutes = (offsetSeconds + 29 + (1 & (offsetSeconds / 60))) / 60; - // Offsets are only displayed in minutes, any seconds are discarded. - const QString hourOffset = formatOffset(hourFormat, offsetSeconds / 60, locale, width); + const QString hourOffset = formatOffset(hourFormat, offsetMinutes, locale, width); if (width == QLocale::ShortFormat) return hourOffset;