diff --git a/src/main/webapp/resources/js/fims/framework/cmm/cmmDateUtil.js b/src/main/webapp/resources/js/fims/framework/cmm/cmmDateUtil.js index e025a255..2c8648b3 100644 --- a/src/main/webapp/resources/js/fims/framework/cmm/cmmDateUtil.js +++ b/src/main/webapp/resources/js/fims/framework/cmm/cmmDateUtil.js @@ -174,12 +174,12 @@ var DateUtil = { var yyyy = stdDay.substring(0,4); var mm = stdDay.substring(4,6); var dd = stdDay.substring(6,8); - var date = new Date(yyyy, (mm-1)*1, dd*1); - date.setDate(date.getDate()+(addDay)); + var dateObj = new Date(yyyy, (mm-1)*1, dd*1); + dateObj.setDate(dateObj.getDate()+(addDay)); - yyyy = date.getFullYear(); - mm = date.getMonth()+1; - dd = date.getDate(); + yyyy = dateObj.getFullYear(); + mm = dateObj.getMonth()+1; + dd = dateObj.getDate(); if( (''+mm).length == 1 ) mm = "0"+ mm; @@ -259,11 +259,36 @@ var DateUtil = { obj.yyyy = ''+yyyy; obj.mm = ''+mm; return obj; - }, + } +} +function getDateObject(dateStr){ + var year = dateStr.substr(0,4); + var month = dateStr.substr(4,2) - 1; + var day = dateStr.substr(6,2); + + return new Date(year,month,day); } +function getDateString(dateObj) { + var result = ""; + + var dateFormat = "YYYYMMDD"; + + for (var i = 0; i < dateFormat.length; i++) { + result += dateFormat.indexOf("YYYY", i) == i ? (i+=3, dateObj.getFullYear() ) : + dateFormat.indexOf("MM", i) == i ? (i+=1, to2(dateObj.getMonth()+1) ) : + dateFormat.indexOf("DD", i) == i ? (i+=1, to2(dateObj.getDate()) ) : + (dateFormat.charAt(i) ); + } + return result; +}; + +function to2(numberObj) { + return (numberObj > 9 ? "" : "0") + numberObj; +}; + /** * 입력일의 이전일 계산 */ @@ -311,7 +336,7 @@ function getLastDay(datestr) { * 년, 월, 일을 입력 받아 Date String으로 변환 */ function getDatetime(nYear, nMonth, nDate){ - var objDate = null; + var dateObj = null; if (nYear.toString().trim().length >= 5) { var sDate = new String(nYear); @@ -322,14 +347,14 @@ function getDatetime(nYear, nMonth, nDate){ var nMinutes = ((sDate.substr(10,2) == "") ? 0 : sDate.substr(10,2)); var nSeconds = ((sDate.substr(12,2) == "") ? 0 : sDate.substr(12,2)); - objDate = new Date(parseInt(nYear), parseInt(nMonth)-1, parseInt(nDate), parseInt(nHours), parseInt(nMinutes), parseInt(nSeconds)); + dateObj = new Date(parseInt(nYear), parseInt(nMonth)-1, parseInt(nDate), parseInt(nHours), parseInt(nMinutes), parseInt(nSeconds)); } else { - objDate = new Date(parseInt(nYear), parseInt(nMonth)-1, parseInt(((nDate == null) ? 1 : nDate))); + dateObj = new Date(parseInt(nYear), parseInt(nMonth)-1, parseInt(((nDate == null) ? 1 : nDate))); } - var strYear = objDate.getFullYear().toString(); - var strMonth = (objDate.getMonth() + 1).toString(); - var strDate = objDate.getDate().toString(); + var strYear = dateObj.getFullYear().toString(); + var strMonth = (dateObj.getMonth() + 1).toString(); + var strDate = dateObj.getDate().toString(); if (strMonth.length == 1) strMonth = "0" + strMonth; if (strDate.length == 1) strDate = "0" + strDate; return strYear + "-" + strMonth + "-" + strDate; @@ -369,7 +394,7 @@ function addDate(date, nOffSet) { }; /** - * 이전해 계싼 + * 이전해 계산 */ function getPrevYear(datestr, year) { if ( year == "0") return datestr; @@ -471,34 +496,6 @@ function setYearMonCombo(id,isAll,isSelect){ } }; -/** - * 문자열 날짜 숫자로 변경 - */ -function stringDateToNum(paramStr){ - var str = paramStr.replace(/-/g, ""); - - var dateNum = ""; - for (var i=0; i= "0") && (str.charAt(i) <= "9")) - dateNum = dateNum + str.charAt(i); - } - if (dateNum.length < 1) { - alert(J.getMessage("cmm.warning.001")); - return false; - } - //if ((dateNum.length != 6) && (dateNum.length != 8)) { - if (dateNum.length != 8) { - alert(J.getMessage("cmm.warning.001")); - return false; - } - if (dateNum.length == 6) { - if (parseInt(dateNum.substr(0, 2), 10) >= 50 ) - dateNum = "19" + dateNum; - else - dateNum = "20" + dateNum; - } - return dateNum; -}; /** * 두 일자간의 일수 계산 @@ -537,15 +534,6 @@ function getWeek(datestr, isConvert){ return week; }; -//----------------------------------------------------------- -// 현재년월 구하기 -//----------------------------------------------------------- -function getYearMonth() { - var today = getToday(); - var yearMonth = today.substr(0, 7); - - return yearMonth; -}; /** * 날짜형식이 올바른지 검사 @@ -557,54 +545,32 @@ function getYearMonth() { function blnOkDate(astrValue, astrNotNull) { var arrDate; - if (astrValue=='') - { + if (astrValue==''){ if (astrNotNull == "nn") return false; else return true; - }else{ - if (astrValue.indexOf("-") != -1) - arrDate = astrValue.split("-"); - else if (astrValue.indexOf("/") != -1) - arrDate = astrValue.split("/"); - else - { - if (astrValue.length != 8) return false; - astrValue = astrValue.substring(0,4)+"/"+astrValue.substring(4,6)+"/" +astrValue.substring(6,8); - arrDate = astrValue.split("/"); - } + } - if (arrDate.length != 3) return false; + if (astrValue.indexOf("-") != -1){ + arrDate = astrValue.split("-"); + } else if (astrValue.indexOf("/") != -1){ + arrDate = astrValue.split("/"); + } else { + if (astrValue.length != 8) return false; + astrValue = astrValue.substring(0,4)+"/"+astrValue.substring(4,6)+"/" +astrValue.substring(6,8); + arrDate = astrValue.split("/"); + } - var chkDate = new Date(arrDate[0] + "/" + arrDate[1] + "/" + arrDate[2]); - if (isNaN(chkDate) == true || - (arrDate[1] != chkDate.getMonth() + 1 || arrDate[2] != chkDate.getDate())) - { - return false; - } + if (arrDate.length != 3) return false; + + var chkDate = new Date(arrDate[0] + "/" + arrDate[1] + "/" + arrDate[2]); + if (isNaN(chkDate) == true + || (arrDate[1] != chkDate.getMonth() + 1 || arrDate[2] != chkDate.getDate())) { + return false; } + return true; } - -/** - * INPUT field에서 날짜를 입력받고서 유효한지 체크(yyyymmdd or yyyy-mm-dd or yyyy/mm/dd)후 틀리면 Calendar Popup - * - * @param field INPUT 객체 - **/ -function openCalendar(dateField) { - var obj = eval("document." + dateField); - - if (obj.value == "") - return; - if (!blnOkDate(obj.value, "nn")) - { - obj.value = ""; - showDateCalendar(dateField); - } - else - obj.value = dateFormat(obj.value, "YYYY-MM-DD"); - -}