Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QTimeZone Class Reference

\inmodule QtCore More...

#include <qtimezone.h>

+ Collaboration diagram for QTimeZone:

Public Types

enum  Initialization { LocalTime , UTC }
 

Public Member Functions

 QTimeZone () noexcept
 Create a null/invalid time zone instance.
 
Q_IMPLICIT QTimeZone (Initialization spec) noexcept
 
 QTimeZone (const QTimeZone &other) noexcept
 Copy constructor: copy other to this.
 
 QTimeZone (QTimeZone &&other) noexcept
 Move constructor of this from other.
 
 ~QTimeZone ()
 Destroys the time zone.
 
QTimeZoneoperator= (const QTimeZone &other)
 Assignment operator, assign other to this.
 
void swap (QTimeZone &other) noexcept
 Swaps this time zone instance with other.
 
bool isValid () const
 Returns true if this time zone is valid.
 
constexpr Qt::TimeSpec timeSpec () const noexcept
 
constexpr int fixedSecondsAheadOfUtc () const noexcept
 
constexpr bool isUtcOrFixedOffset () const noexcept
 

Static Public Member Functions

static QTimeZone fromDurationAheadOfUtc (std::chrono::seconds offset)
 Returns a time representation at a fixed offset, in seconds, ahead of UTC.
 
static QTimeZone fromSecondsAheadOfUtc (int offset)
 
static constexpr bool isUtcOrFixedOffset (Qt::TimeSpec spec) noexcept
 

Static Public Attributes

static constexpr int MinUtcOffsetSecs = -16 * 3600
 
static constexpr int MaxUtcOffsetSecs = +16 * 3600
 

Friends

class QTimeZonePrivate
 
class QDateTime
 
class QDateTimePrivate
 
Q_CORE_EXPORT bool comparesEqual (const QTimeZone &lhs, const QTimeZone &rhs) noexcept
 
Q_CORE_EXPORT QDataStreamoperator<< (QDataStream &ds, const QTimeZone &tz)
 
Q_CORE_EXPORT QDebug operator<< (QDebug dbg, const QTimeZone &tz)
 

Detailed Description

\inmodule QtCore

Since
5.2 \threadsafe

QTimeZone identifies how a time representation relates to UTC.

\compares equality

When dates and times are combined, the meaning of the result depends on how time is being represented. There are various international standards for representing time; one of these, UTC, corresponds to the traditional standard of solar mean time at Greenwich (a.k.a. GMT). All other time systems supported by Qt are ultimately specified in relation to UTC. An instance of this class provides a stateless calculator for conversions between UTC and other time representations.

Some time representations are simply defined at a fixed offset to UTC. Others are defined by governments for use within their jurisdictions. The latter are properly known as time zones, but QTimeZone (since Qt 6.5) is unifies their representation with that of general time systems. One time zone generally supported on most operating systems is designated local time; this is presumed to correspond to the time zone within which the user is living.

For time zones other than local time, UTC and those at fixed offsets from UTC, Qt can only provide support when the operating system provides some way to access that information. When Qt is built, the timezone feature controls whether such information is available. When it is not, some constructors and methods of QTimeZone are excluded from its API; these are documented as depending on feature timezone. Note that, even when Qt is built with this feature enabled, it may be unavailable to users whose systems are misconfigured, or where some standard packages (for example, the tzdata package on Linux) are not installed. This feature is enabled by default when time zone information is available.

This class is primarily designed for use in QDateTime; most applications will not need to access this class directly and should instead use an instance of it when constructing a QDateTime.

Note
For consistency with QDateTime, QTimeZone does not account for leap seconds.

Definition at line 25 of file qtimezone.h.

Member Enumeration Documentation

◆ Initialization

Since
6.5

The type of the simplest lightweight time representations.

This enumeration identifies a type of lightweight time representation to pass to a QTimeZone constructor, where no further data are required. They correspond to the like-named members of Qt::TimeSpec.

