KAlarmCal

datetime.h
1 /*
2  * datetime.h - date/time with start-of-day time for date-only values
3  * This file is part of kalarmcal library, which provides access to KAlarm
4  * calendar data.
5  * SPDX-FileCopyrightText: 2003-2019 David Jarvie <[email protected]>
6  *
7  * SPDX-License-Identifier: LGPL-2.0-or-later
8  */
9 #ifndef KALARM_DATETIME_H
10 #define KALARM_DATETIME_H
11 
12 #include "kalarmcal_export.h"
13 
14 #include "kadatetime.h"
15 
16 namespace KAlarmCal
17 {
18 
29 class KALARMCAL_EXPORT DateTime
30 {
31 public:
35  DateTime();
36 
38  DateTime(const QDate &d, const KADateTime::Spec &spec);
39 
41  DateTime(const QDate &d, const QTime &t, const KADateTime::Spec &spec);
42 
44  DateTime(const QDateTime &dt, const KADateTime::Spec &spec);
45 
47  explicit DateTime(const QDateTime &dt);
48 
50  DateTime(const KADateTime &dt); //krazy:exclude=explicit Allow implicit conversion
51 
53  DateTime(const DateTime &dt);
54 
55  ~DateTime();
56 
58  DateTime &operator=(const DateTime &dt);
59 
63  DateTime &operator=(const KADateTime &dt);
64 
66  bool isNull() const;
67 
69  bool isValid() const;
70 
72  bool isDateOnly() const;
73 
77  void setDateOnly(bool d);
78 
80  QDate date() const;
81 
83  void setDate(const QDate &d);
84 
87  QDateTime qDateTime() const;
88 
90  KADateTime kDateTime() const;
91 
95  QTime effectiveTime() const;
96 
99  void setTime(const QTime &t);
100 
105  QDateTime effectiveDateTime() const;
106 
111  KADateTime effectiveKDateTime() const;
112 
116  QDateTime calendarDateTime() const;
117 
121  KADateTime calendarKDateTime() const;
122 
124  QTimeZone timeZone() const;
125 
127  KADateTime::Spec timeSpec() const;
128 
132  void setTimeSpec(const KADateTime::Spec &spec);
133 
136  KADateTime::SpecType timeType() const;
137 
139  bool isLocalZone() const;
140 
142  bool isUtc() const;
143 
145  bool isOffsetFromUtc() const;
146 
148  int utcOffset() const;
149 
151  bool isSecondOccurrence() const;
152 
154  void setSecondOccurrence(bool second);
155 
157  DateTime toUtc() const;
158 
161  DateTime toOffsetFromUtc() const;
162 
164  DateTime toOffsetFromUtc(int utcOffset) const;
165 
167  DateTime toLocalZone() const;
168 
170  DateTime toZone(const QTimeZone &zone) const;
171 
173  DateTime toTimeSpec(const KADateTime::Spec &spec) const;
174 
177  qint64 toSecsSinceEpoch() const;
178 
181  KALARMCAL_DEPRECATED uint toTime_t() const;
182 
187  void setSecsSinceEpoch(qint64 secs);
188 
193  KALARMCAL_DEPRECATED void setTime_t(uint secs);
194 
196  DateTime addSecs(qint64 n) const;
197 
199  DateTime addMins(qint64 n) const;
200 
202  DateTime addDays(int n) const;
203 
205  DateTime addMonths(int n) const;
206 
208  DateTime addYears(int n) const;
209 
211  int daysTo(const DateTime &dt) const;
212 
214  int minsTo(const DateTime &dt) const;
215 
221  int secsTo(const DateTime &dt) const;
222 
224  qint64 secsTo_long(const DateTime &dt) const;
225 
231 
236  QString toString(const QString &format) const;
237 
242  QString formatLocale(bool shortFormat = true) const;
243 
247  static void setStartOfDay(const QTime &sod);
248 
250  static QTime startOfDay();
251 
253  KADateTime::Comparison compare(const DateTime &other) const;
254 
255  KALARMCAL_EXPORT friend bool operator==(const KAlarmCal::DateTime &dt1, const KAlarmCal::DateTime &dt2);
256  KALARMCAL_EXPORT friend bool operator==(const KADateTime &dt1, const KAlarmCal::DateTime &dt2);
257  KALARMCAL_EXPORT friend bool operator<(const KAlarmCal::DateTime &dt1, const KAlarmCal::DateTime &dt2);
258  friend bool operator<(const KADateTime &dt1, const KAlarmCal::DateTime &dt2);
259 
260 private:
261  //@cond PRIVATE
262  class Private;
263  Private *const d;
264  //@endcond
265 };
266 
268 KALARMCAL_EXPORT bool operator==(const DateTime &dt1, const DateTime &dt2);
269 KALARMCAL_EXPORT bool operator==(const KADateTime &dt1, const DateTime &dt2);
270 
272 inline bool operator!=(const DateTime &dt1, const DateTime &dt2)
273 {
274  return !operator==(dt1, dt2);
275 }
276 inline bool operator!=(const KADateTime &dt1, const DateTime &dt2)
277 {
278  return !operator==(dt1, dt2);
279 }
280 
286 KALARMCAL_EXPORT bool operator<(const DateTime &dt1, const DateTime &dt2);
287 inline bool operator<(const KADateTime &dt1, const DateTime &dt2)
288 {
289  return operator<(DateTime(dt1), dt2);
290 }
291 
297 inline bool operator>(const DateTime &dt1, const DateTime &dt2)
298 {
299  return operator<(dt2, dt1);
300 }
301 inline bool operator>(const KADateTime &dt1, const DateTime &dt2)
302 {
303  return operator<(dt2, DateTime(dt1));
304 }
305 
311 inline bool operator>=(const DateTime &dt1, const DateTime &dt2)
312 {
313  return !operator<(dt1, dt2);
314 }
315 inline bool operator>=(const KADateTime &dt1, const DateTime &dt2)
316 {
317  return !operator<(DateTime(dt1), dt2);
318 }
319 
325 inline bool operator<=(const DateTime &dt1, const DateTime &dt2)
326 {
327  return !operator<(dt2, dt1);
328 }
329 inline bool operator<=(const KADateTime &dt1, const DateTime &dt2)
330 {
331  return !operator<(dt2, DateTime(dt1));
332 }
333 
334 } // namespace KAlarmCal
335 
336 #endif // KALARM_DATETIME_H
337 
338 // vim: et sw=4:
A class representing a date and time with an associated time zone.
Definition: kadatetime.h:145
Date/times with associated time zone.
Comparison
How this KADateTime compares with another.
Definition: kadatetime.h:429
Same format as Qt::TextDate (i.e.
Definition: kadatetime.h:396
SpecType
The time specification type of a KADateTime instance.
Definition: kadatetime.h:155
TimeFormat
Format for strings representing date/time values.
Definition: kadatetime.h:366
The full time specification of a KADateTime instance.
Definition: kadatetime.h:180
As KADateTime, but with a configurable start-of-day time for date-only values.
Definition: datetime.h:29
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat Oct 24 2020 23:15:16 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.