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