X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/68ee7c47300b37e408ef9a04ec9f83af78e90817..be25e4809325d89075f6477025e02706137e6ffd:/include/wx/datetime.inl diff --git a/include/wx/datetime.inl b/include/wx/datetime.inl index e0ba83042f..3fb5776196 100644 --- a/include/wx/datetime.inl +++ b/include/wx/datetime.inl @@ -16,6 +16,8 @@ #error "This file is only included by wx/datetime.h, don't include it manually!" #endif +#define MILLISECONDS_PER_DAY 86400000l + // ---------------------------------------------------------------------------- // wxDateTime construction // ---------------------------------------------------------------------------- @@ -169,6 +171,32 @@ bool wxDateTime::IsBetween(const wxDateTime& t1, const wxDateTime& t2) const return IsEqualTo(t1) || IsEqualTo(t2) || IsStrictlyBetween(t1, t2); } +bool wxDateTime::IsSameDate(const wxDateTime& dt) const +{ + return (m_time - dt.m_time).Abs() < MILLISECONDS_PER_DAY; +} + +bool wxDateTime::IsSameTime(const wxDateTime& dt) const +{ + // notice that we can't do something like this: + // + // m_time % MILLISECONDS_PER_DAY == dt.m_time % MILLISECONDS_PER_DAY + // + // because we have also to deal with (possibly) different DST settings! + Tm tm1 = GetTm(), + tm2 = dt.GetTm(); + + return tm1.hour == tm2.hour && + tm1.min == tm2.min && + tm1.sec == tm2.sec && + tm1.msec == tm2.msec; +} + +bool wxDateTime::IsEqualUpTo(const wxDateTime& dt, const wxTimeSpan& ts) const +{ + return IsBetween(dt.Substract(ts), dt.Add(ts)); +} + // ---------------------------------------------------------------------------- // wxDateTime arithmetics // ---------------------------------------------------------------------------- @@ -251,9 +279,10 @@ wxDateTime& wxDateTime::operator+=(const wxDateSpan& diff) // wxDateTime and timezones // ---------------------------------------------------------------------------- -wxDateTime wxDateTime::ToTimezone(const wxDateTime::TimeZone& tz) const +wxDateTime wxDateTime::ToTimezone(const wxDateTime::TimeZone& tz, + bool noDST) const { - return wxDateTime(*this).MakeTimezone(tz); + return wxDateTime(*this).MakeTimezone(tz, noDST); } // ---------------------------------------------------------------------------- @@ -373,10 +402,10 @@ wxDateSpan::operator+=(const wxDateSpan& other) wxDateSpan& wxDateSpan::Multiply(int factor) { - m_years *= m_years; - m_months *= m_months; - m_weeks *= m_weeks; - m_days *= m_days; + m_years *= factor; + m_months *= factor; + m_weeks *= factor; + m_days *= factor; return *this; } @@ -401,3 +430,4 @@ wxDateSpan& wxDateSpan::Neg() return *this; } +#undef MILLISECONDS_PER_DAY