#pragma once #include "common.h" class AFX_CLASS_EXPORT T2DateTime { public: T2DateTime(); T2DateTime(int year, int month, int hours, int minutes, int seconds); T2DateTime(T2Archive& archive); T2DateTime(const T2DateTime &other) : mYear(other.mYear) , mMonth(other.mMonth) , mRawMinutes(other.mRawMinutes) , mSeconds(other.mSeconds) {} virtual ~T2DateTime(); virtual void Write(T2Archive& archive); int GetTimeZone(); void AddMinutes(unsigned int m); BOOL IsIncDateTime(); void IncDate(); unsigned int CalcLapseDays(unsigned int d) const; unsigned int CalcLapseYears(unsigned int d) const; BOOL WithinHour(int a, int b) const; BOOL WithinMinutes(int a, int b) const; BOOL IsHoliday(T2TowerDoc* doc); void Validate(); static BOOL IsEqualDate(T2DateTime* a, T2DateTime* b); static BOOL IsEqualDateTime(T2DateTime* a, T2DateTime* b); unsigned int GetYear() const { return mYear; } unsigned int GetQuarter() const { return mMonth / 3 + 1; } unsigned int GetSeason() const { return mMonth / 3 + 1; } unsigned int GetDay() const { return mMonth % 3 + 1; } unsigned int GetMonth() const { return mMonth + 1; } unsigned int GetHour() const { return (mRawMinutes % 720) / 60; } unsigned int Get24Hour() const { return mRawMinutes / 60; } unsigned int GetMinutes() const { return mRawMinutes % 60; } unsigned int GetRawMinutes() const { return mRawMinutes; } int CalcTotalDays() const { return (mYear - 1) * 12 + mMonth; } BOOL IsWeekday(T2TowerDoc* doc) { return !IsHoliday(doc); } BOOL IsDay() const { return (mRawMinutes >= 360 && mRawMinutes < 1080); } BOOL IsMidNight() const { return mRawMinutes < 360; } BOOL IsOclock24(unsigned int hour) const { return (Get24Hour() == hour) && (GetMinutes() == 0) && (mSeconds == 0); } unsigned int mYear; unsigned int mMonth; unsigned int mRawMinutes; unsigned int mSeconds; protected: int AdjustMinutes(int m) const; friend BOOL operator>=(const T2DateTime &a, const T2DateTime &b); unsigned int CalcTotalCount() const { return mSeconds + ((mYear * 12 + mMonth) * 1440 + mRawMinutes) * 4; } }; inline BOOL operator>=(const T2DateTime &a, const T2DateTime &b) { return a.CalcTotalCount() >= b.CalcTotalCount(); }