1 /**************************************************************************** 2 ** 3 ** DQt - D bindings for the Qt Toolkit 4 ** 5 ** GNU Lesser General Public License Usage 6 ** This file may be used under the terms of the GNU Lesser 7 ** General Public License version 3 as published by the Free Software 8 ** Foundation and appearing in the file LICENSE.LGPL3 included in the 9 ** packaging of this file. Please review the following information to 10 ** ensure the GNU Lesser General Public License version 3 requirements 11 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. 12 ** 13 ****************************************************************************/ 14 module qt.core.timezone; 15 extern(C++): 16 17 import qt.config; 18 import qt.core.bytearray; 19 import qt.core.datetime; 20 import qt.core.list; 21 import qt.core.locale; 22 import qt.core.shareddata; 23 import qt.core.string; 24 import qt.core.typeinfo; 25 import qt.core.vector; 26 import qt.helpers; 27 28 /+ QT_REQUIRE_CONFIG(timezone); 29 30 #if (defined(Q_OS_DARWIN) || defined(Q_QDOC)) && !defined(QT_NO_SYSTEMLOCALE) 31 Q_FORWARD_DECLARE_CF_TYPE(CFTimeZone); 32 Q_FORWARD_DECLARE_OBJC_CLASS(NSTimeZone); 33 #endif +/ 34 35 36 extern(C++, class) struct QTimeZonePrivate; 37 38 @Q_MOVABLE_TYPE extern(C++, class) struct /+ Q_CORE_EXPORT +/ QTimeZone 39 { 40 public: 41 // Sane UTC offsets range from -14 to +14 hours: 42 enum { 43 // No known zone > 12 hrs West of Greenwich (Baker Island, USA) 44 MinUtcOffsetSecs = -14 * 3600, 45 // No known zone > 14 hrs East of Greenwich (Kiritimati, Christmas Island, Kiribati) 46 MaxUtcOffsetSecs = +14 * 3600 47 } 48 49 enum TimeType { 50 StandardTime = 0, 51 DaylightTime = 1, 52 GenericTime = 2 53 } 54 55 enum NameType { 56 DefaultName = 0, 57 LongName = 1, 58 ShortName = 2, 59 OffsetName = 3 60 } 61 62 @Q_MOVABLE_TYPE struct OffsetData { 63 QString abbreviation; 64 QDateTime atUtc; 65 int offsetFromUtc; 66 int standardTimeOffset; 67 int daylightTimeOffset; 68 69 void rawConstructor() 70 { 71 import core.lifetime; 72 this.abbreviation = QString.create; 73 emplace!QDateTime(&this.atUtc); 74 } 75 } 76 alias OffsetDataList = QVector!(OffsetData); 77 78 @disable this(); 79 pragma(mangle, defaultConstructorMangling(__traits(identifier, typeof(this)))) 80 ref typeof(this) rawConstructor()/+ noexcept+/; 81 static typeof(this) create() 82 { 83 typeof(this) r = typeof(this).init; 84 r.rawConstructor(); 85 return r; 86 } 87 88 /+ explicit +/this(ref const(QByteArray) ianaId); 89 /+ explicit +/this(int offsetSeconds); 90 /*implicit*/ this(ref const(QByteArray) zoneId, int offsetSeconds, ref const(QString) name, 91 ref const(QString) abbreviation, QLocale.Country country = QLocale.Country.AnyCountry, 92 ref const(QString) comment = globalInitVar!QString); 93 @disable this(this); 94 this(ref const(QTimeZone) other); 95 ~this(); 96 97 /+ref QTimeZone operator =(ref const(QTimeZone) other);+/ 98 /+ QTimeZone &operator=(QTimeZone &&other) noexcept { swap(other); return *this; } +/ 99 100 /+ void swap(QTimeZone &other) noexcept 101 { d.swap(other.d); } +/ 102 103 /+bool operator ==(ref const(QTimeZone) other) const;+/ 104 /+bool operator !=(ref const(QTimeZone) other) const;+/ 105 106 bool isValid() const; 107 108 QByteArray id() const; 109 QLocale.Country country() const; 110 QString comment() const; 111 112 QString displayName(ref const(QDateTime) atDateTime, 113 QTimeZone.NameType nameType/* = QTimeZone.NameType.DefaultName*/, 114 ref const(QLocale) locale/* = globalInitVar!QLocale*/) const; 115 QString displayName(QTimeZone.TimeType timeType, 116 QTimeZone.NameType nameType/* = QTimeZone.NameType.DefaultName*/, 117 ref const(QLocale) locale/* = globalInitVar!QLocale*/) const; 118 QString abbreviation(ref const(QDateTime) atDateTime) const; 119 120 int offsetFromUtc(ref const(QDateTime) atDateTime) const; 121 int standardTimeOffset(ref const(QDateTime) atDateTime) const; 122 int daylightTimeOffset(ref const(QDateTime) atDateTime) const; 123 124 bool hasDaylightTime() const; 125 bool isDaylightTime(ref const(QDateTime) atDateTime) const; 126 127 OffsetData offsetData(ref const(QDateTime) forDateTime) const; 128 129 bool hasTransitions() const; 130 OffsetData nextTransition(ref const(QDateTime) afterDateTime) const; 131 OffsetData previousTransition(ref const(QDateTime) beforeDateTime) const; 132 OffsetDataList transitions(ref const(QDateTime) fromDateTime, ref const(QDateTime) toDateTime) const; 133 134 static QByteArray systemTimeZoneId(); 135 static QTimeZone systemTimeZone(); 136 static QTimeZone utc(); 137 138 static bool isTimeZoneIdAvailable(ref const(QByteArray) ianaId); 139 140 static QList!(QByteArray) availableTimeZoneIds(); 141 static QList!(QByteArray) availableTimeZoneIds(QLocale.Country country); 142 static QList!(QByteArray) availableTimeZoneIds(int offsetSeconds); 143 144 static QByteArray ianaIdToWindowsId(ref const(QByteArray) ianaId); 145 static QByteArray windowsIdToDefaultIanaId(ref const(QByteArray) windowsId); 146 static QByteArray windowsIdToDefaultIanaId(ref const(QByteArray) windowsId, 147 QLocale.Country country); 148 static QList!(QByteArray) windowsIdToIanaIds(ref const(QByteArray) windowsId); 149 static QList!(QByteArray) windowsIdToIanaIds(ref const(QByteArray) windowsId, 150 QLocale.Country country); 151 152 static if((!versionIsSet!("QT_NO_SYSTEMLOCALE") && (versionIsSet!("OSX") || versionIsSet!("iOS") || versionIsSet!("TVOS") || versionIsSet!("WatchOS")))) 153 { 154 /+ static QTimeZone fromCFTimeZone(CFTimeZoneRef timeZone); +/ 155 /+ CFTimeZoneRef toCFTimeZone() const Q_DECL_CF_RETURNS_RETAINED; +/ 156 /+ static QTimeZone fromNSTimeZone(const NSTimeZone *timeZone); +/ 157 /+ NSTimeZone *toNSTimeZone() const Q_DECL_NS_RETURNS_AUTORELEASED; +/ 158 } 159 160 private: 161 this(ref QTimeZonePrivate dd); 162 version(QT_NO_DATASTREAM){}else 163 { 164 /+ friend Q_CORE_EXPORT QDataStream &operator<<(QDataStream &ds, const QTimeZone &tz); +/ 165 } 166 /+ friend class QTimeZonePrivate; +/ 167 /+ friend class QDateTime; +/ 168 /+ friend class QDateTimePrivate; +/ 169 QSharedDataPointer!(QTimeZonePrivate) d; 170 } 171 172 /+ Q_DECLARE_TYPEINFO(QTimeZone::OffsetData, Q_MOVABLE_TYPE); 173 Q_DECLARE_SHARED(QTimeZone) 174 175 #ifndef QT_NO_DATASTREAM 176 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &ds, const QTimeZone &tz); 177 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &ds, QTimeZone &tz); 178 #endif 179 180 #ifndef QT_NO_DEBUG_STREAM 181 Q_CORE_EXPORT QDebug operator<<(QDebug dbg, const QTimeZone &tz); 182 #endif +/ 183