필요해서 열심히 타자쳤다가 필요없어져서 아까워서 올립니다 ㅡㅜ
소스코드는 아래에~
1. GetDays( 년, 월 ) : 해당 년/월 의 날짜 수 구하기, 입력 값이 잘못된 경우 0을 반환
2. WeekByDateTime( 년, 월, 일 ) : 해당 년/월/일 의 날짜가 해당 년/월 에서의 몇 번째 주인지 구하기, 입력 값이 잘못된 경우 0을 반환
3. WeekRangeByDateTime( 년, 월, 주, min, max ) : 해당 년/월 의 해당 주의 시작 값과 끝 값을 min, max 에 전달, 입력 값이 잘못된 경우 min, max 모두 0으로 설정
사용법
// 1. 2007년 3월의 날짜 수 구하기
unsigned int dates = GetDates( 2007, 3 );
if ( dates != 0 )
{
// 성공 ( dates = 31 )
}
else
{
// 실패
}
// 2. 2007/03/21 이 3월의 몇번째 주인지 반환
unsigned int index = WeekByDateTime( 2007, 3, 21 );
if ( index != 0 )
{
// 성공 ( index = 4 )
}
else
{
// 실패
}
// 3. 2007년 3월의 3번째 주의 시작날짜와 끝날짜
unsigned int Min, Max;
WeekRangeByDateTime( 2007, 3, 3, Min, Max );
if ( Min != 0 && Max != 0 )
{
// 성공 ( Min = 11, Max = 17 )
}
else
{
// 실패
}
//---------------------------------------------------------------------------
unsigned int __fastcall GetDates( const unsigned int &Year, const unsigned int &Month )
{
if ( 0 >= Month || Month > 12 )
{
return 0;
}
return ( Month != 2 ? ( ( Month < 8 ? Month + 1 : Month ) % 2 == 0 ? 31 : 30 ) : ( ( Year % 100 == 0 ? Year / 100 : Year ) % 4 == 0 ? 29 : 28 ));
}
//---------------------------------------------------------------------------
unsigned int __fastcall WeekByDateTime( const unsigned int &Year, const unsigned int &Month, const unsigned int &Date )
{
TDateTime temp;
AnsiString tag = IntToStr( Year ) + "-" + IntToStr( Month ) + "-";
unsigned int current = 1;
if ( 0 >= Date || Date > GetDates( Year, Month ) )
{
return 0;
}
for ( unsigned int i = 1; i <= Date; i++ )
{
temp = TDateTime( tag + IntToStr( i ) );
if ( temp.DayOfWeek() == 1 )
{
current++;
}
}
return current;
}
//---------------------------------------------------------------------------
void __fastcall WeekRangeByDateTime( const unsigned int &Year, const unsigned int &Month, const unsigned int &Index, unsigned int& Min, unsigned int &Max )
{
TDateTime temp;
AnsiString tag = IntToStr( Year ) + "-" + IntToStr( Month ) + "-";
Min = 1;
unsigned int current = 1, i = 1;
for ( ; i <= GetDates( Year, Month ); i++ )
{
temp = TDateTime( tag + IntToStr( i ) );
switch ( temp.DayOfWeek() )
{
case 1:
if ( ++current == Index )
{
Min = i;
}
break;
case 7:
if ( current == Index )
{
Max = i;
return;
}
break;
}
}
if ( Min > 1 )
{
Max = i - 1;
return;
}
Min = Max = 0;
}
//---------------------------------------------------------------------------
|