📄 datetime.h
字号:
inline wxDateSpan Multiply(int factor) const;
// multiply all components by a (signed) number
inline wxDateSpan& Multiply(int factor);
// multiply all components by a (signed) number
inline wxDateSpan& operator*=(int factor) { return Multiply(factor); }
private:
int m_years,
m_months,
m_weeks,
m_days;
};
// ----------------------------------------------------------------------------
// wxDateTimeArray: array of dates.
// ----------------------------------------------------------------------------
#include "wx/dynarray.h"
WX_DECLARE_EXPORTED_OBJARRAY(wxDateTime, wxDateTimeArray);
// ----------------------------------------------------------------------------
// wxDateTimeHolidayAuthority: an object of this class will decide whether a
// given date is a holiday and is used by all functions working with "work
// days".
//
// NB: the base class is an ABC, derived classes must implement the pure
// virtual methods to work with the holidays they correspond to.
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxDateTimeHolidayAuthority;
WX_DEFINE_EXPORTED_ARRAY(wxDateTimeHolidayAuthority *, wxHolidayAuthoritiesArray);
class wxDateTimeHolidaysModule;
class WXDLLEXPORT wxDateTimeHolidayAuthority
{
friend class wxDateTimeHolidaysModule;
public:
// returns TRUE if the given date is a holiday
static bool IsHoliday(const wxDateTime& dt);
// fills the provided array with all holidays in the given range, returns
// the number of them
static size_t GetHolidaysInRange(const wxDateTime& dtStart,
const wxDateTime& dtEnd,
wxDateTimeArray& holidays);
// clear the list of holiday authorities
static void ClearAllAuthorities();
// add a new holiday authority (the pointer will be deleted by
// wxDateTimeHolidayAuthority)
static void AddAuthority(wxDateTimeHolidayAuthority *auth);
protected:
// this function is called to determine whether a given day is a holiday
virtual bool DoIsHoliday(const wxDateTime& dt) const = 0;
// this function should fill the array with all holidays between the two
// given dates - it is implemented in the base class, but in a very
// inefficient way (it just iterates over all days and uses IsHoliday() for
// each of them), so it must be overridden in the derived class where the
// base class version may be explicitly used if needed
//
// returns the number of holidays in the given range and fills holidays
// array
virtual size_t DoGetHolidaysInRange(const wxDateTime& dtStart,
const wxDateTime& dtEnd,
wxDateTimeArray& holidays) const = 0;
private:
// all holiday authorities
static wxHolidayAuthoritiesArray ms_authorities;
};
// the holidays for this class are all Saturdays and Sundays
class WXDLLEXPORT wxDateTimeWorkDays : public wxDateTimeHolidayAuthority
{
protected:
virtual bool DoIsHoliday(const wxDateTime& dt) const;
virtual size_t DoGetHolidaysInRange(const wxDateTime& dtStart,
const wxDateTime& dtEnd,
wxDateTimeArray& holidays) const;
};
// ============================================================================
// inline functions implementation
// ============================================================================
// don't include inline functions definitions when we're included from anything
// else than datetime.cpp in debug builds: this minimizes rebuilds if we change
// some inline function and the performance doesn't matter in the debug builds.
#if !defined(wxDATETIME_DONT_INLINE) || defined(wxDEFINE_TIME_CONSTANTS)
#define INCLUDED_FROM_WX_DATETIME_H
#include "wx/datetime.inl"
#undef INCLUDED_FROM_WX_DATETIME_H
#endif
// if we defined it to be empty above, restore it now
#ifdef wxDATETIME_DONT_INLINE
#undef inline
#endif
// ============================================================================
// binary operators
// ============================================================================
// ----------------------------------------------------------------------------
// wxDateTime operators
// ----------------------------------------------------------------------------
// arithmetics
// -----------
// no need to check for validity - the member functions we call will do it
inline wxDateTime WXDLLEXPORT operator+(const wxDateTime& dt,
const wxTimeSpan& ts)
{
return dt.Add(ts);
}
inline wxDateTime WXDLLEXPORT operator-(const wxDateTime& dt,
const wxTimeSpan& ts)
{
return dt.Subtract(ts);
}
inline wxDateTime WXDLLEXPORT operator+(const wxDateTime& dt,
const wxDateSpan& ds)
{
return dt.Add(ds);
}
inline wxDateTime WXDLLEXPORT operator-(const wxDateTime& dt,
const wxDateSpan& ds)
{
return dt.Subtract(ds);
}
inline wxTimeSpan WXDLLEXPORT operator-(const wxDateTime& dt1,
const wxDateTime& dt2)
{
return dt1.Subtract(dt2);
}
// comparison
// ----------
inline bool WXDLLEXPORT operator<(const wxDateTime& t1, const wxDateTime& t2)
{
wxASSERT_MSG( t1.IsValid() && t2.IsValid(), _T("invalid wxDateTime") );
return t1.GetValue() < t2.GetValue();
}
inline bool WXDLLEXPORT operator<=(const wxDateTime& t1, const wxDateTime& t2)
{
wxASSERT_MSG( t1.IsValid() && t2.IsValid(), _T("invalid wxDateTime") );
return t1.GetValue() <= t2.GetValue();
}
inline bool WXDLLEXPORT operator>(const wxDateTime& t1, const wxDateTime& t2)
{
wxASSERT_MSG( t1.IsValid() && t2.IsValid(), _T("invalid wxDateTime") );
return t1.GetValue() > t2.GetValue();
}
inline bool WXDLLEXPORT operator>=(const wxDateTime& t1, const wxDateTime& t2)
{
wxASSERT_MSG( t1.IsValid() && t2.IsValid(), _T("invalid wxDateTime") );
return t1.GetValue() >= t2.GetValue();
}
inline bool WXDLLEXPORT operator==(const wxDateTime& t1, const wxDateTime& t2)
{
wxASSERT_MSG( t1.IsValid() && t2.IsValid(), _T("invalid wxDateTime") );
return t1.GetValue() == t2.GetValue();
}
inline bool WXDLLEXPORT operator!=(const wxDateTime& t1, const wxDateTime& t2)
{
wxASSERT_MSG( t1.IsValid() && t2.IsValid(), _T("invalid wxDateTime") );
return t1.GetValue() != t2.GetValue();
}
// ----------------------------------------------------------------------------
// wxTimeSpan operators
// ----------------------------------------------------------------------------
// arithmetics
// -----------
inline wxTimeSpan WXDLLEXPORT operator+(const wxTimeSpan& ts1,
const wxTimeSpan& ts2)
{
return wxTimeSpan(ts1.GetValue() + ts2.GetValue());
}
inline wxTimeSpan WXDLLEXPORT operator-(const wxTimeSpan& ts1,
const wxTimeSpan& ts2)
{
return wxTimeSpan(ts1.GetValue() - ts2.GetValue());
}
inline wxTimeSpan WXDLLEXPORT operator*(const wxTimeSpan& ts, int n)
{
return wxTimeSpan(ts).Multiply(n);
}
inline wxTimeSpan WXDLLEXPORT operator*(int n, const wxTimeSpan& ts)
{
return wxTimeSpan(ts).Multiply(n);
}
// comparison
// ----------
inline bool WXDLLEXPORT operator<(const wxTimeSpan &t1, const wxTimeSpan &t2)
{
return t1.GetValue() < t2.GetValue();
}
inline bool WXDLLEXPORT operator<=(const wxTimeSpan &t1, const wxTimeSpan &t2)
{
return t1.GetValue() <= t2.GetValue();
}
inline bool WXDLLEXPORT operator>(const wxTimeSpan &t1, const wxTimeSpan &t2)
{
return t1.GetValue() > t2.GetValue();
}
inline bool WXDLLEXPORT operator>=(const wxTimeSpan &t1, const wxTimeSpan &t2)
{
return t1.GetValue() >= t2.GetValue();
}
inline bool WXDLLEXPORT operator==(const wxTimeSpan &t1, const wxTimeSpan &t2)
{
return t1.GetValue() == t2.GetValue();
}
inline bool WXDLLEXPORT operator!=(const wxTimeSpan &t1, const wxTimeSpan &t2)
{
return t1.GetValue() != t2.GetValue();
}
// ----------------------------------------------------------------------------
// wxDateSpan
// ----------------------------------------------------------------------------
// comparison
// ----------
// ds1 == d2 if and only if for every wxDateTime t t + ds1 == t + ds2
inline WXDLLEXPORT bool operator==(const wxDateSpan& ds1,
const wxDateSpan& ds2)
{
return ds1.GetYears() == ds2.GetYears() &&
ds1.GetMonths() == ds2.GetMonths() &&
ds1.GetTotalDays() == ds2.GetTotalDays();
}
inline WXDLLEXPORT bool operator!=(const wxDateSpan& ds1,
const wxDateSpan& ds2)
{
return !(ds1 == ds2);
}
// arithmetics
// -----------
inline WXDLLEXPORT wxDateSpan operator+(const wxDateSpan& ds1,
const wxDateSpan& ds2)
{
return wxDateSpan(ds1.GetYears() + ds2.GetYears(),
ds1.GetMonths() + ds2.GetMonths(),
ds1.GetWeeks() + ds2.GetWeeks(),
ds1.GetDays() + ds2.GetDays());
}
inline WXDLLEXPORT wxDateSpan operator-(const wxDateSpan& ds1,
const wxDateSpan& ds2)
{
return wxDateSpan(ds1.GetYears() - ds2.GetYears(),
ds1.GetMonths() - ds2.GetMonths(),
ds1.GetWeeks() - ds2.GetWeeks(),
ds1.GetDays() - ds2.GetDays());
}
inline WXDLLEXPORT wxDateSpan operator*(const wxDateSpan& ds, int n)
{
return wxDateSpan(ds).Multiply(n);
}
inline WXDLLEXPORT wxDateSpan operator*(int n, const wxDateSpan& ds)
{
return wxDateSpan(ds).Multiply(n);
}
// ============================================================================
// other helper functions
// ============================================================================
// ----------------------------------------------------------------------------
// iteration helpers: can be used to write a for loop over enum variable like
// this:
// for
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -