Merge branch 'datetime-compare'
Miscellaneous improvements to wxDateTime comparison operators. Closes #17490.
This commit is contained in:
@@ -450,7 +450,7 @@ public:
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
// default ctor does not initialize the object, use Set()!
|
||||
wxDateTime() { m_time = wxLongLong(wxINT32_MIN, 0); }
|
||||
wxDateTime() { m_time = wxINT64_MIN; }
|
||||
|
||||
// from time_t: seconds since the Epoch 00:00:00 UTC, Jan 1, 1970)
|
||||
inline wxDateTime(time_t timet);
|
||||
@@ -704,7 +704,7 @@ public:
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
// is the date valid?
|
||||
inline bool IsValid() const { return m_time != wxInvalidDateTime.m_time; }
|
||||
inline bool IsValid() const { return m_time != wxLongLong(wxINT64_MIN); }
|
||||
|
||||
// get the broken down date/time representation in the given timezone
|
||||
//
|
||||
@@ -816,38 +816,35 @@ public:
|
||||
|
||||
inline bool operator<(const wxDateTime& dt) const
|
||||
{
|
||||
wxASSERT_MSG( IsValid() && dt.IsValid(), wxT("invalid wxDateTime") );
|
||||
return GetValue() < dt.GetValue();
|
||||
}
|
||||
|
||||
inline bool operator<=(const wxDateTime& dt) const
|
||||
{
|
||||
wxASSERT_MSG( IsValid() && dt.IsValid(), wxT("invalid wxDateTime") );
|
||||
return GetValue() <= dt.GetValue();
|
||||
}
|
||||
|
||||
inline bool operator>(const wxDateTime& dt) const
|
||||
{
|
||||
wxASSERT_MSG( IsValid() && dt.IsValid(), wxT("invalid wxDateTime") );
|
||||
return GetValue() > dt.GetValue();
|
||||
}
|
||||
|
||||
inline bool operator>=(const wxDateTime& dt) const
|
||||
{
|
||||
wxASSERT_MSG( IsValid() && dt.IsValid(), wxT("invalid wxDateTime") );
|
||||
return GetValue() >= dt.GetValue();
|
||||
}
|
||||
|
||||
inline bool operator==(const wxDateTime& dt) const
|
||||
{
|
||||
wxASSERT_MSG( IsValid() && dt.IsValid(), wxT("invalid wxDateTime") );
|
||||
return GetValue() == dt.GetValue();
|
||||
// Intentionally do not call GetValue() here, in order that
|
||||
// invalid wxDateTimes may be compared for equality
|
||||
return m_time == dt.m_time;
|
||||
}
|
||||
|
||||
inline bool operator!=(const wxDateTime& dt) const
|
||||
{
|
||||
wxASSERT_MSG( IsValid() && dt.IsValid(), wxT("invalid wxDateTime") );
|
||||
return GetValue() != dt.GetValue();
|
||||
// As above, don't use GetValue() here.
|
||||
return m_time != dt.m_time;
|
||||
}
|
||||
|
||||
// arithmetics with dates (see also below for more operators)
|
||||
@@ -1774,23 +1771,17 @@ inline wxDateTime wxDateTime::GetYearDay(wxDateTime_t yday) const
|
||||
|
||||
inline bool wxDateTime::IsEqualTo(const wxDateTime& datetime) const
|
||||
{
|
||||
wxASSERT_MSG( IsValid() && datetime.IsValid(), wxT("invalid wxDateTime"));
|
||||
|
||||
return m_time == datetime.m_time;
|
||||
return *this == datetime;
|
||||
}
|
||||
|
||||
inline bool wxDateTime::IsEarlierThan(const wxDateTime& datetime) const
|
||||
{
|
||||
wxASSERT_MSG( IsValid() && datetime.IsValid(), wxT("invalid wxDateTime"));
|
||||
|
||||
return m_time < datetime.m_time;
|
||||
return *this < datetime;
|
||||
}
|
||||
|
||||
inline bool wxDateTime::IsLaterThan(const wxDateTime& datetime) const
|
||||
{
|
||||
wxASSERT_MSG( IsValid() && datetime.IsValid(), wxT("invalid wxDateTime"));
|
||||
|
||||
return m_time > datetime.m_time;
|
||||
return *this > datetime;
|
||||
}
|
||||
|
||||
inline bool wxDateTime::IsStrictlyBetween(const wxDateTime& t1,
|
||||
|
@@ -645,7 +645,14 @@ public:
|
||||
@name Date Comparison
|
||||
|
||||
There are several functions to allow date comparison. To supplement
|
||||
them, a few global operators, etc taking wxDateTime are defined.
|
||||
them, the usual comparison operators taking wxDateTime are defined as
|
||||
well.
|
||||
|
||||
Notice that an invalid wxDateTime object can only be compared for
|
||||
exact equality, i.e. using @c operator==(), @c operator!=() or
|
||||
IsEqualTo(), but comparisons involving an invalid wxDateTime object
|
||||
using any other operators or IsEarlierThan() or IsLaterThan() functions
|
||||
would result in an assert because their result is not well-defined.
|
||||
*/
|
||||
//@{
|
||||
|
||||
|
Reference in New Issue
Block a user