1 /****************************************************************************
4 ** Definition of date and time classes
8 ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
10 ** This file is part of the tools module of the Qt GUI Toolkit.
12 ** This file may be distributed under the terms of the Q Public License
13 ** as defined by Trolltech AS of Norway and appearing in the file
14 ** LICENSE.QPL included in the packaging of this file.
16 ** This file may be distributed and/or modified under the terms of the
17 ** GNU General Public License version 2 as published by the Free Software
18 ** Foundation and appearing in the file LICENSE.GPL included in the
19 ** packaging of this file.
21 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22 ** licenses may use this file in accordance with the Qt Commercial License
23 ** Agreement provided with the Software.
25 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
28 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29 ** information about Qt Commercial License Agreements.
30 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
31 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
33 ** Contact info@trolltech.com if any conditions of this licensing are
36 **********************************************************************/
46 /*****************************************************************************
48 *****************************************************************************/
53 QDate() { jd=0; } // set null date
54 QDate( int y, int m, int d ); // set date
57 bool isNull() const { return jd == 0; }
58 bool isValid() const; // valid date
60 int year() const; // 1752..
61 int month() const; // 1..12
62 int day() const; // 1..31
63 int dayOfWeek() const; // 1..7 (monday==1)
64 int dayOfYear() const; // 1..365
65 int daysInMonth() const; // 28..31
66 int daysInYear() const; // 365 or 366
68 virtual QString monthName( int month ) const;
69 virtual QString dayName( int weekday ) const;
71 QString toString() const;
73 bool setYMD( int y, int m, int d );
75 QDate addDays( int days ) const;
76 int daysTo( const QDate & ) const;
78 bool operator==( const QDate &d ) const { return jd == d.jd; }
79 bool operator!=( const QDate &d ) const { return jd != d.jd; }
80 bool operator<( const QDate &d ) const { return jd < d.jd; }
81 bool operator<=( const QDate &d ) const { return jd <= d.jd; }
82 bool operator>( const QDate &d ) const { return jd > d.jd; }
83 bool operator>=( const QDate &d ) const { return jd >= d.jd; }
85 static QDate currentDate();
86 static bool isValid( int y, int m, int d );
87 static bool leapYear( int year );
90 static uint greg2jul( int y, int m, int d );
91 static void jul2greg( uint jd, int &y, int &m, int &d );
93 static const char * const monthNames[];
94 static const char * const weekdayNames[];
96 friend class QDateTime;
97 #ifndef QT_NO_DATASTREAM
98 friend Q_EXPORT QDataStream &operator<<( QDataStream &, const QDate & );
99 friend Q_EXPORT QDataStream &operator>>( QDataStream &, QDate & );
104 /*****************************************************************************
106 *****************************************************************************/
111 QTime() { ds=0; } // set null time
112 QTime( int h, int m, int s=0, int ms=0 ); // set time
114 bool isNull() const { return ds == 0; }
115 bool isValid() const; // valid time
117 int hour() const; // 0..23
118 int minute() const; // 0..59
119 int second() const; // 0..59
120 int msec() const; // 0..999
122 QString toString() const;
124 bool setHMS( int h, int m, int s, int ms=0 );
126 QTime addSecs( int secs ) const;
127 int secsTo( const QTime & ) const;
128 QTime addMSecs( int ms ) const;
129 int msecsTo( const QTime & ) const;
131 bool operator==( const QTime &d ) const { return ds == d.ds; }
132 bool operator!=( const QTime &d ) const { return ds != d.ds; }
133 bool operator<( const QTime &d ) const { return ds < d.ds; }
134 bool operator<=( const QTime &d ) const { return ds <= d.ds; }
135 bool operator>( const QTime &d ) const { return ds > d.ds; }
136 bool operator>=( const QTime &d ) const { return ds >= d.ds; }
138 static QTime currentTime();
139 static bool isValid( int h, int m, int s, int ms=0 );
146 static bool currentTime( QTime * );
149 friend class QDateTime;
150 #ifndef QT_NO_DATASTREAM
151 friend Q_EXPORT QDataStream &operator<<( QDataStream &, const QTime & );
152 friend Q_EXPORT QDataStream &operator>>( QDataStream &, QTime & );
157 /*****************************************************************************
159 *****************************************************************************/
161 class Q_EXPORT QDateTime
164 QDateTime() {} // set null date and null time
165 QDateTime( const QDate & );
166 QDateTime( const QDate &, const QTime & );
168 bool isNull() const { return d.isNull() && t.isNull(); }
169 bool isValid() const { return d.isValid() && t.isValid(); }
171 QDate date() const { return d; }
172 QTime time() const { return t; }
173 void setDate( const QDate &date ) { d=date; }
174 void setTime( const QTime &time ) { t=time; }
175 void setTime_t( uint secsSince1Jan1970UTC );
177 QString toString() const;
179 QDateTime addDays( int days ) const;
180 QDateTime addSecs( int secs ) const;
181 int daysTo( const QDateTime & ) const;
182 int secsTo( const QDateTime & ) const;
184 bool operator==( const QDateTime &dt ) const;
185 bool operator!=( const QDateTime &dt ) const;
186 bool operator<( const QDateTime &dt ) const;
187 bool operator<=( const QDateTime &dt ) const;
188 bool operator>( const QDateTime &dt ) const;
189 bool operator>=( const QDateTime &dt ) const;
191 static QDateTime currentDateTime();
196 #ifndef QT_NO_DATASTREAM
197 friend Q_EXPORT QDataStream &operator<<( QDataStream &, const QDateTime &);
198 friend Q_EXPORT QDataStream &operator>>( QDataStream &, QDateTime & );
203 /*****************************************************************************
204 Date and time stream functions
205 *****************************************************************************/
207 #ifndef QT_NO_DATASTREAM
208 Q_EXPORT QDataStream &operator<<( QDataStream &, const QDate & );
209 Q_EXPORT QDataStream &operator>>( QDataStream &, QDate & );
210 Q_EXPORT QDataStream &operator<<( QDataStream &, const QTime & );
211 Q_EXPORT QDataStream &operator>>( QDataStream &, QTime & );
212 Q_EXPORT QDataStream &operator<<( QDataStream &, const QDateTime & );
213 Q_EXPORT QDataStream &operator>>( QDataStream &, QDateTime & );
214 #endif // QT_NO_DATASTREAM
216 #endif // QDATETIME_H