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.calendar;
15 extern(C++):
16 
17 import qt.config;
18 import qt.core.datetime;
19 import qt.core.locale;
20 import qt.core.objectdefs;
21 import qt.core.string;
22 import qt.core.stringlist;
23 import qt.core.stringview;
24 import qt.helpers;
25 
26 /* Suggested enum names for other calendars known to CLDR (v33.1)
27 
28    Not yet implemented - see QCalendar::System - contributions welcome:
29 
30    * Buddhist -- Thai Buddhist, to be specific
31    * Chinese
32    * Coptic
33    * Dangi -- Korean
34    * Ethiopic (Amete Mihret - epoch approx. 8 C.E.)
35    * EthiopicAmeteAlem (Amete Alem - epoch approx. 5493 B.C.E; data from
36      type="ethiopic-amete-alem", an alias for type="ethioaa")
37    * Hebrew
38    * Indian -- National
39    * Islamic -- Based on astronomical observations, not predictions, so hard to
40      implement. CLDR's data for type="islamic" apply, unless overridden, to the
41      other Islamic calendar variants, i.e. IslamicCivil, above, and the three
42      following. See QHijriCalendar, a common base to provide that data.
43    * IslamicTabular -- tabular, astronomical epoch (same as IslamicCivil, except
44      for epoch), CLDR type="islamic-tbla"
45    * Saudi -- Saudi Arabia, sighting; CLDR type="islamic-rgsa"
46    * UmmAlQura -- Umm al-Qura, Saudi Arabia, calculated; CLDR type="islamic-umalqura"
47    * Iso8601 -- as Gregorian, but treating ISO 8601 weeks as "months"
48    * Japanese -- Imperial calendar
49    * Minguo -- Republic of China, Taiwan; CLDR type="roc"
50 
51    See:
52    http://www.unicode.org/repos/cldr/tags/latest/common/bcp47/calendar.xml
53 
54    These can potentially be supported, as features, using CLDR's data; any
55    others shall need hand-crafted localization data; it would probably be best
56    to do that by contributing data for them to CLDR.
57 */
58 
59 
60 extern(C++, class) struct QCalendarBackend;
61 /+ class QDate; +/
62 
63 extern(C++, class) struct /+ Q_CORE_EXPORT +/ QCalendar
64 {
65     mixin(Q_GADGET);
66 public:
67     // (Extra parentheses to suppress bogus reading of min() as a macro.)
68     enum int Unspecified = int.min;
69     struct YearMonthDay
70     {
71         /+ YearMonthDay() = default; +/
72         this(int y, int m = 1, int d = 1)
73         {
74             this.year = y;
75             this.month = m;
76             this.day = d;
77         }
78 
79         bool isValid() const
80         { return month != Unspecified && day != Unspecified; }
81         // (The first year supported by QDate has year == Unspecified.)
82 
83         int year = Unspecified;
84         int month = Unspecified;
85         int day = Unspecified;
86     }
87     // Feature (\w+)calendar uses CLDR type="\1" data, except as noted in type="..." comments below
88     enum /+ class +/ System
89     {
90         Gregorian, // CLDR: type = "gregory", alias = "gregorian"
91 /+ #ifndef QT_BOOTSTRAPPED +/
92         Julian = 8,
93         Milankovic = 9,
94 /+ #endif // These are Roman-based, so share Gregorian's CLDR data
95 
96         // Feature-controlled calendars:
97 #if QT_CONFIG(jalalicalendar) +/ // type="persian"
98         Jalali = 10,
99 /+ #endif
100 #if QT_CONFIG(islamiccivilcalendar) +/ // type="islamic-civil", uses data from type="islamic"
101         IslamicCivil = 11,
102         // tabular, civil epoch
103         // 30 year cycle, leap on 2, 5, 7, 10, 13, 16, 18, 21, 24, 26 and 29
104         // (Other variants: 2, 5, 8, (10|11), 13, 16, 19, 21, 24, 27 and 29.)
105 /+ #endif +/
106 
107         Last = 11, // Highest number of any above
108         User = -1
109     }
110     // New entries must be added to the \enum doc in qcalendar.cpp and
111     // handled in QCalendarBackend::fromEnum()
112     /+ Q_ENUM(System) +/
113 
114     @disable this();
115     /+ explicit +/pragma(mangle, defaultConstructorMangling(__traits(identifier, typeof(this))))
116     ref typeof(this) rawConstructor();
117     static typeof(this) create()
118     {
119         typeof(this) r = typeof(this).init;
120         r.rawConstructor();
121         return r;
122     }
123  // Gregorian, optimised
124     /+ explicit +/this(System system);
125     /+ explicit +/this(QLatin1String name);
126     /+ explicit +/this(QStringView name);
127 
128     // QCalendar is a trivially copyable value type.
129     bool isValid() const { return d !is null; }
130 
131     // Date queries:
132     int daysInMonth(int month, int year = Unspecified) const;
133     int daysInYear(int year) const;
134     int monthsInYear(int year) const;
135     bool isDateValid(int year, int month, int day) const;
136 
137     // Leap years:
138     bool isLeapYear(int year) const;
139 
140     // Properties of the calendar:
141     bool isGregorian() const;
142     bool isLunar() const;
143     bool isLuniSolar() const;
144     bool isSolar() const;
145     bool isProleptic() const;
146     bool hasYearZero() const;
147     int maximumDaysInMonth() const;
148     int minimumDaysInMonth() const;
149     int maximumMonthsInYear() const;
150     QString name() const;
151 
152     // QDate conversions:
153     QDate dateFromParts(int year, int month, int day) const;
154     QDate dateFromParts(ref const(YearMonthDay) parts) const;
155     YearMonthDay partsFromDate(QDate date) const;
156     int dayOfWeek(QDate date) const;
157 
158     // Month and week-day names (as in QLocale):
159     QString monthName(ref const(QLocale) locale, int month, int year = Unspecified,
160                           QLocale.FormatType format=QLocale.FormatType.LongFormat) const;
161     QString standaloneMonthName(ref const(QLocale) locale, int month, int year = Unspecified,
162                                     QLocale.FormatType format = QLocale.FormatType.LongFormat) const;
163     QString weekDayName(ref const(QLocale) locale, int day,
164                             QLocale.FormatType format = QLocale.FormatType.LongFormat) const;
165     QString standaloneWeekDayName(ref const(QLocale) locale, int day,
166                                       QLocale.FormatType format=QLocale.FormatType.LongFormat) const;
167 
168     // Formatting of date-times:
169     QString dateTimeToString(QStringView format, ref const(QDateTime) datetime,
170                                  ref const(QDate) dateOnly, ref const(QTime) timeOnly,
171                                  ref const(QLocale) locale) const;
172 
173     // What's available ?
174     static QStringList availableCalendars();
175 private:
176     // Always supplied by QCalendarBackend and expected to be a singleton
177     const(QCalendarBackend)* d;
178 }
179