/****************************************************************************************** * 기능 : 윤년여부 확인 * 인자 : sDate : yyyyMMdd형태의 날짜 ( 예 : "20121122" ) * 리턴 : - sDate가 윤년인 경우 = true * - sDate가 윤년이 아닌 경우 = false * - sDate가 입력되지 않은 경우 = false * 예문 : *****************************************************************************************/
function gfn_IsLeapYear(sDate)
{
var ret;
var nY;
if( gfn_IsNull(sDate) ) return false;
nY = parseInt(sDate.substring(0,4), 10);
if ((nY % 4) == 0)
{
if ((nY % 100) != 0 || (nY % 400) == 0)
ret = true;
else
ret = false;
}
else
ret = false;
return ret;
}
/****************************************************************************************** * 기능 : 음력을 양력으로 변환해주는 함수 (처리가능 기간 1841 - 2043년) * 인자 : sDate : Flag(1 Byte)+yyyyMMdd형태의 음력일자 ( 예 : "020121122" ) ( Flag : 평달 = "0", 윤달 = "1" ) * 리턴 : - 성공 = yyyyMMdd형태의 양력일자 * ( Flag : 평달 = "0", 윤달 = "1" ) * - 실패 = null * - 1841 ~ 2043 범위 오류의 경우 * - sDate가 9자리가 아닐경우 * - sDate의 첫자리 Flag가 "0"도 아니고 "1"도 아닌 경우 * 예문 : *****************************************************************************************/
function gfn_Lunar2Solar(sDate)
{
var sMd = "31,0,31,30,31,30,31,31,30,31,30,31";
var aMd = new Array();
var aBaseInfo = new Array();
var nLy, nLm, nLd, sLflag; // 전해온 음력 인자값을 저장할 년, 월, 일, 윤달여부 임시변수
var nSy, nSm, nSd; // 계산된 양력 년, 월, 일을 저장할 변수
var y1, m1, i, j, y2, y3; // 임시변수
var leap;
if( gfn_IsNull(sDate) ) return "";
if( sDate.length != 9 ) return "";
sLflag = sDate.substr(0,1);
nLy = parseInt(sDate.substr(1,4), 10);
nLm = parseInt(sDate.substr(5,2), 10);
nLd = parseInt(sDate.substr(7,2), 10);
if( nLy < 1841 || nLy > 2043 ) return "";
if( sLflag != "0" && sLflag != "1" ) return "";
aBaseInfo = _SolarBase();
aMd = sMd.split(",");
if( gfn_IsLeapYear(sDate.substr(1,8)) == true )
aMd[1] = 29;
else
aMd[1] = 28;
y1 = nLy - 1841;
m1 = nLm - 1;
leap = 0;
if( parseInt(aBaseInfo[y1*12 + m1]) > 2 )
leap = gfn_IsLeapYear(nLy+"0101");
if( leap == 1 )
{
switch( parseInt(aBaseInfo[y1*12 + m1]) )
{
case 3 : mm = 29;
break;
case 4 : mm = 30;
break;
case 5 : mm = 29;
break;
case 6 : mm = 30;
break;
}
}
else
{
switch( parseInt(aBaseInfo[y1*12 + m1]) )
{
case 1 : mm = 29;
break;
case 2 : mm = 30;
break;
case 3 : mm = 29;
break;
case 4 : mm = 29;
break;
case 5 : mm = 30;
break;
case 6 : mm = 30;
break;
}
}
td = 0;
for( i = 0 ; i <= y1 - 1 ; i++ )
{
for( j = 0 ; j <= 11 ; j++ )
{
switch( parseInt(aBaseInfo[i*12 + j]) )
{
case 1 : td = td + 29;
break;
case 2 : td = td + 30;
break;
case 3 : td = td + 58;
break;
case 4 : td = td + 59;
break;
case 5 : td = td + 59;
break;
case 6 : td = td + 60;
break;
}
}
}
for( j = 0 ; j <= m1 - 1 ; j++ )
{
switch( parseInt(aBaseInfo[y1*12 + j]) )
{
case 1 : td = td + 29;
break;
case 2 : td = td + 30;
break;
case 3 : td = td + 58;
break;
case 4 : td = td + 59;
break;
case 5 : td = td + 59;
break;
case 6 : td = td + 60;
break;
}
}
if( leap == 1 )
{
switch( parseInt(aBaseInfo[y1*12 + m1]) )
{
case 3 : mm = 29;
break;
case 4 : mm = 29;
break;
case 5 : mm = 30;
break;
case 6 : mm = 30;
break;
}
}
td = td + nLd + 22;
if( sLflag == "1" )
{
switch( parseInt(aBaseInfo[y1*12 + m1]) )
{
case 3 : td = td + 29;
break;
case 4 : td = td + 30;
break;
case 5 : td = td + 29;
break;
case 6 : td = td + 30;
break;
}
}
y1 = 1840;
do
{
y1 = y1 + 1;
leap = gfn_IsLeapYear(y1+"0101");
if( leap == 1 )
y2 = 366;
else
y2 = 365;
if( td <= y2 )
break;
td = td - y2;
}
while(1);
nSy = y1;
aMd[1] = y2 - 337;
m1 = 0;
do
{
m1 = m1 + 1;
if( td <= parseInt(aMd[m1-1]) )
break;
td = td - parseInt(aMd[m1-1]);
}
while(1);
nSm = m1;
nSd = td;
y3 = nSy;
td = y3 * 365 + parseInt(y3/4) - parseInt(y3/100) + parseInt(y3/400);
for( i = 0 ; i <= nSm - 1 ; i++ )
td = td + parseInt(aMd[i]);
td = td + nSd;
return y3 + gfn_Right("0" + nSm, 2)+gfn_Right("0" + nSd, 2);
}
/****************************************************************************************** * 기능 : 각 월별 음력 기준 정보를 처리하는 함수(처리가능 기간 1841 - 2043년) 단, 내부에서 사용하는 함수임 * 인자 : 없음 * 리턴 : 성공 = 음력 기준정보 * 예문 : *****************************************************************************************/
function _SolarBase()
{
var kk;
//1841
kk = "1,2,4,1,1,2,1,2,1,2,2,1,";
kk += "2,2,1,2,1,1,2,1,2,1,2,1,";
kk += "2,2,2,1,2,1,4,1,2,1,2,1,";
kk += "2,2,1,2,1,2,1,2,1,2,1,2,";
kk += "1,2,1,2,2,1,2,1,2,1,2,1,";
kk += "2,1,2,1,5,2,1,2,2,1,2,1,";
kk += "2,1,1,2,1,2,1,2,2,2,1,2,";
kk += "1,2,1,1,2,1,2,1,2,2,2,1,";
kk += "2,1,2,3,2,1,2,1,2,1,2,2,";
kk += "2,1,2,1,1,2,1,1,2,2,1,2,";
//1851
kk += "2,2,1,2,1,1,2,1,2,1,5,2,";
kk += "2,1,2,2,1,1,2,1,2,1,1,2,";
kk += "2,1,2,2,1,2,1,2,1,2,1,2,";
kk += "1,2,1,2,1,2,5,2,1,2,1,2,";
kk += "1,1,2,1,2,2,1,2,2,1,2,1,";
kk += "2,1,1,2,1,2,1,2,2,2,1,2,";
kk += "1,2,1,1,5,2,1,2,1,2,2,2,";
kk += "1,2,1,1,2,1,1,2,2,1,2,2,";
kk += "2,1,2,1,1,2,1,1,2,1,2,2,";
kk += "2,1,6,1,1,2,1,1,2,1,2,2,";
//1861
kk += "1,2,2,1,2,1,2,1,2,1,1,2,";
kk += "2,1,2,1,2,2,1,2,2,3,1,2,";
kk += "1,2,2,1,2,1,2,2,1,2,1,2,";
kk += "1,1,2,1,2,1,2,2,1,2,2,1,";
kk += "2,1,1,2,4,1,2,2,1,2,2,1,";
kk += "2,1,1,2,1,1,2,2,1,2,2,2,";
kk += "1,2,1,1,2,1,1,2,1,2,2,2,";
kk += "1,2,2,3,2,1,1,2,1,2,2,1,";
kk += "2,2,2,1,1,2,1,1,2,1,2,1,";
kk += "2,2,2,1,2,1,2,1,1,5,2,1,";
//1871
kk += "2,2,1,2,2,1,2,1,2,1,1,2,";
kk += "1,2,1,2,2,1,2,1,2,2,1,2,";
kk += "1,1,2,1,2,4,2,1,2,2,1,2,";
kk += "1,1,2,1,2,1,2,1,2,2,2,1,";
kk += "2,1,1,2,1,1,2,1,2,2,2,1,";
kk += "2,2,1,1,5,1,2,1,2,2,1,2,";
kk += "2,2,1,1,2,1,1,2,1,2,1,2,";
kk += "2,2,1,2,1,2,1,1,2,1,2,1,";
kk += "2,2,4,2,1,2,1,1,2,1,2,1,";
kk += "2,1,2,2,1,2,2,1,2,1,1,2,";
//1881
kk += "1,2,1,2,1,2,5,2,2,1,2,1,";
kk += "1,2,1,2,1,2,1,2,2,1,2,2,";
kk += "1,1,2,1,1,2,1,2,2,2,1,2,";
kk += "2,1,1,2,3,2,1,2,2,1,2,2,";
kk += "2,1,1,2,1,1,2,1,2,1,2,2,";
kk += "2,1,2,1,2,1,1,2,1,2,1,2,";
kk += "2,2,1,5,2,1,1,2,1,2,1,2,";
kk += "2,1,2,2,1,2,1,1,2,1,2,1,";
kk += "2,1,2,2,1,2,1,2,1,2,1,2,";
kk += "1,5,2,1,2,2,1,2,1,2,1,2,";
//1891
kk += "1,2,1,2,1,2,1,2,2,1,2,2,";
kk += "1,1,2,1,1,5,2,2,1,2,2,2,";
kk += "1,1,2,1,1,2,1,2,1,2,2,2,";
kk += "1,2,1,2,1,1,2,1,2,1,2,2,";
kk += "2,1,2,1,5,1,2,1,2,1,2,1,";
kk += "2,2,2,1,2,1,1,2,1,2,1,2,";
kk += "1,2,2,1,2,1,2,1,2,1,2,1,";
kk += "2,1,5,2,2,1,2,1,2,1,2,1,";
kk += "2,1,2,1,2,1,2,2,1,2,1,2,";
kk += "1,2,1,1,2,1,2,5,2,2,1,2,";
//1901
kk += "1,2,1,1,2,1,2,1,2,2,2,1,";
kk += "2,1,2,1,1,2,1,2,1,2,2,2,";
kk += "1,2,1,2,3,2,1,1,2,2,1,2,";
kk += "2,2,1,2,1,1,2,1,1,2,2,1,";
kk += "2,2,1,2,2,1,1,2,1,2,1,2,";
kk += "1,2,2,4,1,2,1,2,1,2,1,2,";
kk += "1,2,1,2,1,2,2,1,2,1,2,1,";
kk += "2,1,1,2,2,1,2,1,2,2,1,2,";
kk += "1,5,1,2,1,2,1,2,2,2,1,2,";
kk += "1,2,1,1,2,1,2,1,2,2,2,1,";
//1911
kk += "2,1,2,1,1,5,1,2,2,1,2,2,";
kk += "2,1,2,1,1,2,1,1,2,2,1,2,";
kk += "2,2,1,2,1,1,2,1,1,2,1,2,";
kk += "2,2,1,2,5,1,2,1,2,1,1,2,";
kk += "2,1,2,2,1,2,1,2,1,2,1,2,";
kk += "1,2,1,2,1,2,2,1,2,1,2,1,";
kk += "2,3,2,1,2,2,1,2,2,1,2,1,";
kk += "2,1,1,2,1,2,1,2,2,2,1,2,";
kk += "1,2,1,1,2,1,5,2,2,1,2,2,";
kk += "1,2,1,1,2,1,1,2,2,1,2,2,";
//1921
kk += "2,1,2,1,1,2,1,1,2,1,2,2,";
kk += "2,1,2,2,3,2,1,1,2,1,2,2,";
kk += "1,2,2,1,2,1,2,1,2,1,1,2,";
kk += "2,1,2,1,2,2,1,2,1,2,1,1,";
kk += "2,1,2,5,2,1,2,2,1,2,1,2,";
kk += "1,1,2,1,2,1,2,2,1,2,2,1,";
kk += "2,1,1,2,1,2,1,2,2,1,2,2,";
kk += "1,5,1,2,1,1,2,2,1,2,2,2,";
kk += "1,2,1,1,2,1,1,2,1,2,2,2,";
kk += "1,2,2,1,1,5,1,2,1,2,2,1,";
//1931
kk += "2,2,2,1,1,2,1,1,2,1,2,1,";
kk += "2,2,2,1,2,1,2,1,1,2,1,2,";
kk += "1,2,2,1,6,1,2,1,2,1,1,2,";
kk += "1,2,1,2,2,1,2,2,1,2,1,2,";
kk += "1,1,2,1,2,1,2,2,1,2,2,1,";
kk += "2,1,4,1,2,1,2,1,2,2,2,1,";
kk += "2,1,1,2,1,1,2,1,2,2,2,1,";
kk += "2,2,1,1,2,1,4,1,2,2,1,2,";
kk += "2,2,1,1,2,1,1,2,1,2,1,2,";
kk += "2,2,1,2,1,2,1,1,2,1,2,1,";
//1941
kk += "2,2,1,2,2,4,1,1,2,1,2,1,";
kk += "2,1,2,2,1,2,2,1,2,1,1,2,";
kk += "1,2,1,2,1,2,2,1,2,2,1,2,";
kk += "1,1,2,4,1,2,1,2,2,1,2,2,";
kk += "1,1,2,1,1,2,1,2,2,2,1,2,";
kk += "2,1,1,2,1,1,2,1,2,2,1,2,";
kk += "2,5,1,2,1,1,2,1,2,1,2,2,";
kk += "2,1,2,1,2,1,1,2,1,2,1,2,";
kk += "2,2,1,2,1,2,3,2,1,2,1,2,";
kk += "2,1,2,2,1,2,1,1,2,1,2,1,";
//1951
kk += "2,1,2,2,1,2,1,2,1,2,1,2,";
kk += "1,2,1,2,4,2,1,2,1,2,1,2,";
kk += "1,2,1,1,2,2,1,2,2,1,2,2,";
kk += "1,1,2,1,1,2,1,2,2,1,2,2,";
kk += "2,1,4,1,1,2,1,2,1,2,2,2,";
kk += "1,2,1,2,1,1,2,1,2,1,2,2,";
kk += "2,1,2,1,2,1,1,5,2,1,2,2,";
kk += "1,2,2,1,2,1,1,2,1,2,1,2,";
kk += "1,2,2,1,2,1,2,1,2,1,2,1,";
kk += "2,1,2,1,2,5,2,1,2,1,2,1,";
//1961
kk += "2,1,2,1,2,1,2,2,1,2,1,2,";
kk += "1,2,1,1,2,1,2,2,1,2,2,1,";
kk += "2,1,2,3,2,1,2,1,2,2,2,1,";
kk += "2,1,2,1,1,2,1,2,1,2,2,2,";
kk += "1,2,1,2,1,1,2,1,1,2,2,1,";
kk += "2,2,5,2,1,1,2,1,1,2,2,1,";
kk += "2,2,1,2,2,1,1,2,1,2,1,2,";
kk += "1,2,2,1,2,1,5,2,1,2,1,2,";
kk += "1,2,1,2,1,2,2,1,2,1,2,1,";
kk += "2,1,1,2,2,1,2,1,2,2,1,2,";
//1971
kk += "1,2,1,1,5,2,1,2,2,2,1,2,";
kk += "1,2,1,1,2,1,2,1,2,2,2,1,";
kk += "2,1,2,1,1,2,1,1,2,2,2,1,";
kk += "2,2,1,5,1,2,1,1,2,2,1,2,";
kk += "2,2,1,2,1,1,2,1,1,2,1,2,";
kk += "2,2,1,2,1,2,1,5,2,1,1,2,";
kk += "2,1,2,2,1,2,1,2,1,2,1,1,";
kk += "2,2,1,2,1,2,2,1,2,1,2,1,";
kk += "2,1,1,2,1,6,1,2,2,1,2,1,";
kk += "2,1,1,2,1,2,1,2,2,1,2,2,";
//1981
kk += "1,2,1,1,2,1,1,2,2,1,2,2,";
kk += "2,1,2,3,2,1,1,2,2,1,2,2,";
kk += "2,1,2,1,1,2,1,1,2,1,2,2,";
kk += "2,1,2,2,1,1,2,1,1,5,2,2,";
kk += "1,2,2,1,2,1,2,1,1,2,1,2,";
kk += "1,2,2,1,2,2,1,2,1,2,1,1,";
kk += "2,1,2,2,1,5,2,2,1,2,1,2,";
kk += "1,1,2,1,2,1,2,2,1,2,2,1,";
kk += "2,1,1,2,1,2,1,2,2,1,2,2,";
kk += "1,2,1,1,5,1,2,1,2,2,2,2,";
//1991
kk += "1,2,1,1,2,1,1,2,1,2,2,2,";
kk += "1,2,2,1,1,2,1,1,2,1,2,2,";
kk += "1,2,5,2,1,2,1,1,2,1,2,1,";
kk += "2,2,2,1,2,1,2,1,1,2,1,2,";
kk += "1,2,2,1,2,2,1,5,2,1,1,2,";
kk += "1,2,1,2,2,1,2,1,2,2,1,2,";
kk += "1,1,2,1,2,1,2,2,1,2,2,1,";
kk += "2,1,1,2,3,2,2,1,2,2,2,1,";
kk += "2,1,1,2,1,1,2,1,2,2,2,1,";
kk += "2,2,1,1,2,1,1,2,1,2,2,1,";
//2001
kk += "2,2,2,3,2,1,1,2,1,2,1,2,";
kk += "2,2,1,2,1,2,1,1,2,1,2,1,";
kk += "2,2,1,2,2,1,2,1,1,2,1,2,";
kk += "1,5,2,2,1,2,1,2,2,1,1,2,";
kk += "1,2,1,2,1,2,2,1,2,2,1,2,";
kk += "1,1,2,1,2,1,5,2,2,1,2,2,";
kk += "1,1,2,1,1,2,1,2,2,2,1,2,";
kk += "2,1,1,2,1,1,2,1,2,2,1,2,";
kk += "2,2,1,1,5,1,2,1,2,1,2,2,";
kk += "2,1,2,1,2,1,1,2,1,2,1,2,";
//2011
kk += "2,1,2,2,1,2,1,1,2,1,2,1,";
kk += "2,1,6,2,1,2,1,1,2,1,2,1,";
kk += "2,1,2,2,1,2,1,2,1,2,1,2,";
kk += "1,2,1,2,1,2,1,2,5,2,1,2,";
kk += "1,2,1,1,2,1,2,2,2,1,2,2,";
kk += "1,1,2,1,1,2,1,2,2,1,2,2,";
kk += "2,1,1,2,3,2,1,2,1,2,2,2,";
kk += "1,2,1,2,1,1,2,1,2,1,2,2,";
kk += "2,1,2,1,2,1,1,2,1,2,1,2,";
kk += "2,1,2,5,2,1,1,2,1,2,1,2,";
//2021
kk += "1,2,2,1,2,1,2,1,2,1,2,1,";
kk += "2,1,2,1,2,2,1,2,1,2,1,2,";
kk += "1,5,2,1,2,1,2,2,1,2,1,2,";
kk += "1,2,1,1,2,1,2,2,1,2,2,1,";
kk += "2,1,2,1,1,5,2,1,2,2,2,1,";
kk += "2,1,2,1,1,2,1,2,1,2,2,2,";
kk += "1,2,1,2,1,1,2,1,1,2,2,2,";
kk += "1,2,2,1,5,1,2,1,1,2,2,1,";
kk += "2,2,1,2,2,1,1,2,1,1,2,2,";
kk += "1,2,1,2,2,1,2,1,2,1,2,1,";
//2031
kk += "2,1,5,2,1,2,2,1,2,1,2,1,";
kk += "2,1,1,2,1,2,2,1,2,2,1,2,";
kk += "1,2,1,1,2,1,5,2,2,2,1,2,";
kk += "1,2,1,1,2,1,2,1,2,2,2,1,";
kk += "2,1,2,1,1,2,1,1,2,2,1,2,";
kk += "2,2,1,2,1,4,1,1,2,1,2,2,";
kk += "2,2,1,2,1,1,2,1,1,2,1,2,";
kk += "2,2,1,2,1,2,1,2,1,1,2,1,";
kk += "2,2,1,2,5,2,1,2,1,2,1,1,";
kk += "2,1,2,2,1,2,2,1,2,1,2,1,";
//2041
kk += "2,1,1,2,1,2,2,1,2,2,1,2,";
kk += "1,5,1,2,1,2,1,2,2,2,1,2,";
kk += "1,2,1,1,2,1,1,2,2,1,2,2";
var arr = new Array();
arr = kk.split(",");
return arr;
}
|