aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Richard <[email protected]>2005-04-22 10:48:41 +0000
committerVincent Richard <[email protected]>2005-04-22 10:48:41 +0000
commite7569f5edb2ebfeba49671b882c242a11246d4be (patch)
treec4ab5d907a84d8941b8acaef031247741faba9f3
parentFixed bug in RFC-2231 implementation. (diff)
downloadvmime-e7569f5edb2ebfeba49671b882c242a11246d4be.tar.gz
vmime-e7569f5edb2ebfeba49671b882c242a11246d4be.zip
Fixed date/time comparisons.
-rw-r--r--src/dateTime.cpp80
1 files changed, 42 insertions, 38 deletions
diff --git a/src/dateTime.cpp b/src/dateTime.cpp
index a2814a9c..d2f0d5b6 100644
--- a/src/dateTime.cpp
+++ b/src/dateTime.cpp
@@ -762,25 +762,29 @@ void datetime::setZone(const int zone) { m_zone = zone; }
const bool datetime::operator==(const datetime& other) const
{
- return (m_year == other.m_year &&
- m_month == other.m_month &&
- m_day == other.m_day &&
- m_hour == other.m_hour &&
- m_minute == other.m_minute &&
- m_second == other.m_second &&
- m_zone == other.m_zone);
+ const datetime ut1 = utility::datetimeUtils::localTimeToUniversalTime(*this);
+ const datetime ut2 = utility::datetimeUtils::localTimeToUniversalTime(other);
+
+ return (ut1.m_year == ut2.m_year &&
+ ut1.m_month == ut2.m_month &&
+ ut1.m_day == ut2.m_day &&
+ ut1.m_hour == ut2.m_hour &&
+ ut1.m_minute == ut2.m_minute &&
+ ut1.m_second == ut2.m_second);
}
const bool datetime::operator!=(const datetime& other) const
{
- return (m_year != other.m_year ||
- m_month != other.m_month ||
- m_day != other.m_day ||
- m_hour != other.m_hour ||
- m_minute != other.m_minute ||
- m_second != other.m_second ||
- m_zone != other.m_zone);
+ const datetime ut1 = utility::datetimeUtils::localTimeToUniversalTime(*this);
+ const datetime ut2 = utility::datetimeUtils::localTimeToUniversalTime(other);
+
+ return (ut1.m_year != ut2.m_year ||
+ ut1.m_month != ut2.m_month ||
+ ut1.m_day != ut2.m_day ||
+ ut1.m_hour != ut2.m_hour ||
+ ut1.m_minute != ut2.m_minute ||
+ ut1.m_second != ut2.m_second);
}
@@ -789,12 +793,12 @@ const bool datetime::operator<(const datetime& other) const
const datetime ut1 = utility::datetimeUtils::localTimeToUniversalTime(*this);
const datetime ut2 = utility::datetimeUtils::localTimeToUniversalTime(other);
- return (ut1.m_year < ut2.m_year &&
- ut1.m_month < ut2.m_month &&
- ut1.m_day < ut2.m_day &&
- ut1.m_hour < ut2.m_hour &&
- ut1.m_minute < ut2.m_minute &&
- ut1.m_second < ut2.m_second);
+ return ((ut1.m_year < ut2.m_year) ||
+ (ut1.m_year == ut2.m_year && ut1.m_month < ut2.m_month) ||
+ (ut1.m_month == ut2.m_month && ut1.m_day < ut2.m_day) ||
+ (ut1.m_day == ut2.m_day && ut1.m_hour < ut2.m_hour) ||
+ (ut1.m_hour == ut2.m_hour && ut1.m_minute < ut2.m_minute) ||
+ (ut1.m_minute == ut2.m_minute && ut1.m_second < ut2.m_second));
}
@@ -803,12 +807,12 @@ const bool datetime::operator<=(const datetime& other) const
const datetime ut1 = utility::datetimeUtils::localTimeToUniversalTime(*this);
const datetime ut2 = utility::datetimeUtils::localTimeToUniversalTime(other);
- return (ut1.m_year <= ut2.m_year &&
- ut1.m_month <= ut2.m_month &&
- ut1.m_day <= ut2.m_day &&
- ut1.m_hour <= ut2.m_hour &&
- ut1.m_minute <= ut2.m_minute &&
- ut1.m_second <= ut2.m_second);
+ return ((ut1.m_year < ut2.m_year) ||
+ (ut1.m_year == ut2.m_year && ut1.m_month < ut2.m_month) ||
+ (ut1.m_month == ut2.m_month && ut1.m_day < ut2.m_day) ||
+ (ut1.m_day == ut2.m_day && ut1.m_hour < ut2.m_hour) ||
+ (ut1.m_hour == ut2.m_hour && ut1.m_minute < ut2.m_minute) ||
+ (ut1.m_minute == ut2.m_minute && ut1.m_second <= ut2.m_second));
}
@@ -817,12 +821,12 @@ const bool datetime::operator>(const datetime& other) const
const datetime ut1 = utility::datetimeUtils::localTimeToUniversalTime(*this);
const datetime ut2 = utility::datetimeUtils::localTimeToUniversalTime(other);
- return (ut1.m_year > ut2.m_year &&
- ut1.m_month > ut2.m_month &&
- ut1.m_day > ut2.m_day &&
- ut1.m_hour > ut2.m_hour &&
- ut1.m_minute > ut2.m_minute &&
- ut1.m_second > ut2.m_second);
+ return ((ut1.m_year > ut2.m_year) ||
+ (ut1.m_year == ut2.m_year && ut1.m_month > ut2.m_month) ||
+ (ut1.m_month == ut2.m_month && ut1.m_day > ut2.m_day) ||
+ (ut1.m_day == ut2.m_day && ut1.m_hour > ut2.m_hour) ||
+ (ut1.m_hour == ut2.m_hour && ut1.m_minute > ut2.m_minute) ||
+ (ut1.m_minute == ut2.m_minute && ut1.m_second > ut2.m_second));
}
@@ -831,12 +835,12 @@ const bool datetime::operator>=(const datetime& other) const
const datetime ut1 = utility::datetimeUtils::localTimeToUniversalTime(*this);
const datetime ut2 = utility::datetimeUtils::localTimeToUniversalTime(other);
- return (ut1.m_year >= ut2.m_year &&
- ut1.m_month >= ut2.m_month &&
- ut1.m_day >= ut2.m_day &&
- ut1.m_hour >= ut2.m_hour &&
- ut1.m_minute >= ut2.m_minute &&
- ut1.m_second >= ut2.m_second);
+ return ((ut1.m_year > ut2.m_year) ||
+ (ut1.m_year == ut2.m_year && ut1.m_month > ut2.m_month) ||
+ (ut1.m_month == ut2.m_month && ut1.m_day > ut2.m_day) ||
+ (ut1.m_day == ut2.m_day && ut1.m_hour > ut2.m_hour) ||
+ (ut1.m_hour == ut2.m_hour && ut1.m_minute > ut2.m_minute) ||
+ (ut1.m_minute == ut2.m_minute && ut1.m_second >= ut2.m_second));
}