Add systemTimeZoneId() to the C++20 tzdb backend of QTimeZone

It's not strictly necessary, but it should be a little more
efficient. Without it, QTZ::systemTimeZoneId() falls back to using the
id() of a default-constructed backend, QChronoTZP(), which will get
the same answer returned here, but we can avoid the need for that
fall-back by doing the right lookup to begin with.

Change-Id: I6fe5beba048b5e9817b6bfed6eba785b13c2c206
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Edward Welbourne 2024-10-07 17:44:55 +02:00
parent 74c481bd4f
commit 92d24e52f1
2 changed files with 11 additions and 0 deletions

View File

@ -62,6 +62,15 @@ QChronoTimeZonePrivate::QChronoTimeZonePrivate(QByteArrayView id)
QChronoTimeZonePrivate::~QChronoTimeZonePrivate()
= default;
QByteArray QChronoTimeZonePrivate::systemTimeZoneId() const
{
if (const time_zone *zone = std::chrono::current_zone()) {
std::string_view name = zone->name();
return {name.begin(), qsizetype(name.size())};
}
return {};
}
QString QChronoTimeZonePrivate::abbreviation(qint64 atMSecsSinceEpoch) const
{
if (auto info = infoAtEpochMillis(m_timeZone, atMSecsSinceEpoch))

View File

@ -241,6 +241,8 @@ public:
QChronoTimeZonePrivate(QByteArrayView id);
~QChronoTimeZonePrivate() override;
QByteArray systemTimeZoneId() const override;
QString abbreviation(qint64 atMSecsSinceEpoch) const override;
int offsetFromUtc(qint64 atMSecsSinceEpoch) const override;
int standardTimeOffset(qint64 atMSecsSinceEpoch) const override;