Skip to content

Commit

Permalink
Add systemTimeZoneId() to the C++20 tzdb backend of QTimeZone
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
ediosyncratic committed Oct 21, 2024
1 parent 74c481b commit 92d24e5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/corelib/time/qtimezoneprivate_chrono.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 2 additions & 0 deletions src/corelib/time/qtimezoneprivate_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ class QChronoTimeZonePrivate final : public QTimeZonePrivate
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;
Expand Down

0 comments on commit 92d24e5

Please sign in to comment.