23 #include <tqdatetime.h>
45 DateTime() : mDateOnly(false), mTimeValid(false) { }
47 DateTime(
const TQDate& d) : mDateTime(d), mDateOnly(true) { }
50 : mDateTime(d, t), mDateOnly(false), mTimeValid(true) { }
55 DateTime(
const TQDateTime& dt,
bool dateOnly =
false)
56 : mDateTime(dt), mDateOnly(dateOnly), mTimeValid(true)
57 {
if (dateOnly) mDateTime.setTime(TQTime()); }
62 { mDateTime = dt.mDateTime; mDateOnly = dt.mDateOnly; mTimeValid = dt.mTimeValid;
return *
this; }
67 { mDateTime = dt; mDateOnly =
false; mTimeValid =
true;
return *
this; }
72 { mDateTime.setDate(d); mDateTime.setTime(TQTime()); mDateOnly =
true;
return *
this; }
74 bool isNull()
const {
return mDateTime.date().isNull() && (mDateOnly || mDateTime.time().isNull()); }
76 bool isValid()
const {
return mDateTime.date().isValid() && (mDateOnly || mTimeValid && mDateTime.time().isValid()); }
82 void setDateOnly(
bool d) {
if (d) mDateTime.setTime(TQTime());
83 else if (mDateOnly) mTimeValid =
false;
87 TQDate
date()
const {
return mDateTime.date(); }
105 void set(
const TQDateTime& dt,
bool dateOnly =
false)
108 mDateOnly = dateOnly;
110 mDateTime.setTime(TQTime());
114 void set(
const TQDate& d,
const TQTime& t)
115 { mDateTime.setDate(d); mDateTime.setTime(t); mDateOnly =
false; mTimeValid =
true; }
119 void setTime(
const TQTime& t) { mDateTime.setTime(t); mDateOnly =
false; mTimeValid =
true; }
124 void setTime_t(uint secs) { mDateTime.setTime_t(secs); mDateOnly =
false; mTimeValid =
true; }
132 return DateTime(mDateTime.date().addDays(n / (3600*24)),
true);
134 return DateTime(mDateTime.addSecs(n),
false);
143 return DateTime(mDateTime.addDays(n / (60*24)),
true);
145 return DateTime(mDateTime.addSecs(n * 60),
false);
155 {
return (mDateOnly || dt.mDateOnly) ? mDateTime.date().daysTo(dt.
date()) : mDateTime.daysTo(dt.mDateTime); }
161 {
return (mDateOnly || dt.mDateOnly) ? mDateTime.date().daysTo(dt.
date()) * 24*60 : mDateTime.secsTo(dt.mDateTime) / 60; }
167 {
return (mDateOnly || dt.mDateOnly) ? mDateTime.date().daysTo(dt.
date()) * 24*3600 : mDateTime.secsTo(dt.mDateTime); }
172 TQString
toString(Qt::DateFormat f = Qt::TextDate)
const
175 return mDateTime.date().toString(f);
177 return mDateTime.toString(f);
188 return mDateTime.date().toString(format);
190 return mDateTime.toString(format);
210 static TQTime mStartOfDay;
211 TQDateTime mDateTime;
224 inline bool operator!=(
const DateTime& dt1,
const DateTime& dt2) {
return !operator==(dt1, dt2); }
229 inline bool operator>(
const DateTime& dt1,
const DateTime& dt2) {
return operator<(dt2, dt1); }
234 inline bool operator>=(
const DateTime& dt1,
const DateTime& dt2) {
return !operator<(dt1, dt2); }
239 inline bool operator<=(
const DateTime& dt1,
const DateTime& dt2) {
return !operator<(dt2, dt1); }