Eneboo - Documentación para desarrolladores
|
00001 /************************************************************************* 00002 ** $Id: qt/qdatetime.h 3.3.8 edited Jan 11 14:38 $ 00003 ** 00004 ** Definition of date and time classes 00005 ** 00006 ** Created : 940124 00007 ** 00008 ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved. 00009 ** 00010 ** This file is part of the tools module of the Qt GUI Toolkit. 00011 ** 00012 ** This file may be distributed under the terms of the Q Public License 00013 ** as defined by Trolltech ASA of Norway and appearing in the file 00014 ** LICENSE.QPL included in the packaging of this file. 00015 ** 00016 ** This file may be distributed and/or modified under the terms of the 00017 ** GNU General Public License version 2 as published by the Free Software 00018 ** Foundation and appearing in the file LICENSE.GPL included in the 00019 ** packaging of this file. 00020 ** 00021 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition 00022 ** licenses may use this file in accordance with the Qt Commercial License 00023 ** Agreement provided with the Software. 00024 ** 00025 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00026 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00027 ** 00028 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for 00029 ** information about Qt Commercial License Agreements. 00030 ** See http://www.trolltech.com/qpl/ for QPL licensing information. 00031 ** See http://www.trolltech.com/gpl/ for GPL licensing information. 00032 ** 00033 ** Contact info@trolltech.com if any conditions of this licensing are 00034 ** not clear to you. 00035 ** 00036 **********************************************************************/ 00037 00038 #ifndef QDATETIME_H 00039 #define QDATETIME_H 00040 00041 #ifndef QT_H 00042 #include "qstring.h" 00043 #include "qnamespace.h" 00044 #endif // QT_H 00045 00046 00047 /***************************************************************************** 00048 QDate class 00049 *****************************************************************************/ 00050 00051 class Q_EXPORT QDate 00052 { 00053 public: 00054 QDate() { jd = 0; } 00055 QDate( int y, int m, int d ); 00056 00057 bool isNull() const { return jd == 0; } 00058 bool isValid() const; 00059 00060 int year() const; 00061 int month() const; 00062 int day() const; 00063 int dayOfWeek() const; 00064 int dayOfYear() const; 00065 int daysInMonth() const; 00066 int daysInYear() const; 00067 int weekNumber( int *yearNum = 0 ) const; 00068 00069 #ifndef QT_NO_TEXTDATE 00070 #ifndef QT_NO_COMPAT 00071 static QString monthName( int month ) { return shortMonthName( month ); } 00072 static QString dayName( int weekday ) { return shortDayName( weekday ); } 00073 #endif 00074 static QString shortMonthName( int month ); 00075 static QString shortDayName( int weekday ); 00076 static QString longMonthName( int month ); 00077 static QString longDayName( int weekday ); 00078 #endif //QT_NO_TEXTDATE 00079 #ifndef QT_NO_TEXTSTRING 00080 #if !defined(QT_NO_SPRINTF) 00081 QString toString( Qt::DateFormat f = Qt::TextDate ) const; 00082 #endif 00083 QString toString( const QString& format ) const; 00084 #endif 00085 bool setYMD( int y, int m, int d ); 00086 00087 QDate addDays( int days ) const; 00088 QDate addMonths( int months ) const; 00089 QDate addYears( int years ) const; 00090 int daysTo( const QDate & ) const; 00091 00092 bool operator==( const QDate &d ) const { return jd == d.jd; } 00093 bool operator!=( const QDate &d ) const { return jd != d.jd; } 00094 bool operator<( const QDate &d ) const { return jd < d.jd; } 00095 bool operator<=( const QDate &d ) const { return jd <= d.jd; } 00096 bool operator>( const QDate &d ) const { return jd > d.jd; } 00097 bool operator>=( const QDate &d ) const { return jd >= d.jd; } 00098 00099 static QDate currentDate(); 00100 static QDate currentDate( Qt::TimeSpec ); 00101 #ifndef QT_NO_DATESTRING 00102 static QDate fromString( const QString& s, Qt::DateFormat f = Qt::TextDate ); 00103 #endif 00104 static bool isValid( int y, int m, int d ); 00105 static bool leapYear( int year ); 00106 00107 static uint gregorianToJulian( int y, int m, int d ); 00108 static void julianToGregorian( uint jd, int &y, int &m, int &d ); 00109 private: 00110 uint jd; 00111 friend class QDateTime; 00112 #ifndef QT_NO_DATASTREAM 00113 friend Q_EXPORT QDataStream &operator<<( QDataStream &, const QDate & ); 00114 friend Q_EXPORT QDataStream &operator>>( QDataStream &, QDate & ); 00115 #endif 00116 }; 00117 00118 00119 /***************************************************************************** 00120 QTime class 00121 *****************************************************************************/ 00122 00123 class Q_EXPORT QTime 00124 { 00125 public: 00126 QTime() { ds=0; } // set null time 00127 QTime( int h, int m, int s=0, int ms=0 ); // set time 00128 00129 bool isNull() const { return ds == 0; } 00130 bool isValid() const; // valid time 00131 00132 int hour() const; // 0..23 00133 int minute() const; // 0..59 00134 int second() const; // 0..59 00135 int msec() const; // 0..999 00136 #ifndef QT_NO_DATESTRING 00137 #ifndef QT_NO_SPRINTF 00138 QString toString( Qt::DateFormat f = Qt::TextDate ) const; 00139 #endif 00140 QString toString( const QString& format ) const; 00141 #endif 00142 bool setHMS( int h, int m, int s, int ms=0 ); 00143 00144 QTime addSecs( int secs ) const; 00145 int secsTo( const QTime & ) const; 00146 QTime addMSecs( int ms ) const; 00147 int msecsTo( const QTime & ) const; 00148 00149 bool operator==( const QTime &d ) const { return ds == d.ds; } 00150 bool operator!=( const QTime &d ) const { return ds != d.ds; } 00151 bool operator<( const QTime &d ) const { return ds < d.ds; } 00152 bool operator<=( const QTime &d ) const { return ds <= d.ds; } 00153 bool operator>( const QTime &d ) const { return ds > d.ds; } 00154 bool operator>=( const QTime &d ) const { return ds >= d.ds; } 00155 00156 static QTime currentTime(); 00157 static QTime currentTime( Qt::TimeSpec ); 00158 #ifndef QT_NO_DATESTRING 00159 static QTime fromString( const QString& s, Qt::DateFormat f = Qt::TextDate ); 00160 #endif 00161 static bool isValid( int h, int m, int s, int ms=0 ); 00162 00163 void start(); 00164 int restart(); 00165 int elapsed() const; 00166 00167 private: 00168 static bool currentTime( QTime * ); 00169 static bool currentTime( QTime *, Qt::TimeSpec ); 00170 00171 uint ds; 00172 friend class QDateTime; 00173 #ifndef QT_NO_DATASTREAM 00174 friend Q_EXPORT QDataStream &operator<<( QDataStream &, const QTime & ); 00175 friend Q_EXPORT QDataStream &operator>>( QDataStream &, QTime & ); 00176 #endif 00177 }; 00178 00179 00180 /***************************************************************************** 00181 QDateTime class 00182 *****************************************************************************/ 00183 00184 class Q_EXPORT QDateTime 00185 { 00186 public: 00187 QDateTime() {} // set null date and null time 00188 QDateTime( const QDate & ); 00189 QDateTime( const QDate &, const QTime & ); 00190 00191 bool isNull() const { return d.isNull() && t.isNull(); } 00192 bool isValid() const { return d.isValid() && t.isValid(); } 00193 00194 QDate date() const { return d; } 00195 QTime time() const { return t; } 00196 uint toTime_t() const; 00197 void setDate( const QDate &date ) { d = date; } 00198 void setTime( const QTime &time ) { t = time; } 00199 void setTime_t( uint secsSince1Jan1970UTC ); 00200 void setTime_t( uint secsSince1Jan1970UTC, Qt::TimeSpec ); 00201 #ifndef QT_NO_DATESTRING 00202 #ifndef QT_NO_SPRINTF 00203 QString toString( Qt::DateFormat f = Qt::TextDate ) const; 00204 #endif 00205 QString toString( const QString& format ) const; 00206 #endif 00207 QDateTime addDays( int days ) const; 00208 QDateTime addMonths( int months ) const; 00209 QDateTime addYears( int years ) const; 00210 QDateTime addSecs( int secs ) const; 00211 int daysTo( const QDateTime & ) const; 00212 int secsTo( const QDateTime & ) const; 00213 00214 bool operator==( const QDateTime &dt ) const; 00215 bool operator!=( const QDateTime &dt ) const; 00216 bool operator<( const QDateTime &dt ) const; 00217 bool operator<=( const QDateTime &dt ) const; 00218 bool operator>( const QDateTime &dt ) const; 00219 bool operator>=( const QDateTime &dt ) const; 00220 00221 static QDateTime currentDateTime(); 00222 static QDateTime currentDateTime( Qt::TimeSpec ); 00223 #ifndef QT_NO_DATESTRING 00224 static QDateTime fromString( const QString& s, Qt::DateFormat f = Qt::TextDate ); 00225 #endif 00226 private: 00227 QDate d; 00228 QTime t; 00229 #ifndef QT_NO_DATASTREAM 00230 friend Q_EXPORT QDataStream &operator<<( QDataStream &, const QDateTime &); 00231 friend Q_EXPORT QDataStream &operator>>( QDataStream &, QDateTime & ); 00232 #endif 00233 }; 00234 00235 00236 /***************************************************************************** 00237 Date and time stream functions 00238 *****************************************************************************/ 00239 00240 #ifndef QT_NO_DATASTREAM 00241 Q_EXPORT QDataStream &operator<<( QDataStream &, const QDate & ); 00242 Q_EXPORT QDataStream &operator>>( QDataStream &, QDate & ); 00243 Q_EXPORT QDataStream &operator<<( QDataStream &, const QTime & ); 00244 Q_EXPORT QDataStream &operator>>( QDataStream &, QTime & ); 00245 Q_EXPORT QDataStream &operator<<( QDataStream &, const QDateTime & ); 00246 Q_EXPORT QDataStream &operator>>( QDataStream &, QDateTime & ); 00247 #endif // QT_NO_DATASTREAM 00248 00249 #endif // QDATETIME_H 00250