\value LocalTime This time representation corresponds to the one implicitly used by system functions using time_t and {struct tm} value to map between local time and UTC time.

\value UTC This time representation, Coordinated Universal Time, is the base representation to which civil time is referred in all supported time representations. It is defined by the International Telecommunication Union.

Enumerator
LocalTime 
UTC 

Definition at line 94 of file qtimezone.h.

Constructor & Destructor Documentation

◆ QTimeZone() [1/4]

QTimeZone::QTimeZone ( )
noexcept

Create a null/invalid time zone instance.

Definition at line 414 of file qtimezone.cpp.

References MaxUtcOffsetSecs.

Referenced by operator>>().

+ Here is the caller graph for this function:

◆ QTimeZone() [2/4]

QTimeZone::QTimeZone ( Initialization spec)
inlinenoexcept
Since
6.5

Creates a lightweight instance describing UTC or local time.

See also
fromSecondsAheadOfUtc(), asBackendZone(), utc(), systemTimeZone()

Definition at line 97 of file qtimezone.h.

◆ QTimeZone() [3/4]

QTimeZone::QTimeZone ( const QTimeZone & other)
noexcept

Copy constructor: copy other to this.

Definition at line 679 of file qtimezone.cpp.

◆ QTimeZone() [4/4]

QTimeZone::QTimeZone ( QTimeZone && other)
inlinenoexcept

Move constructor of this from other.

Definition at line 109 of file qtimezone.h.

◆ ~QTimeZone()

QTimeZone::~QTimeZone ( )

Destroys the time zone.

Definition at line 694 of file qtimezone.cpp.

Member Function Documentation

◆ fixedSecondsAheadOfUtc()

int QTimeZone::fixedSecondsAheadOfUtc ( ) const
inlineconstexprnoexcept
Since
6.5

For a lightweight time representation whose \l timeSpec() is Qt::OffsetFromUTC, this returns the fixed offset from UTC that it describes. For any other time representation it returns 0, even if that time representation does have a constant offset from UTC.

Definition at line 137 of file qtimezone.h.

References d, and Qt::OffsetFromUTC.

◆ fromDurationAheadOfUtc()

QTimeZone::fromDurationAheadOfUtc ( std::chrono::seconds offset)
inlinestatic

Returns a time representation at a fixed offset, in seconds, ahead of UTC.

The offset from UTC must be in the range -16 hours to +16 hours otherwise an invalid time zone will be returned. The returned QTimeZone is a lightweight time representation, not a time zone (backed by system-supplied or standard data).

If the offset is 0, the \l timeSpec() of the returned instance will be Qt::UTC. Otherwise, if offset is valid, timeSpec() is Qt::OffsetFromUTC. An invalid time zone, when returned, has Qt::TimeZone as its timeSpec().

See also
QTimeZone(int), asBackendZone(), fixedSecondsAheadOfUtc(), MinUtcOffsetSecs, MaxUtcOffsetSecs

Definition at line 125 of file qtimezone.h.

References Qt::OffsetFromUTC, Qt::TimeZone, and Qt::UTC.

◆ fromSecondsAheadOfUtc()

QTimeZone::fromSecondsAheadOfUtc ( int offset)
inlinestatic
Since
6.5

Definition at line 132 of file qtimezone.h.

Referenced by QOCIDateTime::fromOCIDateTime(), operator>>(), QDateTimeParser::setDigit(), and QDateTime::toOffsetFromUtc().

+ Here is the caller graph for this function:

◆ isUtcOrFixedOffset() [1/2]

QTimeZone::isUtcOrFixedOffset ( ) const
inlineconstexprnoexcept
Since
6.5

Returns true if \l timeSpec() is Qt::UTC or Qt::OffsetFromUTC.

When it is true, the time description does not change over time, such as having seasonal daylight-saving changes, as may happen for local time or a time zone. Knowing this may save the calling code to need for various other checks.

