1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the core module of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
32
#include "QtCore/qstring.h"
33
#include "QtCore/qnamespace.h"
35
class Q_CORE_EXPORT QDate
39
QDate(int y, int m, int d);
41
bool isNull() const { return jd == 0; }
47
int dayOfWeek() const;
48
int dayOfYear() const;
49
int daysInMonth() const;
50
int daysInYear() const;
51
int weekNumber(int *yearNum = 0) const;
53
#ifndef QT_NO_TEXTDATE
55
static QT3_SUPPORT QString monthName(int month) { return shortMonthName(month); }
56
static QT3_SUPPORT QString dayName(int weekday) { return shortDayName(weekday); }
58
static QString shortMonthName(int month);
59
static QString shortDayName(int weekday);
60
static QString longMonthName(int month);
61
static QString longDayName(int weekday);
62
#endif // QT_NO_TEXTDATE
63
#ifndef QT_NO_DATESTRING
64
QString toString(Qt::DateFormat f = Qt::TextDate) const;
65
QString toString(const QString &format) const;
67
bool setYMD(int y, int m, int d);
69
QDate addDays(int days) const;
70
QDate addMonths(int months) const;
71
QDate addYears(int years) const;
72
int daysTo(const QDate &) const;
74
bool operator==(const QDate &other) const { return jd == other.jd; }
75
bool operator!=(const QDate &other) const { return jd != other.jd; }
76
bool operator<(const QDate &other) const { return jd < other.jd; }
77
bool operator<=(const QDate &other) const { return jd <= other.jd; }
78
bool operator>(const QDate &other) const { return jd > other.jd; }
79
bool operator>=(const QDate &other) const { return jd >= other.jd; }
81
static QDate currentDate();
82
#ifndef QT_NO_DATESTRING
83
static QDate fromString(const QString &s, Qt::DateFormat f = Qt::TextDate);
85
static QDate fromString(const QString &s, const QString &format);
86
static bool isValid(int y, int m, int d);
87
static bool isLeapYear(int year);
89
inline static QT3_SUPPORT bool leapYear(int year) { return isLeapYear(year); }
92
static uint gregorianToJulian(int y, int m, int d);
93
static void julianToGregorian(uint jd, int &y, int &m, int &d);
96
static QT3_SUPPORT QDate currentDate(Qt::TimeSpec spec);
99
static inline QDate fromJulianDay(int jd) { QDate d; d.jd = jd; return d; }
100
inline int toJulianDay() const { return jd; }
105
friend class QDateTime;
106
#ifndef QT_NO_DATASTREAM
107
friend Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QDate &);
108
friend Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QDate &);
111
Q_DECLARE_TYPEINFO(QDate, Q_MOVABLE_TYPE);
113
class Q_CORE_EXPORT QTime
117
QTime(int h, int m, int s = 0, int ms = 0);
119
bool isNull() const { return ds == 0; }
120
bool isValid() const;
126
#ifndef QT_NO_DATESTRING
127
QString toString(Qt::DateFormat f = Qt::TextDate) const;
128
QString toString(const QString &format) const;
130
bool setHMS(int h, int m, int s, int ms = 0);
132
QTime addSecs(int secs) const;
133
int secsTo(const QTime &) const;
134
QTime addMSecs(int ms) const;
135
int msecsTo(const QTime &) const;
137
bool operator==(const QTime &other) const { return ds == other.ds; }
138
bool operator!=(const QTime &other) const { return ds != other.ds; }
139
bool operator<(const QTime &other) const { return ds < other.ds; }
140
bool operator<=(const QTime &other) const { return ds <= other.ds; }
141
bool operator>(const QTime &other) const { return ds > other.ds; }
142
bool operator>=(const QTime &other) const { return ds >= other.ds; }
144
static QTime currentTime();
145
#ifndef QT_NO_DATESTRING
146
static QTime fromString(const QString &s, Qt::DateFormat f = Qt::TextDate);
148
static QTime fromString(const QString &s, const QString &format);
149
static bool isValid(int h, int m, int s, int ms = 0);
152
static QT3_SUPPORT QTime currentTime(Qt::TimeSpec spec);
153
static QT3_SUPPORT QDate currentDate(Qt::TimeSpec spec);
163
friend class QDateTime;
164
#ifndef QT_NO_DATASTREAM
165
friend Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QTime &);
166
friend Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QTime &);
169
Q_DECLARE_TYPEINFO(QTime, Q_MOVABLE_TYPE);
171
class QDateTimePrivate;
173
class Q_CORE_EXPORT QDateTime
177
explicit QDateTime(const QDate &);
178
QDateTime(const QDate &, const QTime &, Qt::TimeSpec spec = Qt::LocalTime);
179
QDateTime(const QDateTime &other);
182
QDateTime &operator=(const QDateTime &other);
185
bool isValid() const;
189
Qt::TimeSpec timeSpec() const;
190
uint toTime_t() const;
191
void setDate(const QDate &date);
192
void setTime(const QTime &time);
193
void setTimeSpec(Qt::TimeSpec spec);
194
void setTime_t(uint secsSince1Jan1970UTC);
195
#ifndef QT_NO_DATESTRING
196
QString toString(Qt::DateFormat f = Qt::TextDate) const;
197
QString toString(const QString &format) const;
199
QDateTime addDays(int days) const;
200
QDateTime addMonths(int months) const;
201
QDateTime addYears(int years) const;
202
QDateTime addSecs(int secs) const;
203
QDateTime toTimeSpec(Qt::TimeSpec spec) const;
204
inline QDateTime toLocalTime() const { return toTimeSpec(Qt::LocalTime); }
205
inline QDateTime toUTC() const { return toTimeSpec(Qt::UTC); }
206
int daysTo(const QDateTime &) const;
207
int secsTo(const QDateTime &) const;
209
bool operator==(const QDateTime &other) const;
210
inline bool operator!=(const QDateTime &other) const { return !(*this == other); }
211
bool operator<(const QDateTime &other) const;
212
inline bool operator<=(const QDateTime &other) const { return !(other < *this); }
213
inline bool operator>(const QDateTime &other) const { return other < *this; }
214
inline bool operator>=(const QDateTime &other) const { return !(*this < other); }
216
static QDateTime currentDateTime();
217
#ifndef QT_NO_DATESTRING
218
static QDateTime fromString(const QString &s, Qt::DateFormat f = Qt::TextDate);
220
static QDateTime fromString(const QString &s, const QString &format);
223
inline QT3_SUPPORT void setTime_t(uint secsSince1Jan1970UTC, Qt::TimeSpec spec) {
224
setTime_t(secsSince1Jan1970UTC);
228
static inline QT3_SUPPORT QDateTime currentDateTime(Qt::TimeSpec spec) {
229
if (spec == Qt::LocalTime)
230
return currentDateTime();
232
return currentDateTime().toUTC();
240
#ifndef QT_NO_DATASTREAM
241
friend Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QDateTime &);
242
friend Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QDateTime &);
245
Q_DECLARE_TYPEINFO(QDateTime, Q_MOVABLE_TYPE);
248
inline QDate QDate::currentDate(Qt::TimeSpec spec)
250
if (spec == Qt::LocalTime)
251
return currentDate();
253
return QDateTime::currentDateTime().toUTC().date();
256
inline QTime QTime::currentTime(Qt::TimeSpec spec)
258
if (spec == Qt::LocalTime)
259
return currentTime();
261
return QDateTime::currentDateTime().toUTC().time();
265
#ifndef QT_NO_DATASTREAM
266
Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QDate &);
267
Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QDate &);
268
Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QTime &);
269
Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QTime &);
270
Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QDateTime &);
271
Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QDateTime &);
272
#endif // QT_NO_DATASTREAM
274
#ifndef QT_NO_DEBUG_STREAM
275
Q_CORE_EXPORT QDebug operator<<(QDebug, const QDate &);
276
Q_CORE_EXPORT QDebug operator<<(QDebug, const QTime &);
277
Q_CORE_EXPORT QDebug operator<<(QDebug, const QDateTime &);
280
#endif // QDATETIME_H