2
* datetime.cpp - date/time with start-of-day time for date-only values
4
* Copyright © 2003,2005-2007,2009,2010 by David Jarvie <djarvie@kde.org>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License along
17
* with this program; if not, write to the Free Software Foundation, Inc.,
18
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26
QTime DateTime::mStartOfDay;
28
QTime DateTime::effectiveTime() const
30
return mDateTime.isDateOnly() ? mStartOfDay : mDateTime.time();
33
QDateTime DateTime::effectiveDateTime() const
35
if (mDateTime.isDateOnly())
37
QDateTime dt = mDateTime.dateTime(); // preserve Qt::UTC or Qt::LocalTime
38
dt.setTime(mStartOfDay);
41
return mDateTime.dateTime();
44
KDateTime DateTime::effectiveKDateTime() const
46
if (mDateTime.isDateOnly())
48
KDateTime dt = mDateTime;
49
dt.setTime(mStartOfDay);
55
KDateTime DateTime::calendarKDateTime() const
57
if (mDateTime.isDateOnly())
59
KDateTime dt = mDateTime;
60
dt.setTime(QTime(0, 0));
66
QString DateTime::formatLocale(bool shortFormat) const
68
return KGlobal::locale()->formatDateTime(mDateTime, (shortFormat ? KLocale::ShortDate : KLocale::LongDate));
71
bool operator<(const DateTime& dt1, const DateTime& dt2)
73
if (dt1.isDateOnly() && !dt2.isDateOnly())
75
KDateTime dt = dt1.mDateTime.addDays(1);
76
dt.setTime(DateTime::mStartOfDay);
77
return dt <= dt2.mDateTime;
79
if (!dt1.isDateOnly() && dt2.isDateOnly())
81
KDateTime dt = dt2.mDateTime;
82
dt.setTime(DateTime::mStartOfDay);
83
return dt1.mDateTime < dt;
85
return dt1.mDateTime < dt2.mDateTime;