summaryrefslogtreecommitdiffstats
path: root/src/corelib/time/qtimezone.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/time/qtimezone.h')
-rw-r--r--src/corelib/time/qtimezone.h36
1 files changed, 22 insertions, 14 deletions
diff --git a/src/corelib/time/qtimezone.h b/src/corelib/time/qtimezone.h
index 20b6df2ad5..6c490c4e25 100644
--- a/src/corelib/time/qtimezone.h
+++ b/src/corelib/time/qtimezone.h
@@ -5,6 +5,7 @@
#ifndef QTIMEZONE_H
#define QTIMEZONE_H
+#include <QtCore/qcompare.h>
#include <QtCore/qdatetime.h>
#include <QtCore/qlocale.h>
#include <QtCore/qswap.h>
@@ -12,7 +13,7 @@
#include <chrono>
-#if QT_CONFIG(timezone) && (defined(Q_OS_DARWIN) || defined(Q_QDOC)) && !defined(QT_NO_SYSTEMLOCALE)
+#if QT_CONFIG(timezone) && (defined(Q_OS_DARWIN) || defined(Q_QDOC))
Q_FORWARD_DECLARE_CF_TYPE(CFTimeZone);
Q_FORWARD_DECLARE_OBJC_CLASS(NSTimeZone);
#endif
@@ -48,7 +49,7 @@ class Q_CORE_EXPORT QTimeZone
#endif
{
}
- friend constexpr bool operator==(const ShortData &lhs, const ShortData &rhs)
+ friend constexpr bool operator==(ShortData lhs, ShortData rhs)
{ return lhs.mode == rhs.mode && lhs.offset == rhs.offset; }
constexpr Qt::TimeSpec spec() const { return Qt::TimeSpec((mode + 3) & 3); }
};
@@ -82,13 +83,13 @@ class Q_CORE_EXPORT QTimeZone
QTimeZone(ShortData sd) : d(sd) {}
public:
- // Sane UTC offsets range from -14 to +14 hours:
- enum {
- // No known zone > 12 hrs West of Greenwich (Baker Island, USA)
- MinUtcOffsetSecs = -14 * 3600,
- // No known zone > 14 hrs East of Greenwich (Kiritimati, Christmas Island, Kiribati)
- MaxUtcOffsetSecs = +14 * 3600
- };
+ // Sane UTC offsets range from -16 to +16 hours:
+ static constexpr int MinUtcOffsetSecs = -16 * 3600;
+ // No known modern zone > 12 hrs West of Greenwich.
+ // Until 1844, Asia/Manila (in The Philippines) was at 15:56 West.
+ static constexpr int MaxUtcOffsetSecs = +16 * 3600;
+ // No known modern zone > 14 hrs East of Greenwich.
+ // Until 1867, America/Metlakatla (in Alaska) was at 15:13:42 East.
enum Initialization { LocalTime, UTC };
@@ -114,20 +115,23 @@ public:
void swap(QTimeZone &other) noexcept
{ d.swap(other.d); }
+#if QT_CORE_REMOVED_SINCE(6, 7)
bool operator==(const QTimeZone &other) const;
bool operator!=(const QTimeZone &other) const;
+#endif
bool isValid() const;
static QTimeZone fromDurationAheadOfUtc(std::chrono::seconds offset)
{
- return fromSecondsAheadOfUtc(int(offset.count()));
+ return QTimeZone((offset.count() >= MinUtcOffsetSecs && offset.count() <= MaxUtcOffsetSecs)
+ ? ShortData(offset.count() ? Qt::OffsetFromUTC : Qt::UTC,
+ int(offset.count()))
+ : ShortData(Qt::TimeZone));
}
static QTimeZone fromSecondsAheadOfUtc(int offset)
{
- return QTimeZone((offset >= MinUtcOffsetSecs && offset <= MaxUtcOffsetSecs)
- ? ShortData(offset ? Qt::OffsetFromUTC : Qt::UTC, offset)
- : ShortData(Qt::TimeZone));
+ return fromDurationAheadOfUtc(std::chrono::seconds{offset});
}
constexpr Qt::TimeSpec timeSpec() const noexcept { return d.s.spec(); }
constexpr int fixedSecondsAheadOfUtc() const noexcept
@@ -162,6 +166,7 @@ public:
};
typedef QList<OffsetData> OffsetDataList;
+ bool aliasMatches(QByteArrayView alias) const;
QByteArray id() const;
QLocale::Territory territory() const;
# if QT_DEPRECATED_SINCE(6, 6)
@@ -210,7 +215,7 @@ public:
static QList<QByteArray> windowsIdToIanaIds(const QByteArray &windowsId,
QLocale::Territory territory);
-# if (defined(Q_OS_DARWIN) || defined(Q_QDOC)) && !defined(QT_NO_SYSTEMLOCALE)
+# if defined(Q_OS_DARWIN) || defined(Q_QDOC)
static QTimeZone fromCFTimeZone(CFTimeZoneRef timeZone);
CFTimeZoneRef toCFTimeZone() const Q_DECL_CF_RETURNS_RETAINED;
static QTimeZone fromNSTimeZone(const NSTimeZone *timeZone);
@@ -229,6 +234,9 @@ public:
# endif
#endif // feature timezone
private:
+ friend Q_CORE_EXPORT bool comparesEqual(const QTimeZone &lhs, const QTimeZone &rhs) noexcept;
+ Q_DECLARE_EQUALITY_COMPARABLE(QTimeZone)
+
#ifndef QT_NO_DATASTREAM
friend Q_CORE_EXPORT QDataStream &operator<<(QDataStream &ds, const QTimeZone &tz);
#endif