블로그는 나의 힘!
[ Programing ]/Algorithm2013. 12. 20. 11:05

입력한 틱 타임값을 날짜 구조체에 담는다.

 

 

 

 

/*

// 날짜 관련 구조체. 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

*/

 

// 입력한 Tick 값을 Date 구조체에 담는다.
void GetTimeToDateInfo( SDate& sDateInfo, int iTime )
{

        //time_t atm = time( NULL );   // 현재 시간 초 단위로 담기
        time_t atm = static_cast<time_t>( iTime );
        tm tmTime;

 

        // 현재 초단위 시간을 분리하여 구조체 담기
        // 2번째 인자에 Tick을 넣으면 그 Tick 시간 설정된 시간으로 구조체 담기
        // localtime 함수로 현재 시간 구할 수 있으나 VS 2005 이후보안이 강화
        // localtime 사용시 waring c4996 경고 뜸
        localtime_s( &tmTime, &atm );

 

        sDateInfo.iSec = tmTime.tm_sec;
        sDateInfo.iMin = tmTime.tm_min;
        sDateInfo.iHour = tmTime.tm_hour;
        sDateInfo.iDay = tmTime.tm_mday;
        sDateInfo.iMonth = tmTime.tm_mon + 1;
        sDateInfo.iYear = tmTime.tm_year + 1900;
}

 

Posted by Mister_Q