#if !defined(__CTIME__)
#define __CTIME__

#if !defined(TIMEDATE_YEAR_BASE)
#define TIMEDATE_YEAR_BASE 1900
#endif // !defined(TIMEDATE_YEAR_BASE)

#if !defined(TIMEDATE_YEAR_BITS)
#define TIMEDATE_YEAR_BITS 8
#endif // !defined(TIMEDATE_YEAR_BITS)

#define TIMEDATE_RESERVED_BITS (32 - (5 + 4 + TIMEDATE_YEAR_BITS + 1 + 1)) // 13?

class CTimeDate
{
public:
    union {
    struct {
    // Bit Fields declared first are at the low-bit end.
    DWORD m_xDay: 5; // 2^0, 2^5-1
    DWORD m_xMonth: 4; // 2^5, 2^4-1
    DWORD m_xYear: TIMEDATE_YEAR_BITS; // from 1900-2155 // 2^9, 2^8-1
    DWORD m_xReserved: TIMEDATE_RESERVED_BITS; // 2^17,2^13-1
    DWORD m_xLunar: 1; // lunar system not solar system // 2^30, 2^1-1
    DWORD m_xLeap: 1; // leap month? in case of lunar system // 2^31, 2^1-1
    } m_LN;
    long m_lDate;
    };
public:
    CTimeDate() { m_lDate = 0; } // TIMEDATE_YEAR_BASE/1/1 in solar
    CTimeDate(const CTimeDate& that) { m_lDate = that.m_lDate; }
    operator long& () { return *(long*)&m_lDate; }
    static BOOL IsLeapYear(int nYear);
    static long GetCurrent();
    int const GetYear() const { return m_LN.m_xYear + TIMEDATE_YEAR_BASE; }
    int const GetMonth() const { return m_LN.m_xMonth; }
    int const GetDay() const { return m_LN.m_xDay; }
    void CurrentDate();
    BOOL GetDate(long lDate, BOOL bLunar = FALSE, BOOL bLeap = FALSE);
};

class CTimeLong
{
public:
    long m_lTime; // time_t
public:
    CTimeLong() { m_lTime = 0; }
    CTimeLong(const CTimeLong& that) { m_lTime = that.m_lTime; }
    operator long& () { return *(long*)&m_lTime; }
    static long GetCurrent();
    void CurrentTime();
    void GetTime(tm& t) const;
};

#endif //!defined(__CTIME__)
