date.h

来自「API经典入门」· C头文件 代码 · 共 106 行

H
106
字号
#ifndef __DATE_H__
#define __DATE_H__

#ifndef __SQL
typedef unsigned short int UWORD;
typedef short int SWORD;
#endif
 
class CDate : public CObject
{

DECLARE_SERIAL(CDate)

protected:

	SWORD m_nYear;
	UWORD m_nMonth;
	UWORD m_nDay;

public:
    
    // constructors
	CDate(); // default
	//default constructor initializes date to null
	CDate(CDate& Date);  // copy 
	CDate(CTime& Time);
    CDate(SWORD y, UWORD m, UWORD d);
	
	// assignment
	CDate& operator=(CDate& Date);
	
	// selectors
	SWORD Year()
		{return m_nYear;}
	UWORD Month()
		{return m_nMonth;}
	UWORD Day()
		{return m_nDay;}

	// functions that increment the date by one day
	CDate& operator++();	// prefix notation
	CDate& operator++(int);	// postfix notation
	void AddDay();

	// functions that decrement the date by one day
	CDate& operator--();	// prefix notation
	CDate& operator--(int);	// postfix notation
	void SubtractDay();

protected:	
	// internal month increments.
	// these functions don't validate the day!
	void AddMonth();
	void SubtractMonth();

public:
	// sum & difference operators
	CDate& operator+ (unsigned int Days);
	CDate& operator- (unsigned int Days);
	int operator- (CDate& Date);  // returns days
	void Subtract (CDate& Date, UWORD& Years,
			UWORD& Months, UWORD& Days); 
	// returns difference in Years, Months, and Days
	void Add (SWORD Years, SWORD Months = 0, SWORD Days = 0);
	
	// comparison operators
	BOOL operator== (CDate& Date);
	BOOL operator!= (CDate& Date);
	BOOL operator> (CDate& Date);
	BOOL operator>= (CDate& Date);
	BOOL operator< (CDate& Date);
	BOOL operator<= (CDate& Date);

	// returns FALSE if Date is invalid
	BOOL IsValid();
	
	// changes date to closest valid date
	void MakeValid();
	
	// returns TRUE if leapyear
	BOOL IsLeapYear(SWORD y);
	
	// returns the number of days in the month
	UWORD DaysInMonth();

	// returns a CString object representation of the date.
	// Format is the same as in strftime() -- see MS Visual C++
	// run-time library reference.
	CString DateString (const char* Format = "%d %b %Y");
	
	// sets the date to the value held in the string
	// a string to date conversion is performed.
	// Returns TRUE if successful.
	BOOL StringToDate (const char* strDate);
			
#ifdef _DEBUG
	virtual void Dump(CDumpContext& dc) const;
	virtual void AssertValid() const;
#endif 

	virtual void Serialize( CArchive& ar);

};

#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?