diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 (patch) | |
tree | 67208f7c145782a7e90b123b982ca78d88cc2c87 /kalarm/lib/datetime.cpp | |
download | tdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.tar.gz tdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kalarm/lib/datetime.cpp')
-rw-r--r-- | kalarm/lib/datetime.cpp | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/kalarm/lib/datetime.cpp b/kalarm/lib/datetime.cpp new file mode 100644 index 000000000..d7f5ee862 --- /dev/null +++ b/kalarm/lib/datetime.cpp @@ -0,0 +1,80 @@ +/* + * datetime.cpp - date/time representation with optional date-only value + * Program: kalarm + * Copyright (C) 2003, 2005 by David Jarvie <software@astrojar.org.uk> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#include "kalarm.h" + +#include <kglobal.h> +#include <klocale.h> + +#include "datetime.h" + +QTime DateTime::mStartOfDay; + +QTime DateTime::time() const +{ + return mDateOnly ? mStartOfDay : mDateTime.time(); +} + +QDateTime DateTime::dateTime() const +{ + return mDateOnly ? QDateTime(mDateTime.date(), mStartOfDay) : mDateTime; +} + +QString DateTime::formatLocale(bool shortFormat) const +{ + if (mDateOnly) + return KGlobal::locale()->formatDate(mDateTime.date(), shortFormat); + else if (mTimeValid) + return KGlobal::locale()->formatDateTime(mDateTime, shortFormat); + else + return QString::null; +} + +bool operator==(const DateTime& dt1, const DateTime& dt2) +{ + if (dt1.mDateTime.date() != dt2.mDateTime.date()) + return false; + if (dt1.mDateOnly && dt2.mDateOnly) + return true; + if (!dt1.mDateOnly && !dt2.mDateOnly) + { + bool valid1 = dt1.mTimeValid && dt1.mDateTime.time().isValid(); + bool valid2 = dt2.mTimeValid && dt2.mDateTime.time().isValid(); + if (!valid1 && !valid2) + return true; + if (!valid1 || !valid2) + return false; + return dt1.mDateTime.time() == dt2.mDateTime.time(); + } + return (dt1.mDateOnly ? dt2.mDateTime.time() : dt1.mDateTime.time()) == DateTime::startOfDay(); +} + +bool operator<(const DateTime& dt1, const DateTime& dt2) +{ + if (dt1.mDateTime.date() != dt2.mDateTime.date()) + return dt1.mDateTime.date() < dt2.mDateTime.date(); + if (dt1.mDateOnly && dt2.mDateOnly) + return false; + if (!dt1.mDateOnly && !dt2.mDateOnly) + return dt1.mDateTime.time() < dt2.mDateTime.time(); + QTime t = DateTime::startOfDay(); + if (dt1.mDateOnly) + return t < dt2.mDateTime.time(); + return dt1.mDateTime.time() < t; +} |