#ifndef TDATETIME_H_
#define TDATETIME_H_

#define dDATETIME_BASESTART_YEAR	2000

typedef union{
	unsigned int FullValue;
	struct {
		unsigned char Day;
		unsigned char Month;
		unsigned short Year;
	}Split;
}TDate;

typedef union{
	unsigned int FullValue;
	struct {
		unsigned char Second ;
		unsigned char Minute ;
		unsigned char Hour;
		unsigned char Rev;
	}Split;
}TTime;

typedef struct {
	unsigned char Second ;
	unsigned char Minute ;
	unsigned char Hour;
	unsigned char Day;
	unsigned char Month;
	unsigned char Year;
	unsigned char Dump0;
	unsigned char Dump1; 
}TDateTimeBytes;

class TDateTime{
	public:
		static constexpr unsigned char MonthDaysNotLeapYear[12] = {31, 28, 31, 30, 31, 30,31, 31, 30, 31, 30, 31};
		static constexpr unsigned char MonthDaysLeapYear[12] = {31, 29, 31, 30, 31, 30,31, 31, 30, 31, 30, 31};
	public:
		unsigned int DateTimeInSecond;
		TDate Date;
		TTime Time;
	
	private:
		static void s__DecodeLeapYearMonth(unsigned int sec, TDate *Date);
		static void s__DecodeYearMonth(unsigned int sec, TDate *Date);
		static void s__DecodeTime(unsigned int sec, TTime *pTime);
	
		static void s__EncodeLeapYearMonth(TDate aDate, unsigned int *pSec);
		static void s__EncodeYearMonth(TDate aDate, unsigned int *pSec);
		static void s__EncodeTime(TTime aTime, unsigned int *pSec);
	
	public:
		TDateTime(void){
			DateTimeInSecond=0;
		}
		
		TDate GetDate(void);
		TTime GetTime(void);
		unsigned int GetDateTime(void);
		
		static void sDecodeDateTime(unsigned int aDateTime, TDate *pDate, TTime *pTime);
		static void sEncodeDateTime(TDate aDate, TTime aTime, unsigned int *pSec);
		
		void SetDateTimeSplit(TDate aDate, TTime aTime);
		void SetDateTimeViaSecond(unsigned int aDateTime);
		int GetWeek(void);
		
		static void sDateTimeIncSec(unsigned char *DtBytes, unsigned int IncSec);
};








#endif

















