블로그는 나의 힘!
[ Programing ]/C++2013. 5. 22. 10:33

날짜 관련 비교해서 만들어야 할 조건이 생겨 하나 만들어봤다...

기존에 있는 tm 구조체, SYSTEMTIME은 데이터만 담고 비교 자체가 없더라...

걍 하나 노가다로 operator로 만들어 봤는데... 쓸만한거 같네...

 


// 날짜 관련 구조체. operator 포함
struct SDate
{
        int iYear;
        int iMonth;
        int iDay;
        int iHour;
        int iMin;
        int iSec;

 

        SDate()
        {
                Initialize();
        }

 

        void Initialize()
        {
                memset( this, 0x00, sizeof(SDate) );
        }

 

        SDate& operator=( const SDate& rhsDate )
        {
                this->iYear = rhsDate.iYear;

                this->iMonth = rhsDate.iMonth;

                this->iDay = rhsDate.iDay;

                this->iHour = rhsDate.iHour;

                this->iMin = rhsDate.iMin;

                this->iSec = rhsDate.iSec;


                return (*this);
        }

 

        bool operator<( const SDate& rhsDate ) const
        {
                if( this->iYear > rhsDate.iYear ) return false;
                if( this->iYear < rhsDate.iYear ) return true;

 

                if( this->iMonth > rhsDate.iMonth ) return false;
                if( this->iMonth < rhsDate.iMonth ) return true;

 

                if( this->iDay > rhsDate.iDay ) return false;
                if( this->iDay < rhsDate.iDay ) return true;

 

                if( this->iHour > rhsDate.iHour ) return false;
                if( this->iHour < rhsDate.iHour ) return true;

 

                if( this->iMin > rhsDate.iMin ) return false;
                if( this->iMin < rhsDate.iMin ) return true;

 

                if( this->iSec >= rhsDate.iSec ) return false;

 

                return true;
        }

 

        bool operator>( const SDate& rhsDate ) const
        {
                if( this->iYear < rhsDate.iYear ) return false;
                if( this->iYear > rhsDate.iYear ) return true;

 

                if( this->iMonth < rhsDate.iMonth ) return false;
                if( this->iMonth > rhsDate.iMonth ) return true;

 

                if( this->iDay < rhsDate.iDay ) return false;
                if( this->iDay > rhsDate.iDay ) return true;


                if( this->iHour < rhsDate.iHour ) return false
                if( this->iHour > rhsDate.iHour ) return true;

 

                if( this->iMin < rhsDate.iMin ) return false;
                if( this->iMin > rhsDate.iMin ) return true;

 

                if( this->iSec <= rhsDate.iSec ) return false;

 

                return true;
        }

 

        bool operator==( const SDate& rhsDate ) const
        {
                if( this->iYear != rhsDate.iYear ) return false;
                if( this->iMonth != rhsDate.iMonth ) return false;
                if( this->iDay != rhsDate.iDay ) return false;
                if( this->iHour != rhsDate.iHour ) return false;
                if( this->iMin != rhsDate.iMin ) return false;
                if( this->iSec != rhsDate.iSec ) return false;

 

                return true;
        }

 

        bool operator!=( const SDate& rhsDate ) const
        {
                if( this->iYear != rhsDate.iYear ) return true;
                if( this->iMonth != rhsDate.iMonth ) return true;
                if( this->iDay != rhsDate.iDay ) return true;
                if( this->iHour != rhsDate.iHour ) return true;
                if( this->iMin != rhsDate.iMin ) return true;
                if( this->iSec != rhsDate.iSec ) return true;

 

                return false;
        }

 

        bool operator<=( const SDate& rhsDate ) const
        {
                if( this->iYear > rhsDate.iYear ) return false;
                if( this->iYear < rhsDate.iYear ) return true;

 

                if( this->iMonth > rhsDate.iMonth ) return false;
                if( this->iMonth < rhsDate.iMonth ) return true;

 

                if( this->iDay > rhsDate.iDay ) return false;
                if( this->iDay < rhsDate.iDay ) return true;

 

                if( this->iHour > rhsDate.iHour ) return false;
                if( this->iHour < rhsDate.iHour ) return true;

 

                if( this->iMin > rhsDate.iMin ) return false;
                if( this->iMin < rhsDate.iMin ) return true;

 

                if( this->iSec > rhsDate.iSec ) return false;

 

                return true;
        }

 

        bool operator>=( const SDate& rhsDate ) const
        {
                if( this->iYear < rhsDate.iYear ) return false;
                if( this->iYear > rhsDate.iYear ) return true;

 

                if( this->iMonth < rhsDate.iMonth ) return false;
                if( this->iMonth > rhsDate.iMonth ) return true;

 

                if( this->iDay < rhsDate.iDay ) return false;
                if( this->iDay > rhsDate.iDay ) return true;

 

                if( this->iHour < rhsDate.iHour ) return false;
                if( this->iHour > rhsDate.iHour ) return true;

 

                if( this->iMin < rhsDate.iMin ) return false;
                if( this->iMin > rhsDate.iMin ) return true;

 

                if( this->iSec < rhsDate.iSec ) return false;

 

                return true;
        }
} // !SDate

 

Posted by Mister_Q