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()!
|
// 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)
|
// from time_t: seconds since the Epoch 00:00:00 UTC, Jan 1, 1970)
|
||||||
inline wxDateTime(time_t timet);
|
inline wxDateTime(time_t timet);
|
||||||
@@ -704,7 +704,7 @@ public:
|
|||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
|
||||||
// is the date valid?
|
// 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
|
// get the broken down date/time representation in the given timezone
|
||||||
//
|
//
|
||||||
@@ -816,38 +816,35 @@ public:
|
|||||||
|
|
||||||
inline bool operator<(const wxDateTime& dt) const
|
inline bool operator<(const wxDateTime& dt) const
|
||||||
{
|
{
|
||||||
wxASSERT_MSG( IsValid() && dt.IsValid(), wxT("invalid wxDateTime") );
|
|
||||||
return GetValue() < dt.GetValue();
|
return GetValue() < dt.GetValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool operator<=(const wxDateTime& dt) const
|
inline bool operator<=(const wxDateTime& dt) const
|
||||||
{
|
{
|
||||||
wxASSERT_MSG( IsValid() && dt.IsValid(), wxT("invalid wxDateTime") );
|
|
||||||
return GetValue() <= dt.GetValue();
|
return GetValue() <= dt.GetValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool operator>(const wxDateTime& dt) const
|
inline bool operator>(const wxDateTime& dt) const
|
||||||
{
|
{
|
||||||
wxASSERT_MSG( IsValid() && dt.IsValid(), wxT("invalid wxDateTime") );
|
|
||||||
return GetValue() > dt.GetValue();
|
return GetValue() > dt.GetValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool operator>=(const wxDateTime& dt) const
|
inline bool operator>=(const wxDateTime& dt) const
|
||||||
{
|
{
|
||||||
wxASSERT_MSG( IsValid() && dt.IsValid(), wxT("invalid wxDateTime") );
|
|
||||||
return GetValue() >= dt.GetValue();
|
return GetValue() >= dt.GetValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool operator==(const wxDateTime& dt) const
|
inline bool operator==(const wxDateTime& dt) const
|
||||||
{
|
{
|
||||||
wxASSERT_MSG( IsValid() && dt.IsValid(), wxT("invalid wxDateTime") );
|
// Intentionally do not call GetValue() here, in order that
|
||||||
return GetValue() == dt.GetValue();
|
// invalid wxDateTimes may be compared for equality
|
||||||
|
return m_time == dt.m_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool operator!=(const wxDateTime& dt) const
|
inline bool operator!=(const wxDateTime& dt) const
|
||||||
{
|
{
|
||||||
wxASSERT_MSG( IsValid() && dt.IsValid(), wxT("invalid wxDateTime") );
|
// As above, don't use GetValue() here.
|
||||||
return GetValue() != dt.GetValue();
|
return m_time != dt.m_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
// arithmetics with dates (see also below for more operators)
|
// 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
|
inline bool wxDateTime::IsEqualTo(const wxDateTime& datetime) const
|
||||||
{
|
{
|
||||||
wxASSERT_MSG( IsValid() && datetime.IsValid(), wxT("invalid wxDateTime"));
|
return *this == datetime;
|
||||||
|
|
||||||
return m_time == datetime.m_time;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool wxDateTime::IsEarlierThan(const wxDateTime& datetime) const
|
inline bool wxDateTime::IsEarlierThan(const wxDateTime& datetime) const
|
||||||
{
|
{
|
||||||
wxASSERT_MSG( IsValid() && datetime.IsValid(), wxT("invalid wxDateTime"));
|
return *this < datetime;
|
||||||
|
|
||||||
return m_time < datetime.m_time;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool wxDateTime::IsLaterThan(const wxDateTime& datetime) const
|
inline bool wxDateTime::IsLaterThan(const wxDateTime& datetime) const
|
||||||
{
|
{
|
||||||
wxASSERT_MSG( IsValid() && datetime.IsValid(), wxT("invalid wxDateTime"));
|
return *this > datetime;
|
||||||
|
|
||||||
return m_time > datetime.m_time;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool wxDateTime::IsStrictlyBetween(const wxDateTime& t1,
|
inline bool wxDateTime::IsStrictlyBetween(const wxDateTime& t1,
|
||||||
|
@@ -645,7 +645,14 @@ public:
|
|||||||
@name Date Comparison
|
@name Date Comparison
|
||||||
|
|
||||||
There are several functions to allow date comparison. To supplement
|
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