![]() |
Qt 6.x
The Qt SDK
|
\inmodule QtCore More...
#include <qtimezone.h>
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. | |
QTimeZone & | operator= (const QTimeZone &other) |
Assignment operator, assign other to this. | |
void | swap (QTimeZone &other) noexcept |
Swaps this time zone instance with other. | |
bool | operator== (const QTimeZone &other) const |
Returns true if this time representation is equal to the other. | |
bool | operator!= (const QTimeZone &other) const |
Returns true if this time zone is not equal to the other time zone. | |
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 QDataStream & | operator<< (QDataStream &ds, const QTimeZone &tz) |
Q_CORE_EXPORT QDebug | operator<< (QDebug dbg, const QTimeZone &tz) |
\inmodule QtCore
QTimeZone identifies how a time representation relates to UTC.
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.
Definition at line 24 of file qtimezone.h.
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 93 of file qtimezone.h.
|
noexcept |
Create a null/invalid time zone instance.
Definition at line 427 of file qtimezone.cpp.
References MaxUtcOffsetSecs.
|
inlinenoexcept |
Creates a lightweight instance describing UTC or local time.
Definition at line 96 of file qtimezone.h.
|
noexcept |
Copy constructor: copy other to this.
Definition at line 694 of file qtimezone.cpp.
|
inlinenoexcept |
Move constructor of this from other.
Definition at line 108 of file qtimezone.h.
QTimeZone::~QTimeZone | ( | ) |
Destroys the time zone.
Definition at line 709 of file qtimezone.cpp.
|
inlineconstexprnoexcept |
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 134 of file qtimezone.h.
References d, and Qt::OffsetFromUTC.
Referenced by reviseTimeZone().
|
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().
Definition at line 122 of file qtimezone.h.
References Qt::OffsetFromUTC, Qt::TimeZone, and Qt::UTC.
|
inlinestatic |
Definition at line 129 of file qtimezone.h.
Referenced by QOCIDateTime::fromOCIDateTime(), operator>>(), QDateTimeParser::setDigit(), and QDateTime::toOffsetFromUtc().
|
inlineconstexprnoexcept |
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 139 of file qtimezone.h.
References isUtcOrFixedOffset().
Referenced by isUtcOrFixedOffset(), massageAdjustedDateTime(), refreshSimpleDateTime(), reviseTimeZone(), and QDateTime::setMSecsSinceEpoch().
|
inlinestaticconstexprnoexcept |
Returns true
if spec is Qt::UTC or Qt::OffsetFromUTC.
Definition at line 137 of file qtimezone.h.
References Qt::OffsetFromUTC, and Qt::UTC.
Referenced by QDateTimePrivate::create(), toEarliest(), and toLatest().
bool QTimeZone::isValid | ( | ) | const |
Returns true
if this time zone is valid.
Definition at line 779 of file qtimezone.cpp.
Referenced by QDate::endOfDay(), QDateTime::fromMSecsSinceEpoch(), QDateTime::fromSecsSinceEpoch(), QDate::startOfDay(), and stateAtMillis().
bool QTimeZone::operator!= | ( | const QTimeZone & | other | ) | const |
Returns true
if this time zone is not equal to the other time zone.
Two representations are different if they are internally described differently, even if they agree in their representation of all moments of time. In particular, a lightweight time representation may coincide with a time zone but the two will not be equal.
Definition at line 770 of file qtimezone.cpp.
References 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 724 of file qtimezone.cpp.
References other().
bool QTimeZone::operator== | ( | const QTimeZone & | other | ) | const |
Returns true
if this time representation is equal to the other.
Two representations are different if they are internally described differently, even if they agree in their representation of all moments of time. In particular, a lightweight time representation may coincide with a time zone but the two will not be equal.
Definition at line 746 of file qtimezone.cpp.
References other().
|
inlinenoexcept |
Swaps this time zone instance with other.
This function is very fast and never fails.
Definition at line 114 of file qtimezone.h.
|
inlineconstexprnoexcept |
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.
Definition at line 133 of file qtimezone.h.
References d.
Referenced by QDate::endOfDay(), QDateTimeEditPrivate::getMaximum(), QDateTimeEditPrivate::getMinimum(), refreshZonedDateTime(), reviseTimeZone(), QDate::startOfDay(), and stateAtMillis().
|
friend |
Definition at line 1594 of file qtimezone.cpp.
Definition at line 1652 of file qtimezone.cpp.
|
friend |
Definition at line 241 of file qtimezone.h.
|
friend |
Definition at line 242 of file qtimezone.h.
|
friend |
Definition at line 240 of file qtimezone.h.
|
staticconstexpr |
Definition at line 89 of file qtimezone.h.
Referenced by QTimeZone(), QDateTimeParser::absoluteMax(), and QTimeZonePrivate::dataForLocalTime().
|
staticconstexpr |
Definition at line 86 of file qtimezone.h.
Referenced by QDateTimeParser::absoluteMin(), and QTimeZonePrivate::dataForLocalTime().