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 <thiago.macieira@intel.com>
This commit is contained in:
Edward Welbourne 2024-10-08 19:01:57 +02:00
parent 2739c59749
commit cc57089a7c

View File

@ -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;