Make systemTimeZone() and systemTimeZoneId() consistent
It's possible, as was (and still is) documented, at least on Windows, for the backend to determine the system local time zone's properties but not its IANA ID. (That involves an update to Windows introducing a Windows zone ID unknown to the CLDR with whose data Qt was compiled.) Formerly this lead to systemTimeZoneId() and systemTimeZone().id() being inconsistent. Furthermore, either in this case or when the system zone can't be determined, passing the return from systemTimeZoneId() to the constructor got a valid QTimeZone that did not faithfully represent the system's local time or the return from systemTimeZone(). [ChangeLog][QtCore][QTimeZone] When unable to determine the IANA ID of the system's local time zone, QTimeZone::systemTimeZoneId() now returns empty instead of the "UTC" it formerly, and misleadingly, returned. Passing the return to the QTimeZone constructor now consistently produces the same as calling QTimeZone::systemTimeZone(), whose id() now matches the return from QTimeZone::systemTimeZoneId(). This is independent of whether QTimeZone::systemTimeZone() is valid. Change-Id: I55bbe3ea407ca38343a09da353d9336708747bf1 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
8e0bf6e05b
commit
ffe8932ef3
@ -1315,13 +1315,25 @@ QTimeZone::OffsetDataList QTimeZone::transitions(const QDateTime &fromDateTime,
|
|||||||
/*!
|
/*!
|
||||||
Returns the current system time zone IANA ID.
|
Returns the current system time zone IANA ID.
|
||||||
|
|
||||||
On Windows this ID is translated from the Windows ID using an internal
|
Equivalent to calling systemTimeZone().id(), but may bypass some computation
|
||||||
translation table and the user's selected country. As a consequence there
|
to obtain it. Constructing a QTimeZone from the returned byte array will
|
||||||
is a small chance any Windows install may have IDs not known by Qt, in
|
produce the same result as systemTimeZone().
|
||||||
which case "UTC" will be returned.
|
|
||||||
|
If the backend is unable to determine the correct system zone, the result is
|
||||||
|
empty. In this case, systemTimeZone().isValid() is false and a warning is
|
||||||
|
output if either this method of systemTimeZone() is called.
|
||||||
|
|
||||||
|
If the backend is able to determine the correct system zone but not its
|
||||||
|
name, an empty byte array is returned. For example, on Windows, the system
|
||||||
|
native ID is converted to an IANA ID - if the system ID isn't known to the
|
||||||
|
internal translation code, the result shall be empty. In this case,
|
||||||
|
systemTimeZone().isValid() shall be true.
|
||||||
|
|
||||||
This method is only available when feature \c timezone is enabled.
|
This method is only available when feature \c timezone is enabled.
|
||||||
|
|
||||||
|
\note Prior to Qt 6.7, when the result could not be determined, the
|
||||||
|
misleading result "UTC" was returned.
|
||||||
|
|
||||||
\sa systemTimeZone()
|
\sa systemTimeZone()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -1331,12 +1343,7 @@ QByteArray QTimeZone::systemTimeZoneId()
|
|||||||
if (!sys.isEmpty())
|
if (!sys.isEmpty())
|
||||||
return sys;
|
return sys;
|
||||||
// The system zone, despite the empty ID, may know its real ID anyway:
|
// The system zone, despite the empty ID, may know its real ID anyway:
|
||||||
auto zone = systemTimeZone();
|
return systemTimeZone().id();
|
||||||
if (zone.isValid() && !zone.id().isEmpty())
|
|
||||||
return zone.id();
|
|
||||||
// TODO: "-00:00", meaning "unspecified local zone" in some RFC, may be more apt.
|
|
||||||
// If all else fails, guess UTC.
|
|
||||||
return QTimeZonePrivate::utcQByteArray();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -1355,7 +1362,7 @@ QByteArray QTimeZone::systemTimeZoneId()
|
|||||||
lack the timezone data relied on by the backend for which Qt was compiled,
|
lack the timezone data relied on by the backend for which Qt was compiled,
|
||||||
it may be invalid. In such a case, a warning is output.
|
it may be invalid. In such a case, a warning is output.
|
||||||
|
|
||||||
\sa utc(), Initialization, asBackendZone()
|
\sa utc(), Initialization, asBackendZone(), systemTimeZoneId()
|
||||||
*/
|
*/
|
||||||
QTimeZone QTimeZone::systemTimeZone()
|
QTimeZone QTimeZone::systemTimeZone()
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user