qdatetime.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 **
4 ** Definition of date and time classes
5 **
6 ** Created : 940124
7 **
8 ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
9 **
10 ** This file is part of the tools module of the Qt GUI Toolkit.
11 **
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.
15 **
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.
20 **
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.
24 **
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.
27 **
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.
32 **
33 ** Contact info@trolltech.com if any conditions of this licensing are
34 ** not clear to you.
35 **
36 **********************************************************************/
37 
38 #ifndef QDATETIME_H
39 #define QDATETIME_H
40 
41 #ifndef QT_H
42 #include "qstring.h"
43 #endif // QT_H
44 
45 
46 /*****************************************************************************
47  QDate class
48  *****************************************************************************/
49 
51 {
52 public:
53  QDate() { jd=0; } // set null date
54  QDate( int y, int m, int d ); // set date
55  virtual ~QDate() {}
56 
57  bool isNull() const { return jd == 0; }
58  bool isValid() const; // valid date
59 
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
67 
68  virtual QString monthName( int month ) const;
69  virtual QString dayName( int weekday ) const;
70 
71  QString toString() const;
72 
73  bool setYMD( int y, int m, int d );
74 
75  QDate addDays( int days ) const;
76  int daysTo( const QDate & ) const;
77 
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; }
84 
85  static QDate currentDate();
86  static bool isValid( int y, int m, int d );
87  static bool leapYear( int year );
88 
89 protected:
90  static uint greg2jul( int y, int m, int d );
91  static void jul2greg( uint jd, int &y, int &m, int &d );
92 private:
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 & );
100 #endif
101 };
102 
103 
104 /*****************************************************************************
105  QTime class
106  *****************************************************************************/
107 
109 {
110 public:
111  QTime() { ds=0; } // set null time
112  QTime( int h, int m, int s=0, int ms=0 ); // set time
113 
114  bool isNull() const { return ds == 0; }
115  bool isValid() const; // valid time
116 
117  int hour() const; // 0..23
118  int minute() const; // 0..59
119  int second() const; // 0..59
120  int msec() const; // 0..999
121 
122  QString toString() const;
123 
124  bool setHMS( int h, int m, int s, int ms=0 );
125 
126  QTime addSecs( int secs ) const;
127  int secsTo( const QTime & ) const;
128  QTime addMSecs( int ms ) const;
129  int msecsTo( const QTime & ) const;
130 
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; }
137 
138  static QTime currentTime();
139  static bool isValid( int h, int m, int s, int ms=0 );
140 
141  void start();
142  int restart();
143  int elapsed();
144 
145 private:
146  static bool currentTime( QTime * );
147 
149  friend class QDateTime;
150 #ifndef QT_NO_DATASTREAM
151  friend Q_EXPORT QDataStream &operator<<( QDataStream &, const QTime & );
153 #endif
154 };
155 
156 
157 /*****************************************************************************
158  QDateTime class
159  *****************************************************************************/
160 
162 {
163 public:
164  QDateTime() {} // set null date and null time
165  QDateTime( const QDate & );
166  QDateTime( const QDate &, const QTime & );
167 
168  bool isNull() const { return d.isNull() && t.isNull(); }
169  bool isValid() const { return d.isValid() && t.isValid(); }
170 
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 );
176 
177  QString toString() const;
178 
179  QDateTime addDays( int days ) const;
180  QDateTime addSecs( int secs ) const;
181  int daysTo( const QDateTime & ) const;
182  int secsTo( const QDateTime & ) const;
183 
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;
190 
191  static QDateTime currentDateTime();
192 
193 private:
196 #ifndef QT_NO_DATASTREAM
197  friend Q_EXPORT QDataStream &operator<<( QDataStream &, const QDateTime &);
199 #endif
200 };
201 
202 
203 /*****************************************************************************
204  Date and time stream functions
205  *****************************************************************************/
206 
207 #ifndef QT_NO_DATASTREAM
214 #endif // QT_NO_DATASTREAM
215 
216 #endif // QDATETIME_H
QDate d
Definition: qdatetime.h:194
bool isNull() const
Definition: qdatetime.h:168
QTime t
Definition: qdatetime.h:195
uint ds
Definition: qdatetime.h:148
bool operator>(ScheduleID const left, ScheduleID const right) noexcept
Definition: ScheduleID.cc:53
QTime time() const
Definition: qdatetime.h:172
bool isNull() const
Definition: qdatetime.h:114
The QDate class provides date functions.
Definition: qdatetime.h:50
QDate()
Definition: qdatetime.h:53
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
Q_EXPORT QDataStream & operator>>(QDataStream &, QDate &)
bool operator!=(ModuleKeyAndType const &a, ModuleKeyAndType const &b) noexcept
virtual ~QDate()
Definition: qdatetime.h:55
static constexpr double ms
Definition: Units.h:96
The QTime class provides clock time functions.
Definition: qdatetime.h:108
bool operator<(ProductInfo const &a, ProductInfo const &b)
Definition: ProductInfo.cc:51
bool operator<=(ScheduleID const left, ScheduleID const right) noexcept
Definition: ScheduleID.cc:47
void setDate(const QDate &date)
Definition: qdatetime.h:173
void setTime(const QTime &time)
Definition: qdatetime.h:174
bool operator>(const QDate &d) const
Definition: qdatetime.h:82
bool operator>=(const QDate &d) const
Definition: qdatetime.h:83
QTime()
Definition: qdatetime.h:111
bool isValid() const
Definition: qdatetime.h:169
bool operator==(const QTime &d) const
Definition: qdatetime.h:131
bool operator!=(const QTime &d) const
Definition: qdatetime.h:132
string toString(const TVector3 &xyz, int w=9)
The QDateTime class provides date and time functions.
Definition: qdatetime.h:161
QDate date() const
Definition: qdatetime.h:171
bool operator<(const QTime &d) const
Definition: qdatetime.h:133
bool operator>(const QTime &d) const
Definition: qdatetime.h:135
bool operator<=(const QTime &d) const
Definition: qdatetime.h:134
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:47
bool operator==(const QDate &d) const
Definition: qdatetime.h:78
bool operator>=(ScheduleID const left, ScheduleID const right) noexcept
Definition: ScheduleID.cc:59
uint jd
Definition: qdatetime.h:95
bool operator<=(const QDate &d) const
Definition: qdatetime.h:81
bool isNull() const
Definition: qdatetime.h:57
bool operator<(const QDate &d) const
Definition: qdatetime.h:80
second_as<> second
Type of time stored in seconds, in double precision.
Definition: spacetime.h:85
Q_EXPORT QDataStream & operator<<(QDataStream &, const QDate &)
unsigned uint
Definition: qglobal.h:351
static QCString * s
Definition: config.cpp:1042
#define Q_EXPORT
Definition: qglobal.h:468
bool operator>=(const QTime &d) const
Definition: qdatetime.h:136
bool operator==(ModuleKeyAndType const &a, ModuleKeyAndType const &b) noexcept
bool operator!=(const QDate &d) const
Definition: qdatetime.h:79