Definition at line 142 of file qtimezone.h.

References isUtcOrFixedOffset().

Referenced by isUtcOrFixedOffset(), massageAdjustedDateTime(), refreshSimpleDateTime(), reviseTimeZone(), and QDateTime::setMSecsSinceEpoch().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isUtcOrFixedOffset() [2/2]

QTimeZone::isUtcOrFixedOffset ( Qt::TimeSpec spec)
inlinestaticconstexprnoexcept
Since
6.5

Returns true if spec is Qt::UTC or Qt::OffsetFromUTC.

Definition at line 140 of file qtimezone.h.

References Qt::OffsetFromUTC, and Qt::UTC.

◆ isValid()

bool QTimeZone::isValid ( ) const

Returns true if this time zone is valid.

Definition at line 764 of file qtimezone.cpp.

References QTimeZonePrivate::isValid().

Referenced by QDateTime::fromMSecsSinceEpoch(), QDateTime::fromSecsSinceEpoch(), QDateTime::isDaylightTime(), QDateTime::setMSecsSinceEpoch(), QDateTime::timeZoneAbbreviation(), and QDateTime::toMSecsSinceEpoch().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator=()

QTimeZone & QTimeZone::operator= ( const QTimeZone & other)

Assignment operator, assign other to this.

Move-assigns other to this QTimeZone instance, transferring the ownership of its data to this instance.

Definition at line 709 of file qtimezone.cpp.

References other().

+ Here is the call graph for this function:

◆ swap()

QTimeZone::swap ( QTimeZone & other)
inlinenoexcept

Swaps this time zone instance with other.

This function is very fast and never fails.

Definition at line 115 of file qtimezone.h.

References d, and other().

+ Here is the call graph for this function:

◆ timeSpec()

Qt::TimeSpec QTimeZone::timeSpec ( ) const
inlineconstexprnoexcept
Since
6.5

Returns a Qt::TimeSpec identifying the type of time representation.

If the result is Qt::TimeZone, this time description is a time zone (backed by system-supplied or standard data); otherwise, it is a lightweight time representation. If the result is Qt::LocalTime it describes local time: see Qt::TimeSpec for details.

See also
fixedSecondsAheadOfUtc(), asBackendZone()

Definition at line 136 of file qtimezone.h.

References d.

Referenced by QDateTimeEditPrivate::getMaximum(), and QDateTimeEditPrivate::getMinimum().

+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ comparesEqual

Q_CORE_EXPORT bool comparesEqual ( const QTimeZone & lhs,
const QTimeZone & rhs )
friend

Definition at line 744 of file qtimezone.cpp.

◆ operator<< [1/2]

Q_CORE_EXPORT QDataStream & operator<< ( QDataStream & ds,
const QTimeZone & tz )
friend

Definition at line 1640 of file qtimezone.cpp.

◆ operator<< [2/2]

Q_CORE_EXPORT QDebug operator<< ( QDebug dbg,
const QTimeZone & tz )
friend

Definition at line 1698 of file qtimezone.cpp.

◆ QDateTime

friend class QDateTime
friend

Definition at line 247 of file qtimezone.h.

◆ QDateTimePrivate

friend class QDateTimePrivate
friend

Definition at line 248 of file qtimezone.h.

◆ QTimeZonePrivate

friend class QTimeZonePrivate
friend

Definition at line 246 of file qtimezone.h.

Member Data Documentation

◆ MaxUtcOffsetSecs

constexpr int QTimeZone::MaxUtcOffsetSecs = +16 * 3600
staticconstexpr

◆ MinUtcOffsetSecs

constexpr int QTimeZone::MinUtcOffsetSecs = -16 * 3600
staticconstexpr

Definition at line 87 of file qtimezone.h.

Referenced by QDateTimeParser::absoluteMin(), and QTimeZonePrivate::stateAtZoneTime().


The documentation for this class was generated from the following files: