mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Add comparison operators for GncDate
Note the operands are const GncDate& because the GncDate has no copy constructor/assigment operator (any other definition would fail when used with variables of type boost::optional<GncDate>)
This commit is contained in:
parent
1a3595cbeb
commit
5070037314
@ -213,6 +213,12 @@ private:
|
|||||||
Date m_greg;
|
Date m_greg;
|
||||||
|
|
||||||
friend GncDateTimeImpl::GncDateTimeImpl(const GncDateImpl&, DayPart);
|
friend GncDateTimeImpl::GncDateTimeImpl(const GncDateImpl&, DayPart);
|
||||||
|
friend bool operator<(const GncDateImpl&, const GncDateImpl&);
|
||||||
|
friend bool operator>(const GncDateImpl&, const GncDateImpl&);
|
||||||
|
friend bool operator==(const GncDateImpl&, const GncDateImpl&);
|
||||||
|
friend bool operator<=(const GncDateImpl&, const GncDateImpl&);
|
||||||
|
friend bool operator>=(const GncDateImpl&, const GncDateImpl&);
|
||||||
|
friend bool operator!=(const GncDateImpl&, const GncDateImpl&);
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Member function definitions for GncDateTimeImpl.
|
/* Member function definitions for GncDateTimeImpl.
|
||||||
@ -427,6 +433,13 @@ GncDateImpl::format(const char* format) const
|
|||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool operator<(const GncDateImpl& a, const GncDateImpl& b) { return a.m_greg < b.m_greg; }
|
||||||
|
bool operator>(const GncDateImpl& a, const GncDateImpl& b) { return a.m_greg > b.m_greg; }
|
||||||
|
bool operator==(const GncDateImpl& a, const GncDateImpl& b) { return a.m_greg == b.m_greg; }
|
||||||
|
bool operator<=(const GncDateImpl& a, const GncDateImpl& b) { return a.m_greg <= b.m_greg; }
|
||||||
|
bool operator>=(const GncDateImpl& a, const GncDateImpl& b) { return a.m_greg >= b.m_greg; }
|
||||||
|
bool operator!=(const GncDateImpl& a, const GncDateImpl& b) { return a.m_greg != b.m_greg; }
|
||||||
|
|
||||||
/* =================== Presentation-class Implementations ====================*/
|
/* =================== Presentation-class Implementations ====================*/
|
||||||
/* GncDateTime */
|
/* GncDateTime */
|
||||||
|
|
||||||
@ -519,3 +532,10 @@ GncDate::year_month_day() const
|
|||||||
{
|
{
|
||||||
return m_impl->year_month_day();
|
return m_impl->year_month_day();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool operator<(const GncDate& a, const GncDate& b) { return *(a.m_impl) < *(b.m_impl); }
|
||||||
|
bool operator>(const GncDate& a, const GncDate& b) { return *(a.m_impl) > *(b.m_impl); }
|
||||||
|
bool operator==(const GncDate& a, const GncDate& b) { return *(a.m_impl) == *(b.m_impl); }
|
||||||
|
bool operator<=(const GncDate& a, const GncDate& b) { return *(a.m_impl) <= *(b.m_impl); }
|
||||||
|
bool operator>=(const GncDate& a, const GncDate& b) { return *(a.m_impl) >= *(b.m_impl); }
|
||||||
|
bool operator!=(const GncDate& a, const GncDate& b) { return *(a.m_impl) != *(b.m_impl); }
|
||||||
|
@ -270,6 +270,23 @@ private:
|
|||||||
std::unique_ptr<GncDateImpl> m_impl;
|
std::unique_ptr<GncDateImpl> m_impl;
|
||||||
|
|
||||||
friend GncDateTime::GncDateTime(const GncDate&, DayPart);
|
friend GncDateTime::GncDateTime(const GncDate&, DayPart);
|
||||||
|
friend bool operator<(const GncDate&, const GncDate&);
|
||||||
|
friend bool operator>(const GncDate&, const GncDate&);
|
||||||
|
friend bool operator==(const GncDate&, const GncDate&);
|
||||||
|
friend bool operator<=(const GncDate&, const GncDate&);
|
||||||
|
friend bool operator>=(const GncDate&, const GncDate&);
|
||||||
|
friend bool operator!=(const GncDate&, const GncDate&);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**@{
|
||||||
|
* Standard comparison operators working on GncDate objects.
|
||||||
|
*/
|
||||||
|
bool operator<(const GncDate& a, const GncDate& b);
|
||||||
|
bool operator>(const GncDate& a, const GncDate& b);
|
||||||
|
bool operator==(const GncDate& a, const GncDate& b);
|
||||||
|
bool operator<=(const GncDate& a, const GncDate& b);
|
||||||
|
bool operator>=(const GncDate& a, const GncDate& b);
|
||||||
|
bool operator!=(const GncDate& a, const GncDate& b);
|
||||||
|
/**@}*/
|
||||||
|
|
||||||
#endif // __GNC_DATETIME_HPP__
|
#endif // __GNC_DATETIME_HPP__
|
||||||
|
@ -183,6 +183,38 @@ TEST(gnc_date_constructors, test_str_format_constructor)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(gnc_date_operators, test_equality)
|
||||||
|
{
|
||||||
|
GncDate a(2017, 1, 6);
|
||||||
|
GncDate b(2017, 1, 6);
|
||||||
|
GncDate c(2015, 6, 13);
|
||||||
|
EXPECT_TRUE (a == b);
|
||||||
|
EXPECT_FALSE (a == c);
|
||||||
|
EXPECT_TRUE (a != c);
|
||||||
|
EXPECT_FALSE (a != b);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(gnc_date_operators, test_more_less_than)
|
||||||
|
{
|
||||||
|
GncDate a(2017, 1, 6);
|
||||||
|
GncDate b(2017, 1, 6);
|
||||||
|
GncDate c(2015, 6, 13);
|
||||||
|
EXPECT_TRUE (a >= b);
|
||||||
|
EXPECT_TRUE (a <= b);
|
||||||
|
EXPECT_FALSE (a > b);
|
||||||
|
EXPECT_FALSE (a < b);
|
||||||
|
|
||||||
|
EXPECT_TRUE (a > c);
|
||||||
|
EXPECT_TRUE (a >= c);
|
||||||
|
EXPECT_FALSE (a < c);
|
||||||
|
EXPECT_FALSE (a <= c);
|
||||||
|
|
||||||
|
EXPECT_TRUE (c < a);
|
||||||
|
EXPECT_TRUE (c <= a);
|
||||||
|
EXPECT_FALSE (c > a);
|
||||||
|
EXPECT_FALSE (c >= a);
|
||||||
|
}
|
||||||
|
|
||||||
TEST(gnc_datetime_constructors, test_default_constructor)
|
TEST(gnc_datetime_constructors, test_default_constructor)
|
||||||
{
|
{
|
||||||
GncDateTime atime;
|
GncDateTime atime;
|
||||||
|
Loading…
Reference in New Issue
Block a user