TIP게시판

제목 달력 Data를 배열로 가져오기 js버전.
글쓴이 SADBLUE 작성시각 2009/10/29 23:18:29
댓글 : 2 추천 : 0 스크랩 : 0 조회수 : 13702   RSS
아래 소스와 동일한 개념입니다.

var Calendar = {
	m_currentDate : null,

	makeData : function(pYear, pMonth)
	{
		if (pMonth == 1)
			var oPrevMonth = new Date((pYear-1), 12, 0);
		else
			var oPrevMonth = new Date(pYear, (pMonth-1), 0);

		var oLastDate = new Date(pYear, pMonth, 0);
		var oFirstDate = new Date(pYear, pMonth, 1);

		var nWeekCount = 0;
		var nStartDate = 1;
		var nStartDay = oPrevMonth.getDay() + 1;
		
		if (nStartDay > 6) nStartDay = 0;

		var nLastDate = oLastDate.getDate();
		var nLastDay = oLastDate.getDay();
		
		var nPrevMonthLastDate = oPrevMonth.getDate();

		var stMonth = Array();
		var stWeek = Array();

		if (this.m_currentDate > nLastDate) this.m_currentDate = nLastDate;

		for(i=0 ; i<nStartDay ; ++i)
			stWeek[i] = (nPrevMonthLastDate - nStartDay + i + 1);
		
		for(i=nStartDay ; i<7 ; ++i)
			stWeek[i] = nStartDate++;
		
		stMonth[nWeekCount++] = stWeek;
		stWeek = null;
		stWeek = Array();
		
		for(i=nStartDate ; i<=nLastDate ; ++i)
		{
			if (stWeek.length == 7)
			{
				stMonth[nWeekCount++] = stWeek;
				stWeek = null;
				stWeek = Array();
			}
			stWeek[stWeek.length] = nStartDate++;
		}

		var nTemp = stWeek.length;
		for(i=1 ; i<=7-nTemp ; ++i)
			stWeek[nTemp+i-1] = i;

		stMonth[nWeekCount] = stWeek;

		return stMonth;
	}
}



 다음글 php 세션(서버에저장되는)을 쓰기위해서 (1)
 이전글 달력 Data를 배열로 가져오기 helper (6)

댓글

최용운 / 2009/11/01 11:48:00 / 추천 0

블루야 오랜만이다!!

SADBLUE / 2009/11/01 14:40:44 / 추천 0
안녕하세요 흐흐;